-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimport_scanner.py
More file actions
62 lines (49 loc) · 1.89 KB
/
import_scanner.py
File metadata and controls
62 lines (49 loc) · 1.89 KB
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
import shutil
from pathlib import Path
import pefile
class ImportScanner:
def __init__(self, paths : list[Path]):
self.paths = paths
def get_dlls(self, binary):
to_scan = [binary]
scanned = []
dependencies = set([binary])
while len(to_scan) > 0:
file = to_scan.pop()
pe = pefile.PE(str(file))
for entry in pe.DIRECTORY_ENTRY_IMPORT:
dependency = entry.dll.decode("utf-8")
for path in self.paths:
target = Path(path, dependency)
if target.exists():
if target not in scanned and target not in to_scan:
to_scan.append(target)
dependencies.add(target)
scanned.append(file)
return dependencies
if __name__ == "__main__":
"""This script will scan certain executables and
recursively look for dependencies.
"""
msys2_additional_path = Path("/", "usr", "bin")
files = [
Path("bwa", "bwa.exe"),
Path("htslib", "bgzip.exe"),
Path("htslib", "tabix.exe"),
Path("htslib", "htsfile.exe"),
Path("samtools", "samtools.exe"),
Path("bcftools", "bcftools.exe"),
Path("minimap2", "minimap2.exe"),
Path("/", "usr", "bin", "gzip.exe"),
]
destination_root = Path("helix","third_party")
if not destination_root.exists():
destination_root.mkdir(parents=True, exist_ok=True)
destination_root.joinpath("__init__.py").touch()
for file in files:
scanner = ImportScanner([msys2_additional_path])
binaries = scanner.get_dlls(file)
for source_binary in binaries:
destination_binary = destination_root.joinpath(source_binary.name)
if not destination_binary.exists():
shutil.copy(source_binary, destination_binary)