Skip to content

Commit

Permalink
Merge pull request #61 from mrexodia/ctype-structs
Browse files Browse the repository at this point in the history
Implement ctypes alternative
  • Loading branch information
mrexodia authored Mar 13, 2023
2 parents 335d4ce + 4edee8a commit 59a45ff
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 178 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
with:
python-version: '3.9'
architecture: 'x64'

cache: 'pip'
cache-dependency-path: 'setup.cfg'

- name: Python setup
run: |
python setup.py develop
Expand Down
15 changes: 6 additions & 9 deletions src/dumpulator/dumpulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def raise_kill(self, exc=None):
self.regs.cip = FORCE_KILL_ADDR
self.kill_me = exc
if exc is not None:
raise exc
return exc
else:
self.kill_me = True
self._uc.emu_stop()
Expand Down Expand Up @@ -1501,7 +1501,7 @@ def syscall_arg(index):
try:
argvalue = argtype(dp.args[i] & 0xFFFFFFFF)
except KeyError as x:
raise Exception(f"Unknown enum value {dp.args[i]} for {type(argtype)}")
raise Exception(f"Unknown enum value {dp.args[i]} for {type(argtype)}") from None
else:
argvalue = argtype(argvalue)
args.append(argvalue)
Expand All @@ -1517,7 +1517,7 @@ def syscall_arg(index):
if isinstance(status, ExceptionInfo):
print("context switch, stopping emulation")
dp.exception = status
dp.raise_kill(UcError(UC_ERR_EXCEPTION))
raise dp.raise_kill(UcError(UC_ERR_EXCEPTION)) from None
else:
dp.info(f"status = {status:x}")
dp.regs.cax = status
Expand All @@ -1530,17 +1530,14 @@ def syscall_arg(index):
except UcError as err:
raise err
except Exception as exc:
traceback.print_exc()
dp.error(f"Exception thrown during syscall implementation, stopping emulation!")
dp.raise_kill(exc)
raise dp.raise_kill(exc) from None
finally:
dp.sequence_id += 1
else:
dp.error(f"syscall index: {index:x} -> {name} not implemented!")
dp.raise_kill(NotImplementedError())
raise dp.raise_kill(NotImplementedError(f"syscall index: {index:x} -> {name} not implemented!")) from None
else:
dp.error(f"syscall index {index:x} out of range")
dp.raise_kill(IndexError())
raise dp.raise_kill(IndexError(f"syscall index {index:x} out of range")) from None

def _emulate_unsupported_instruction(dp: Dumpulator, instr: CsInsn):
if instr.id == X86_INS_RDRAND:
Expand Down
19 changes: 7 additions & 12 deletions src/dumpulator/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,18 +596,13 @@ class SECTION_IMAGE_INFORMATION(ctypes.Structure):
]
return SECTION_IMAGE_INFORMATION()

def PROCESS_BASIC_INFORMATION(arch: Architecture):
class PROCESS_BASIC_INFORMATION(ctypes.Structure):
_alignment_ = arch.alignment()
_fields_ = [
("ExitStatus", ctypes.c_uint32),
("PebBaseAddress", arch.ptr_type()),
("AffinityMask", arch.ptr_type()),
("BasePriority", ctypes.c_uint32),
("UniqueProcessId", arch.ptr_type()),
("InheritedFromUniqueProcessId", arch.ptr_type()),
]
return PROCESS_BASIC_INFORMATION()
class PROCESS_BASIC_INFORMATION(Struct):
ExitStatus: ULONG
PebBaseAddress: PVOID
AffinityMask: KAFFINITY
BasePriority: KPRIORITY
UniqueProcessId: ULONG_PTR
InheritedFromUniqueProcessId: ULONG_PTR

class KEY_VALUE_FULL_INFORMATION(ctypes.Structure):
_fields_ = [
Expand Down
Loading

0 comments on commit 59a45ff

Please sign in to comment.