Add target_dll and target_func to TransparentApiProxy + test_code.py handles raw [x86|x64]

This commit is contained in:
Clement Rouault
2016-08-19 15:15:04 +02:00
parent 943945225a
commit 19b168df07
2 changed files with 22 additions and 13 deletions
+14 -5
View File
@@ -112,10 +112,13 @@ class CodeTesteur(dbg.Debugger):
print(hexdump(data, start.sp))
def test_code_x86():
def test_code_x86(raw=False):
print("Testing x86 code")
process = windows.test.pop_calc_32(dwCreationFlags=DEBUG_PROCESS)
code = x86.assemble(sys.argv[1])
if raw:
code = sys.argv[1].replace(" ", "").decode('hex')
else:
code = x86.assemble(sys.argv[1])
start_register = {}
if len(sys.argv) > 2:
@@ -131,12 +134,15 @@ def test_code_x86():
x = CodeTesteur(process, code, start_register)
x.loop()
def test_code_x64():
def test_code_x64(raw=False):
print("Testing x64 code")
if windows.current_process.bitness == 32:
raise ValueError("Cannot debug a 64b process from 32b python")
process = windows.test.pop_calc_64(dwCreationFlags=DEBUG_PROCESS)
code = x64.assemble(sys.argv[1])
if raw:
code = sys.argv[1].replace(" ", "").decode('hex')
else:
code = x64.assemble(sys.argv[1])
start_register = {}
if len(sys.argv) > 2:
@@ -162,7 +168,10 @@ if sys.argv[1] == "-x64":
test_code_x64()
elif sys.argv[1] == "--raw":
sys.argv.remove("--raw")
pass
test_code_x86(raw=True)
elif sys.argv[1] == "--raw64":
sys.argv.remove("--raw64")
test_code_x64(raw=True)
else:
test_code_x86()
+8 -8
View File
@@ -211,14 +211,14 @@ class VersionProxy(ApiProxy):
# return None
class TransparentApiProxy(object):
def __init__(self, DLLNAME, func_name, error_check):
self.dll_name = DLLNAME
self.func_name = func_name
def __init__(self, DLLNAME, target_func, error_check):
self.target_dll = DLLNAME
self.target_func = target_func
self.error_check = error_check
self._ctypes_function = None
self.prototype = getattr(winfuncs, func_name + "Prototype")
self.params = getattr(winfuncs, func_name + "Params")
self.prototype = getattr(winfuncs, target_func + "Prototype")
self.params = getattr(winfuncs, target_func + "Params")
def __call__(self, *args, **kwargs):
if self._ctypes_function is None:
@@ -227,10 +227,10 @@ class TransparentApiProxy(object):
def force_resolution(self):
try:
c_prototyped = self.prototype((self.func_name, getattr(ctypes.windll, self.dll_name)), self.params)
c_prototyped = self.prototype((self.target_func, getattr(ctypes.windll, self.target_dll)), self.params)
except AttributeError:
raise ExportNotFound(self.func_name, self.dll_name)
c_prototyped.errcheck = functools.wraps(self.error_check)(functools.partial(self.error_check, self.func_name))
raise ExportNotFound(self.target_func, self.target_dll)
c_prototyped.errcheck = functools.wraps(self.error_check)(functools.partial(self.error_check, self.target_func))
self._ctypes_function = c_prototyped