File: find_deps.py

package info (click to toggle)
tesseract 5.5.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 43,508 kB
  • sloc: cpp: 154,570; makefile: 1,519; java: 1,143; ansic: 852; sh: 763; python: 51
file content (64 lines) | stat: -rwxr-xr-x 1,820 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
#
# Copyright (C) 2024 Stefan Weil
#
# SPDX-License-Identifier: MIT
#
# Find the DLL files which are required for a given set of
# Windows executables and libraries.

import argparse
import os
import pefile

VERBOSE = False

def find_dependencies(binary, search_path, analyzed_deps):
    pe = pefile.PE(binary)
    pe.parse_data_directories()
    if VERBOSE:
        print(f'{binary}:')
    # print(pe.dump_info())

    for entry in pe.DIRECTORY_ENTRY_IMPORT:
        name = entry.dll.decode('utf-8')
        if name in analyzed_deps:
            if VERBOSE:
                print(f'skip {name} (already analyzed)')
            continue
        analyzed_deps.add(name)
        fullpath = os.path.join(search_path, name)
        if not os.path.exists(fullpath):
            # Not found, maybe system DLL. Skip it.
            if VERBOSE:
                print(f'skip {name} (not found, maybe system DLL)')
            continue
        print(fullpath)
        analyzed_deps = find_dependencies(fullpath, search_path, analyzed_deps)

    return analyzed_deps

def main():
    """
    Command-line interface for universal dependency scanner.
    """

    parser = argparse.ArgumentParser(description='Find and copy DLL dependencies')
    parser.add_argument('files', nargs='+', help='Paths to executable or library files')
    parser.add_argument('--dlldir', dest='dlldir', default='/mingw64/bin/',
                        help='path to dll files')

    args = parser.parse_args()

    # try:
    # Find dependencies
    analyzed_deps = set()
    for binary in args.files:
        if True:
            analyzed_deps = find_dependencies(binary, args.dlldir, analyzed_deps)
        # except:
        #    print(f'error: failed to find dependencies for {binary}')


if __name__ == '__main__':
    main()