Skip to content

Commit 59a45ff

Browse files
authored
Merge pull request #61 from mrexodia/ctype-structs
Implement ctypes alternative
2 parents 335d4ce + 4edee8a commit 59a45ff

File tree

6 files changed

+193
-178
lines changed

6 files changed

+193
-178
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ jobs:
1919
with:
2020
python-version: '3.9'
2121
architecture: 'x64'
22-
22+
cache: 'pip'
23+
cache-dependency-path: 'setup.cfg'
24+
2325
- name: Python setup
2426
run: |
2527
python setup.py develop

src/dumpulator/dumpulator.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ def raise_kill(self, exc=None):
10721072
self.regs.cip = FORCE_KILL_ADDR
10731073
self.kill_me = exc
10741074
if exc is not None:
1075-
raise exc
1075+
return exc
10761076
else:
10771077
self.kill_me = True
10781078
self._uc.emu_stop()
@@ -1501,7 +1501,7 @@ def syscall_arg(index):
15011501
try:
15021502
argvalue = argtype(dp.args[i] & 0xFFFFFFFF)
15031503
except KeyError as x:
1504-
raise Exception(f"Unknown enum value {dp.args[i]} for {type(argtype)}")
1504+
raise Exception(f"Unknown enum value {dp.args[i]} for {type(argtype)}") from None
15051505
else:
15061506
argvalue = argtype(argvalue)
15071507
args.append(argvalue)
@@ -1517,7 +1517,7 @@ def syscall_arg(index):
15171517
if isinstance(status, ExceptionInfo):
15181518
print("context switch, stopping emulation")
15191519
dp.exception = status
1520-
dp.raise_kill(UcError(UC_ERR_EXCEPTION))
1520+
raise dp.raise_kill(UcError(UC_ERR_EXCEPTION)) from None
15211521
else:
15221522
dp.info(f"status = {status:x}")
15231523
dp.regs.cax = status
@@ -1530,17 +1530,14 @@ def syscall_arg(index):
15301530
except UcError as err:
15311531
raise err
15321532
except Exception as exc:
1533-
traceback.print_exc()
15341533
dp.error(f"Exception thrown during syscall implementation, stopping emulation!")
1535-
dp.raise_kill(exc)
1534+
raise dp.raise_kill(exc) from None
15361535
finally:
15371536
dp.sequence_id += 1
15381537
else:
1539-
dp.error(f"syscall index: {index:x} -> {name} not implemented!")
1540-
dp.raise_kill(NotImplementedError())
1538+
raise dp.raise_kill(NotImplementedError(f"syscall index: {index:x} -> {name} not implemented!")) from None
15411539
else:
1542-
dp.error(f"syscall index {index:x} out of range")
1543-
dp.raise_kill(IndexError())
1540+
raise dp.raise_kill(IndexError(f"syscall index {index:x} out of range")) from None
15441541

15451542
def _emulate_unsupported_instruction(dp: Dumpulator, instr: CsInsn):
15461543
if instr.id == X86_INS_RDRAND:

src/dumpulator/native.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -596,18 +596,13 @@ class SECTION_IMAGE_INFORMATION(ctypes.Structure):
596596
]
597597
return SECTION_IMAGE_INFORMATION()
598598

599-
def PROCESS_BASIC_INFORMATION(arch: Architecture):
600-
class PROCESS_BASIC_INFORMATION(ctypes.Structure):
601-
_alignment_ = arch.alignment()
602-
_fields_ = [
603-
("ExitStatus", ctypes.c_uint32),
604-
("PebBaseAddress", arch.ptr_type()),
605-
("AffinityMask", arch.ptr_type()),
606-
("BasePriority", ctypes.c_uint32),
607-
("UniqueProcessId", arch.ptr_type()),
608-
("InheritedFromUniqueProcessId", arch.ptr_type()),
609-
]
610-
return PROCESS_BASIC_INFORMATION()
599+
class PROCESS_BASIC_INFORMATION(Struct):
600+
ExitStatus: ULONG
601+
PebBaseAddress: PVOID
602+
AffinityMask: KAFFINITY
603+
BasePriority: KPRIORITY
604+
UniqueProcessId: ULONG_PTR
605+
InheritedFromUniqueProcessId: ULONG_PTR
611606

612607
class KEY_VALUE_FULL_INFORMATION(ctypes.Structure):
613608
_fields_ = [

0 commit comments

Comments
 (0)