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 sys
|
||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from pe.superpe import SuperPe
|
from pe.superpe import SuperPe
|
||||||
|
|
||||||
@@ -12,13 +13,14 @@ class DllResolve():
|
|||||||
self.path_res = path_res
|
self.path_res = path_res
|
||||||
|
|
||||||
|
|
||||||
def all_dll_exist(superpe):
|
def all_dll_exist(superpe) -> bool:
|
||||||
for dll_name in superpe.get_iat_entries():
|
for dll_name in superpe.get_iat_entries():
|
||||||
if not check_dll_availability(dll_name):
|
if not check_dll_availability(dll_name):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def unresolved_dlls(superpe):
|
|
||||||
|
def unresolved_dlls(superpe) -> List[str]:
|
||||||
res = []
|
res = []
|
||||||
for dll_name in superpe.get_iat_entries():
|
for dll_name in superpe.get_iat_entries():
|
||||||
if not check_dll_availability(dll_name):
|
if not check_dll_availability(dll_name):
|
||||||
@@ -26,20 +28,21 @@ def unresolved_dlls(superpe):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def resolve_dlls(superpe):
|
def resolve_dlls(superpe) -> List[DllResolve]:
|
||||||
res = []
|
res = []
|
||||||
for dll_name in superpe.get_iat_entries():
|
for dll_name in superpe.get_iat_entries():
|
||||||
res.append(resolve_dll(dll_name))
|
res.append(resolve_dll(dll_name))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def resolve_dll(dllname):
|
def resolve_dll(dllname) -> DllResolve:
|
||||||
cdll_res = check_dll_availability(dllname)
|
cdll_res = check_dll_availability(dllname)
|
||||||
path_res = search_for_dll(dllname)
|
path_res = search_for_dll(dllname)
|
||||||
return DllResolve(dllname, cdll_res, path_res)
|
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:
|
try:
|
||||||
_ = ctypes.CDLL(dll_name)
|
_ = ctypes.CDLL(dll_name)
|
||||||
return True
|
return True
|
||||||
@@ -47,7 +50,8 @@ def check_dll_availability(dll_name):
|
|||||||
return False
|
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 = [
|
paths = [
|
||||||
os.getcwd(), # Current directory
|
os.getcwd(), # Current directory
|
||||||
os.environ.get('SYSTEMROOT', '') + '\\System32', # System directory
|
os.environ.get('SYSTEMROOT', '') + '\\System32', # System directory
|
||||||
|
|||||||
Reference in New Issue
Block a user