Skip to content

Commit

Permalink
parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
wh201906 authored Nov 22, 2023
1 parent 04b7381 commit 5310ce1
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion pack/find_dlls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import re
import sys
import ctypes.util
import ctypes
import concurrent.futures
import threading

from datetime import datetime


Expand All @@ -27,11 +31,43 @@ def get_dependencies(file_path, checked_dlls=None):

return checked_dlls

def get_dependencies_hs(file_path, checked_dlls, lock):
with lock:
if file_path in checked_dlls:
return set()

result = subprocess.run(
["objdump", "-p", file_path], capture_output=True, text=True
)
output = result.stdout

pattern = r"DLL Name:\s*(.+)"
dlls_to_check = []
for line in output.splitlines():
matches = re.findall(pattern, line, re.IGNORECASE)
if matches:
dll_name = matches[0].strip()
dll_path = ctypes.util.find_library(dll_name)
if dll_path:
with lock:
if dll_path not in checked_dlls:
checked_dlls.add(dll_path)
dlls_to_check.append(dll_path)

new_checked = set()
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(get_dependencies_hs, dll, checked_dlls, lock) for dll in dlls_to_check]
for future in concurrent.futures.as_completed(futures):
new_checked.update(future.result())

return new_checked

def copy_dependencies(file_path):
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S.%f"), flush=True)
dependencies = get_dependencies(file_path)
checked_dlls = set()
lock = threading.Lock()
dependencies = get_dependencies_hs(file_path, checked_dlls, lock)
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S.%f"), flush=True)
print("dependencies:", flush=True)
Expand Down

0 comments on commit 5310ce1

Please sign in to comment.