mirror of
https://github.com/dobin/SuperMega
synced 2026-06-02 17:27:10 +00:00
refactor: syntax improvement for dllresolver
This commit is contained in:
+10
-6
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import ctypes
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
from pe.superpe import SuperPe
|
||||
|
||||
@@ -12,13 +13,14 @@ class DllResolve():
|
||||
self.path_res = path_res
|
||||
|
||||
|
||||
def all_dll_exist(superpe):
|
||||
def all_dll_exist(superpe) -> bool:
|
||||
for dll_name in superpe.get_iat_entries():
|
||||
if not check_dll_availability(dll_name):
|
||||
return False
|
||||
return True
|
||||
|
||||
def unresolved_dlls(superpe):
|
||||
|
||||
def unresolved_dlls(superpe) -> List[str]:
|
||||
res = []
|
||||
for dll_name in superpe.get_iat_entries():
|
||||
if not check_dll_availability(dll_name):
|
||||
@@ -26,20 +28,21 @@ def unresolved_dlls(superpe):
|
||||
return res
|
||||
|
||||
|
||||
def resolve_dlls(superpe):
|
||||
def resolve_dlls(superpe) -> List[DllResolve]:
|
||||
res = []
|
||||
for dll_name in superpe.get_iat_entries():
|
||||
res.append(resolve_dll(dll_name))
|
||||
return res
|
||||
|
||||
|
||||
def resolve_dll(dllname):
|
||||
def resolve_dll(dllname) -> DllResolve:
|
||||
cdll_res = check_dll_availability(dllname)
|
||||
path_res = search_for_dll(dllname)
|
||||
return DllResolve(dllname, cdll_res, path_res)
|
||||
|
||||
|
||||
def check_dll_availability(dll_name):
|
||||
def check_dll_availability(dll_name) -> bool:
|
||||
"""Check if a DLL is available for loading by attempting to load it with ctypes."""
|
||||
try:
|
||||
_ = ctypes.CDLL(dll_name)
|
||||
return True
|
||||
@@ -47,7 +50,8 @@ def check_dll_availability(dll_name):
|
||||
return False
|
||||
|
||||
|
||||
def search_for_dll(dll_name):
|
||||
def search_for_dll(dll_name) -> str:
|
||||
"""Search for a DLL in the system directories and PATH."""
|
||||
paths = [
|
||||
os.getcwd(), # Current directory
|
||||
os.environ.get('SYSTEMROOT', '') + '\\System32', # System directory
|
||||
|
||||
Reference in New Issue
Block a user