diff --git a/examples/emu_dll.py b/examples/emu_dll.py index bf4f9f3e..6ae71ad3 100644 --- a/examples/emu_dll.py +++ b/examples/emu_dll.py @@ -29,7 +29,7 @@ def hook_messagebox(emu, api_name, func, params): return rv -def hook_mem_write(emu, access, address, size, value, ctx): +def hook_mem_write(emu, access, address, size, value): """ Hook that is called whenever memory is written to Args: diff --git a/examples/upx_unpack.py b/examples/upx_unpack.py index 3f8a6e90..675ee2a3 100644 --- a/examples/upx_unpack.py +++ b/examples/upx_unpack.py @@ -26,7 +26,7 @@ def save_unpacked_file(self): up.write(self.mem_read(mm.base, mm.size)) # TODO: Fixup the import table after dumping - def code_hook(self, emu, addr, size, ctx): + def code_hook(self, emu, addr, size): if self.end_addr >= addr >= self.start_addr: print("[*] Section hop signature hit, dumping module") self.save_unpacked_file() diff --git a/speakeasy/binemu.py b/speakeasy/binemu.py index da8d4362..91e77063 100644 --- a/speakeasy/binemu.py +++ b/speakeasy/binemu.py @@ -894,14 +894,14 @@ def add_api_hook(self, cb, module="", api_name="", argc=0, call_conv=None, emu=N self.hooks.update({common.HOOK_API: obj}) return hook - def add_code_hook(self, cb, begin=1, end=0, ctx={}, emu=None): + def add_code_hook(self, cb, begin=1, end=0, emu=None): """ Add a hook that will fire for every CPU instruction """ hl = self.hooks.get(common.HOOK_CODE, []) if not emu: emu = self - hook = common.CodeHook(self, self.emu_eng, cb, begin, end, ctx) + hook = common.CodeHook(self, self.emu_eng, cb, begin, end) if not hl: self.hooks.update( { @@ -918,11 +918,7 @@ def add_code_hook(self, cb, begin=1, end=0, ctx={}, emu=None): return hook - def _dynamic_code_cb(self, emu, addr, size, ctx={}): - """ - Call all subscribers that want callbacks dynamic code callbacks - """ - + def _fire_dyn_code_hooks(self, addr): profiler = self.get_profiler() mm = self.get_address_map(addr) if profiler: @@ -932,13 +928,7 @@ def _dynamic_code_cb(self, emu, addr, size, ctx={}): for h in self.hooks.get(common.HOOK_DYN_CODE, []): h.cb(mm) - # Delete the code hook that got us here - if ctx and isinstance(ctx, dict): - h = ctx.get("_delete_hook") - if h: - h.disable() - - def _set_dyn_code_hook(self, addr, size, ctx={}): + def _set_dyn_code_hook(self, addr, size): """ Set the top level dispatch hook for dynamic code execution """ @@ -946,10 +936,16 @@ def _set_dyn_code_hook(self, addr, size, ctx={}): if size > max_hook_size: size = max_hook_size - ch = self.add_code_hook(cb=self._dynamic_code_cb, begin=addr, end=addr + size, ctx=ctx) - ctx.update({"_delete_hook": ch}) + hook_ref = [None] + + def _dynamic_code_cb(emu, addr, size): + self._fire_dyn_code_hooks(addr) + if hook_ref[0]: + hook_ref[0].disable() + + hook_ref[0] = self.add_code_hook(cb=_dynamic_code_cb, begin=addr, end=addr + size) - def add_dyn_code_hook(self, cb, ctx=[], emu=None): + def add_dyn_code_hook(self, cb, emu=None): """ Add a hook that will fire when dynamically generated/copied code is executed """ @@ -957,7 +953,7 @@ def add_dyn_code_hook(self, cb, ctx=[], emu=None): emu = self hl = self.hooks.get(common.HOOK_DYN_CODE, []) - hook = common.DynCodeHook(emu, self.emu_eng, cb, ctx) + hook = common.DynCodeHook(emu, self.emu_eng, cb) if not hl: self.hooks.update( { @@ -1043,7 +1039,7 @@ def add_mem_map_hook(self, cb, begin=1, end=0, emu=None): return hook - def _hook_mem_invalid_dispatch(self, emu, access, address, size, value, ctx): + def _hook_mem_invalid_dispatch(self, emu, access, address, size, value): """ This handler will dispatch other invalid memory hooks """ @@ -1052,7 +1048,7 @@ def _hook_mem_invalid_dispatch(self, emu, access, address, size, value, ctx): rv = True for mem_access_hook in hl[1:]: if mem_access_hook.enabled: - rv = mem_access_hook.cb(emu, access, address, size, value, ctx) + rv = mem_access_hook.cb(emu, access, address, size, value) if rv is False: break return rv @@ -1079,13 +1075,13 @@ def add_mem_invalid_hook(self, cb, emu=None): return hook - def add_interrupt_hook(self, cb, ctx=[], emu=None): + def add_interrupt_hook(self, cb, emu=None): """ Add a hook that will fire for software interrupts """ if not emu: emu = self - hook = common.InterruptHook(emu, self.emu_eng, cb, ctx=[]) + hook = common.InterruptHook(emu, self.emu_eng, cb) hl = self.hooks.get(common.HOOK_INTERRUPT) if not hl: self.hooks.update( @@ -1103,13 +1099,13 @@ def add_interrupt_hook(self, cb, ctx=[], emu=None): return hook - def add_instruction_hook(self, cb, begin=1, end=0, ctx=[], emu=None, insn=None): + def add_instruction_hook(self, cb, begin=1, end=0, emu=None, insn=None): """ Add a hook that will fire for IN, SYSCALL, or SYSENTER instructions """ if not emu: emu = self - hook = common.InstructionHook(emu, self.emu_eng, cb, ctx=[], insn=insn) + hook = common.InstructionHook(emu, self.emu_eng, cb, insn=insn) hl = self.hooks.get(common.HOOK_INSN) if not hl: self.hooks.update( @@ -1127,11 +1123,11 @@ def add_instruction_hook(self, cb, begin=1, end=0, ctx=[], emu=None, insn=None): return hook - def add_invalid_instruction_hook(self, cb, ctx=[], emu=None): + def add_invalid_instruction_hook(self, cb, emu=None): if not emu: emu = self - hook = common.InvalidInstructionHook(emu, self.emu_eng, cb, ctx=[]) + hook = common.InvalidInstructionHook(emu, self.emu_eng, cb) hl = self.hooks.get(common.HOOK_INSN_INVALID) if not hl: diff --git a/speakeasy/common.py b/speakeasy/common.py index 76a60b79..2d68da31 100644 --- a/speakeasy/common.py +++ b/speakeasy/common.py @@ -55,13 +55,12 @@ class Hook: Base class for all emulator hooks """ - def __init__(self, se_obj, emu_eng, cb, ctx=[], native_hook=False): + def __init__(self, se_obj, emu_eng, cb, native_hook=False): """ Arguments: se_obj: speakeasy emulator object emu_eng: emulation engine object cb: Python callback function - ctx: Arbitrary context that be passed between hook callbacks native_hook: When set to True, a new, raw callback will be registered with with the underlying emulation engine that is called directly by the DLL. Otherwise, this hook will be dispatched via a wrapper hook @@ -74,7 +73,6 @@ def __init__(self, se_obj, emu_eng, cb, ctx=[], native_hook=False): self.native_hook = native_hook self.emu_eng = emu_eng self.se_obj = se_obj - self.ctx = ctx def enable(self): self.enabled = True @@ -84,48 +82,48 @@ def disable(self): self.enabled = False self.emu_eng.hook_disable(self.handle) - def _wrap_code_cb(self, emu, addr, size, ctx=[]): + def _wrap_code_cb(self, emu, addr, size, ctx=None): try: if self.enabled: if self.se_obj.exit_event and self.se_obj.exit_event.is_set(): self.se_obj.stop() return False - return self.cb(self.se_obj, addr, size, self.ctx) + return self.cb(self.se_obj, addr, size) return True except KeyboardInterrupt: self.se_obj.stop() return False - def _wrap_intr_cb(self, emu, num, ctx=[]): + def _wrap_intr_cb(self, emu, num, ctx=None): if self.enabled: - return self.cb(self.se_obj, num, self.ctx) + return self.cb(self.se_obj, num) return True - def _wrap_in_insn_cb(self, emu, port, size, ctx=[]): + def _wrap_in_insn_cb(self, emu, port, size, ctx=None): if self.enabled: return self.cb(self.se_obj, port, size) return True - def _wrap_syscall_insn_cb(self, emu, ctx=[]): + def _wrap_syscall_insn_cb(self, emu, ctx=None): if self.enabled: return self.cb(self.se_obj) return True - def _wrap_memory_access_cb(self, emu, access, addr, size, value, ctx): + def _wrap_memory_access_cb(self, emu, access, addr, size, value, ctx=None): try: if self.enabled: if self.se_obj.exit_event and self.se_obj.exit_event.is_set(): self.se_obj.stop() return False - return self.cb(self.se_obj, access, addr, size, value, ctx) + return self.cb(self.se_obj, access, addr, size, value) return True except KeyboardInterrupt: self.se_obj.stop() return False - def _wrap_invalid_insn_cb(self, emu, ctx=[]): + def _wrap_invalid_insn_cb(self, emu, ctx=None): if self.enabled: - return self.cb(self.se_obj, self.ctx) + return self.cb(self.se_obj) return True @@ -148,7 +146,7 @@ class DynCodeHook(Hook): Currently, this will only fire once per dynamic code mapping. Could be useful for unpacking. """ - def __init__(self, se_obj, emu_eng, cb, ctx=[]): + def __init__(self, se_obj, emu_eng, cb): super().__init__(se_obj, emu_eng, cb) @@ -157,8 +155,8 @@ class CodeHook(Hook): This hook callback will fire for every CPU instruction """ - def __init__(self, se_obj, emu_eng, cb, begin=1, end=0, ctx=[], native_hook=True): - super().__init__(se_obj, emu_eng, cb, ctx=ctx, native_hook=native_hook) + def __init__(self, se_obj, emu_eng, cb, begin=1, end=0, native_hook=True): + super().__init__(se_obj, emu_eng, cb, native_hook=native_hook) self.begin = begin self.end = end @@ -242,8 +240,8 @@ class InterruptHook(Hook): This hook will fire each time a a software interrupt is triggered """ - def __init__(self, se_obj, emu_eng, cb, ctx=[], native_hook=True): - super().__init__(se_obj, emu_eng, cb, ctx=ctx, native_hook=native_hook) + def __init__(self, se_obj, emu_eng, cb, native_hook=True): + super().__init__(se_obj, emu_eng, cb, native_hook=native_hook) def add(self): if not self.added and self.native_hook: @@ -258,8 +256,8 @@ class InstructionHook(Hook): Only the instructions: IN, OUT, SYSCALL, and SYSENTER are supported by unicorn. """ - def __init__(self, se_obj, emu_eng, cb, ctx=[], native_hook=True, insn=None): - super().__init__(se_obj, emu_eng, cb, ctx=ctx, native_hook=native_hook) + def __init__(self, se_obj, emu_eng, cb, native_hook=True, insn=None): + super().__init__(se_obj, emu_eng, cb, native_hook=native_hook) self.insn = insn def add(self): @@ -275,8 +273,8 @@ class InvalidInstructionHook(Hook): to be executed """ - def __init__(self, se_obj, emu_eng, cb, ctx=[], native_hook=True): - super().__init__(se_obj, emu_eng, cb, ctx=ctx, native_hook=native_hook) + def __init__(self, se_obj, emu_eng, cb, native_hook=True): + super().__init__(se_obj, emu_eng, cb, native_hook=native_hook) def add(self): if not self.added and self.native_hook: diff --git a/speakeasy/engines/unicorn_eng.py b/speakeasy/engines/unicorn_eng.py index b2ae594b..60c1a82d 100644 --- a/speakeasy/engines/unicorn_eng.py +++ b/speakeasy/engines/unicorn_eng.py @@ -213,7 +213,7 @@ def start(self, addr, timeout=0, count=0): timeout = self._sec_to_usec(timeout) return self.emu.emu_start(addr, 0xFFFFFFFF, timeout=timeout, count=count) # type: ignore[union-attr] - def hook_add(self, addr=None, cb=None, htype=None, ctx=None, begin=1, end=0, arg1=0): + def hook_add(self, addr=None, cb=None, htype=None, begin=1, end=0, arg1=0): """ Add a callback function for a specific event type or address """ @@ -238,7 +238,7 @@ def hook_add(self, addr=None, cb=None, htype=None, ctx=None, begin=1, end=0, arg elif hook_type == uc.UC_HOOK_MEM_INVALID: cb = ct.cast(UC_HOOK_MEM_INVALID_CB(cb), UC_HOOK_MEM_INVALID_CB) else: - return self.emu.hook_add(htype=hook_type, callback=cb, user_data=ctx, begin=begin, end=end) # type: ignore[union-attr] + return self.emu.hook_add(htype=hook_type, callback=cb, begin=begin, end=end) # type: ignore[union-attr] ptr = ct.cast(cb, ct.c_void_p) # uc_hook_add requires an additional paramter for the hook type UC_HOOK_INSN if hook_type == uc.UC_HOOK_INSN: diff --git a/speakeasy/memmgr.py b/speakeasy/memmgr.py index 0461a190..b6e9cbd0 100644 --- a/speakeasy/memmgr.py +++ b/speakeasy/memmgr.py @@ -78,13 +78,12 @@ def __init__(self, *args, **kwargs): def _hook_mem_map_dispatch(self, mm): hl = self.hooks.get(common.HOOK_MEM_MAP, []) - ctx: dict[str, object] = {} for mem_map_hook in hl: if mem_map_hook.enabled: # the mapped memory region's base address falls within the hook's bounds if mem_map_hook.begin <= mm.base: if not mem_map_hook.end or mem_map_hook.end > mm.base: - mem_map_hook.cb(self, mm.base, mm.size, mm.tag, mm.prot, mm.flags, ctx) + mem_map_hook.cb(self, mm.base, mm.size, mm.tag, mm.prot, mm.flags) def mem_map(self, size, base=None, perms=common.PERM_MEM_RWX, tag=None, flags=0, shared=False, process=None): """ diff --git a/speakeasy/profiler.py b/speakeasy/profiler.py index 6d03f4fd..73979451 100644 --- a/speakeasy/profiler.py +++ b/speakeasy/profiler.py @@ -224,7 +224,7 @@ def record_dropped_files_event(self, run, files): entry = {"path": f.path, "size": len(data), "sha256": _hash, "data_ref": data_ref} run.dropped_files.append(entry) - def record_api_event(self, run, pos: TracePosition, name, ret, argv, ctx=[]): + def record_api_event(self, run, pos: TracePosition, name, ret, argv): """ Log a call to an OS API. This includes arguments, return address, and return value """ diff --git a/speakeasy/speakeasy.py b/speakeasy/speakeasy.py index 147416e0..f4ec324f 100644 --- a/speakeasy/speakeasy.py +++ b/speakeasy/speakeasy.py @@ -37,7 +37,7 @@ def wrap(self, *args, **kwargs): return wrap - def __init__(self, config=None, argv=[], debug=False, exit_event=None, gdb_port=None, volumes=None): + def __init__(self, config=None, argv=None, debug=False, exit_event=None, gdb_port=None, volumes=None): if volumes: if isinstance(config, SpeakeasyConfig): @@ -51,18 +51,18 @@ def __init__(self, config=None, argv=[], debug=False, exit_event=None, gdb_port= self._init_config(config) self.emu: Win32Emulator | WinKernelEmulator | None = None self.api_hooks: list[tuple[Callable, str, str, int, object | None]] = [] - self.code_hooks: list[tuple[Callable, int, int, dict]] = [] - self.dyn_code_hooks: list[tuple[Callable, dict]] = [] - self.invalid_insn_hooks: list[tuple[Callable, list]] = [] + self.code_hooks: list[tuple[Callable, int, int]] = [] + self.dyn_code_hooks: list[tuple[Callable]] = [] + self.invalid_insn_hooks: list[tuple[Callable]] = [] self.mem_read_hooks: list[tuple[Callable, int, int]] = [] - self.argv = argv + self.argv = argv if argv is not None else [] self.exit_event = exit_event self.debug = debug self.gdb_port = gdb_port self.loaded_bins: list[str | None] = [] self.mem_write_hooks: list[tuple[Callable, int, int]] = [] self.mem_invalid_hooks: list[tuple[Callable]] = [] - self.interrupt_hooks: list[tuple[Callable, dict]] = [] + self.interrupt_hooks: list[tuple[Callable]] = [] self.mem_map_hooks: list[tuple[Callable, int, int]] = [] def __enter__(self): @@ -142,16 +142,16 @@ def _init_hooks(self) -> None: self.add_api_hook(cb, mod, func, argc, cconv) while self.code_hooks: h = self.code_hooks.pop(0) - cb, begin, end, ctx = h - self.add_code_hook(cb, begin, end, ctx) + cb, begin, end = h + self.add_code_hook(cb, begin, end) while self.dyn_code_hooks: h = self.dyn_code_hooks.pop(0) - cb, ctx = h - self.add_dyn_code_hook(cb, ctx) + (cb,) = h + self.add_dyn_code_hook(cb) while self.invalid_insn_hooks: h = self.invalid_insn_hooks.pop(0) - cb, ctx = h - self.add_invalid_instruction_hook(cb, ctx) + (cb,) = h + self.add_invalid_instruction_hook(cb) while self.mem_read_hooks: h = self.mem_read_hooks.pop(0) cb, begin, end = h @@ -166,8 +166,8 @@ def _init_hooks(self) -> None: self.add_mem_invalid_hook(cb) while self.interrupt_hooks: h = self.interrupt_hooks.pop(0) - cb, ctx = h - self.add_interrupt_hook(cb, ctx) + (cb,) = h + self.add_interrupt_hook(cb) while self.mem_map_hooks: h = self.mem_map_hooks.pop(0) self.add_mem_map_hook(h) @@ -421,7 +421,7 @@ def call(self, addr: int, params=[]) -> None: output_active_config(self.config, logger) return self.emu.call(addr, params=params) # type: ignore[no-any-return, union-attr] - def add_code_hook(self, cb: Callable, begin=1, end=0, ctx={}): + def add_code_hook(self, cb: Callable, begin=1, end=0): """ Set a callback to fire for every CPU instruction that is emulated @@ -429,29 +429,27 @@ def add_code_hook(self, cb: Callable, begin=1, end=0, ctx={}): cb: Callable python function to execute begin: beginning of the address range to hook end: end of the address range to hook - ctx: Optional context to pass back and forth between the hook function return: Hook object for newly registered hooks """ if not self.emu: - self.code_hooks.append((cb, begin, end, ctx)) + self.code_hooks.append((cb, begin, end)) return - return self.emu.add_code_hook(cb, begin=begin, end=end, ctx=ctx, emu=self) + return self.emu.add_code_hook(cb, begin=begin, end=end, emu=self) - def add_dyn_code_hook(self, cb: Callable, ctx={}): + def add_dyn_code_hook(self, cb: Callable): """ Set a callback to fire when dynamically generated/copied code is executed args: cb: Callable python function to execute - ctx: Optional context to pass back and forth between the hook function return: Hook object for newly registered hooks """ if not self.emu: - self.dyn_code_hooks.append((cb, ctx)) + self.dyn_code_hooks.append((cb,)) return - return self.emu.add_dyn_code_hook(cb, ctx=ctx, emu=self) + return self.emu.add_dyn_code_hook(cb, emu=self) def add_mem_read_hook(self, cb: Callable, begin=1, end=0): """ @@ -517,7 +515,7 @@ def add_SYSCALL_instruction_hook(self, cb: Callable, begin=1, end=0): return return self.emu.add_instruction_hook(cb, begin=begin, end=end, emu=self, insn=700) - def add_invalid_instruction_hook(self, cb: Callable, ctx=[]): + def add_invalid_instruction_hook(self, cb: Callable): """ Set a callback to fire when an invalid instruction is attempted to be executed @@ -528,9 +526,9 @@ def add_invalid_instruction_hook(self, cb: Callable, ctx=[]): Hook object for newly registered hooks """ if not self.emu: - self.invalid_insn_hooks.append((cb, ctx)) + self.invalid_insn_hooks.append((cb,)) return - return self.emu.add_invalid_instruction_hook(cb, ctx) + return self.emu.add_invalid_instruction_hook(cb) def add_mem_invalid_hook(self, cb: Callable): """ @@ -546,20 +544,19 @@ def add_mem_invalid_hook(self, cb: Callable): return return self.emu.add_mem_invalid_hook(cb, emu=self) - def add_interrupt_hook(self, cb: Callable, ctx={}): + def add_interrupt_hook(self, cb: Callable): """ Get a callback for software interrupts args: cb: Callable python function to execute - ctx: Optional context to pass back and forth between the hook function return: Hook object for newly registered hooks """ if not self.emu: - self.interrupt_hooks.append((cb, ctx)) + self.interrupt_hooks.append((cb,)) return - return self.emu.add_interrupt_hook(cb, ctx=ctx, emu=self) + return self.emu.add_interrupt_hook(cb, emu=self) def get_registry_key(self, handle=0, path=""): """ diff --git a/speakeasy/windows/fileman.py b/speakeasy/windows/fileman.py index 494382f3..98c96011 100644 --- a/speakeasy/windows/fileman.py +++ b/speakeasy/windows/fileman.py @@ -71,7 +71,7 @@ class File: curr_handle = 0x80 - def __init__(self, path, config={}, data=b""): + def __init__(self, path, config=None, data=b""): self.path: str = path self.data: io.BytesIO | bytes | None = None self.bytes_written: int = 0 @@ -79,7 +79,7 @@ def __init__(self, path, config={}, data=b""): self.data = io.BytesIO(data) self.curr_offset: int = 0 self.is_dir: bool = False - self.config: Any = config + self.config: Any = config if config is not None else {} def duplicate(self): if not self.data and self.config: @@ -195,7 +195,7 @@ class Pipe(File): curr_handle = 0x400 - def __init__(self, name, mode, num_instances, out_size, in_size, config={}): + def __init__(self, name, mode, num_instances, out_size, in_size, config=None): super().__init__(path=name, config=config) self.name = name self.mode = mode diff --git a/speakeasy/windows/objman.py b/speakeasy/windows/objman.py index 56091c3b..30d35ced 100644 --- a/speakeasy/windows/objman.py +++ b/speakeasy/windows/objman.py @@ -463,7 +463,7 @@ class Process(KernelObject): An EPROCESS object used by the Windows kernel to represent a process """ - def __init__(self, emu, pe=None, user_modules=[], name="", path="", cmdline="", base=0, session=0): + def __init__(self, emu, pe=None, user_modules=None, name="", path="", cmdline="", base=0, session=0): super().__init__(emu=emu) self.ldr_entries: list[LdrDataTableEntry] = [] # TODO: For now just allocate a blank opaque struct for an EPROCESS @@ -480,7 +480,7 @@ def __init__(self, emu, pe=None, user_modules=[], name="", path="", cmdline="", self.name: str = name self.base: int = base self.pid: int = self.id - self.modules: list[Any] = user_modules + self.modules: list[Any] = user_modules if user_modules is not None else [] self.threads: list[Thread] = [] self.console: Console | None = None self.curr_thread: Thread | None = None diff --git a/speakeasy/windows/win32.py b/speakeasy/windows/win32.py index cd1c0d7c..48afb66c 100644 --- a/speakeasy/windows/win32.py +++ b/speakeasy/windows/win32.py @@ -31,13 +31,13 @@ class Win32Emulator(WindowsEmulator): User Mode Windows Emulator Class """ - def __init__(self, config, argv=[], debug=False, exit_event=None, gdb_port=None): + def __init__(self, config, argv=None, debug=False, exit_event=None, gdb_port=None): super().__init__(config, debug=debug, exit_event=exit_event, gdb_port=gdb_port) self.last_error = 0 self.peb_addr = 0 self.heap_allocs = [] - self.argv = argv + self.argv = argv if argv is not None else [] self.sessman = SessionManager(config) self.com = COM(config) @@ -605,7 +605,7 @@ def exit_process(self): self.enable_code_hook() self.run_complete = True - def _hook_mem_unmapped(self, emu, access, address, size, value, ctx): + def _hook_mem_unmapped(self, emu, access, address, size, value): _access = self.emu_eng.mem_access.get(access) # type: ignore[union-attr] if _access == common.INVALID_MEM_READ: @@ -615,7 +615,7 @@ def _hook_mem_unmapped(self, emu, access, address, size, value, ctx): self.mem_map_reserve(pld.address) self.init_peb(self._ordered_peb_modules()) return True - return super()._hook_mem_unmapped(emu, access, address, size, value, ctx) + return super()._hook_mem_unmapped(emu, access, address, size, value) def set_hooks(self): """Set the emulator callbacks""" diff --git a/speakeasy/windows/winemu.py b/speakeasy/windows/winemu.py index afee8dd3..f8d365e0 100644 --- a/speakeasy/windows/winemu.py +++ b/speakeasy/windows/winemu.py @@ -207,7 +207,7 @@ def disable_code_hook(self): if self.tmp_code_hook: self.tmp_code_hook.disable() - def _module_access_hook(self, emu, addr, size, ctx): + def _module_access_hook(self, emu, addr, size): symbol = self.get_symbol_from_address(addr) if symbol: logger.debug("module_access: %s", symbol) @@ -1354,7 +1354,7 @@ def handle_import_data(self, mod_name, sym, data_ptr=0): data_addr = self.api.call_data_func(module, func, data_ptr) # type: ignore[union-attr] return data_addr - def _handle_invalid_fetch(self, emu, address, size, value, ctx): + def _handle_invalid_fetch(self, emu, address, size, value): """ Called when an attempt to emulate an instruction from an invalid address """ @@ -1653,7 +1653,7 @@ def handle_import_func(self, dll, name): # Is this function being called from a dynamcially allocated memory segment? if mm and "virtualalloc" in mm.tag.lower(): - self._dynamic_code_cb(self, ret, 0, {}) + self._fire_dyn_code_hooks(ret) # Log the API args and return value self.log_api(call_pc, imp_api, rv, argv) @@ -1717,7 +1717,7 @@ def handle_import_func(self, dll, name): ) self.on_run_complete() - def _hook_mem_unmapped(self, emu, access, address, size, value, ctx): + def _hook_mem_unmapped(self, emu, access, address, size, value): """ High level function used to catch all invalid memory accesses that occur during emulation @@ -1745,21 +1745,21 @@ def _hook_mem_unmapped(self, emu, access, address, size, value, ctx): self.do_call_return(len(args), pc) self._unset_emu_hooks() return True - return self._handle_invalid_fetch(emu, address, size, value, ctx) + return self._handle_invalid_fetch(emu, address, size, value) elif access == common.INVALID_MEM_READ: - return self._handle_invalid_read(emu, address, size, value, ctx) + return self._handle_invalid_read(emu, address, size, value) elif access == common.INVAL_PERM_MEM_EXEC: - return self._handle_prot_fetch(emu, address, size, value, ctx) + return self._handle_prot_fetch(emu, address, size, value) elif access == common.INVALID_MEM_WRITE: fakeout = address & 0xFFFFFFFFFFFFF000 self.mem_map(self.page_size, base=fakeout) self.tmp_maps.append((fakeout, self.page_size)) - return self._handle_invalid_write(emu, address, size, value, ctx) + return self._handle_invalid_write(emu, address, size, value) elif access == common.INVAL_PERM_MEM_WRITE: - return self._handle_prot_write(emu, address, size, value, ctx) + return self._handle_prot_write(emu, address, size, value) except Exception as e: logger.exception("Invalid memory exception") error = self.get_error_info(str(e), self.get_pc(), traceback=traceback.format_exc()) @@ -1767,7 +1767,7 @@ def _hook_mem_unmapped(self, emu, access, address, size, value, ctx): self.on_emu_complete() return False - def _handle_prot_write(self, emu, address, size, value, ctx): + def _handle_prot_write(self, emu, address, size, value): fakeout = address & 0xFFFFFFFFFFFFF000 self.mem_map(self.page_size, base=fakeout) @@ -1796,7 +1796,7 @@ def get_symbol_from_address(self, address): symbol = "{}.{}".format(*sym) return symbol - def _hook_mem_read(self, emu, access, address, size, value, ctx): + def _hook_mem_read(self, emu, access, address, size, value): """ Hook each memory read event that occurs. This hook is used to lookup symbols and modules that are read from during emulation. @@ -1872,7 +1872,7 @@ def _hook_mem_read(self, emu, access, address, size, value, ctx): self.on_emu_complete() return False - def _hook_mem_write(self, emu, access, address, size, value, ctx): + def _hook_mem_write(self, emu, access, address, size, value): """ Hook each memory write event that occurs. This hook is used to track memory modifications to interesting memory locations. @@ -1925,7 +1925,7 @@ def _hook_mem_write(self, emu, access, address, size, value, ctx): self.on_emu_complete() return False - def _handle_invalid_read(self, emu, address, size, value, ctx): + def _handle_invalid_read(self, emu, address, size, value): """ Hook each invalid memory read event that occurs. """ @@ -1953,7 +1953,7 @@ def _handle_invalid_read(self, emu, address, size, value, ctx): self.on_run_complete() return True - def _handle_prot_fetch(self, emu, address, size, value, ctx): + def _handle_prot_fetch(self, emu, address, size, value): """ Called when non-executable code is emulated """ @@ -1973,7 +1973,7 @@ def _handle_prot_fetch(self, emu, address, size, value, ctx): self.handle_import_func(mod_name, fn) return True - def _handle_invalid_write(self, emu, address, size, value, ctx): + def _handle_invalid_write(self, emu, address, size, value): """ Called when non-writable address is written to """ @@ -1996,7 +1996,7 @@ def _handle_invalid_write(self, emu, address, size, value, ctx): self.on_run_complete() return True - def _hook_code_core(self, emu, addr, size, ctx): + def _hook_code_core(self, emu, addr, size): """ Transient code hook for deferred work: SEH dispatch, run lifecycle, temp map cleanup, and import data queue processing. Enabled on demand @@ -2048,7 +2048,7 @@ def _hook_code_core(self, emu, addr, size, ctx): self.on_emu_complete() return False - def _hook_code_coverage(self, emu, addr, size, ctx): + def _hook_code_coverage(self, emu, addr, size): """ Persistent code hook that records every executed address for coverage. """ @@ -2062,7 +2062,7 @@ def _hook_code_coverage(self, emu, addr, size, ctx): self.on_emu_complete() return False - def _hook_code_tracing(self, emu, addr, size, ctx): + def _hook_code_tracing(self, emu, addr, size): """ Persistent code hook for memory tracing: instruction counting, symbol execution tracking, and per-region execution tracking. @@ -2131,7 +2131,7 @@ def _hook_code_tracing(self, emu, addr, size, ctx): self.on_emu_complete() return False - def _hook_code_debug(self, emu, addr, size, ctx): + def _hook_code_debug(self, emu, addr, size): """ Persistent code hook that prints disassembly and register state for every instruction when debug mode is enabled. @@ -2707,17 +2707,10 @@ def create_mutant(self, name=""): hnd = self.om.get_handle(mtx) # type: ignore[union-attr] return hnd, mtx - def _hook_interrupt(self, emu, intnum, ctx=[]): + def _hook_interrupt(self, emu, intnum): """ Called when software interrupts occur """ - - def _tmp_hook(emu, addr, size, ctx): - ret = self.pop_stack() - self.set_pc(ret) - hook_obj = ctx.pop(0) - hook_obj.disable() - exception_list = self._get_exception_list() if exception_list and self.config.exceptions.dispatch_handlers: # Catch software breakpoint interrupts @@ -2748,7 +2741,14 @@ def _tmp_hook(emu, addr, size, ctx): ecx = self.reg_read(_arch.X86_REG_ECX) # Cookie security init failed, just return since we are in __security_init_cookie if ecx == 6: - ctx.append(self.add_code_hook(cb=_tmp_hook, ctx=ctx)) + hook_ref = [None] + + def _tmp_hook(emu, addr, size): + ret = self.pop_stack() + self.set_pc(ret) + hook_ref[0].disable() + + hook_ref[0] = self.add_code_hook(cb=_tmp_hook) return True pc = self.get_pc() diff --git a/speakeasy/winenv/api/api.py b/speakeasy/winenv/api/api.py index b6d9f890..97df758c 100644 --- a/speakeasy/winenv/api/api.py +++ b/speakeasy/winenv/api/api.py @@ -12,6 +12,8 @@ logger = logging.getLogger(__name__) +ApiContext = dict[str, str] | None + class ApiHandler: """ diff --git a/speakeasy/winenv/api/kernelmode/fwpkclnt.py b/speakeasy/winenv/api/kernelmode/fwpkclnt.py index 023fd026..8c0e097f 100644 --- a/speakeasy/winenv/api/kernelmode/fwpkclnt.py +++ b/speakeasy/winenv/api/kernelmode/fwpkclnt.py @@ -73,7 +73,7 @@ def new_filter(self, name, desc, key): return ret @apihook("FwpmEngineOpen0", argc=5) - def FwpmEngineOpen0(self, emu, argv, ctx={}): + def FwpmEngineOpen0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmEngineOpen0( const wchar_t *serverName, @@ -95,7 +95,7 @@ def FwpmEngineOpen0(self, emu, argv, ctx={}): return rv @apihook("FwpsInjectionHandleCreate0", argc=3) - def FwpsInjectionHandleCreate0(self, emu, argv, ctx={}): + def FwpsInjectionHandleCreate0(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS FwpsInjectionHandleCreate0( ADDRESS_FAMILY addressFamily, @@ -114,7 +114,7 @@ def FwpsInjectionHandleCreate0(self, emu, argv, ctx={}): return rv @apihook("FwpmSubLayerAdd0", argc=3) - def FwpmSubLayerAdd0(self, emu, argv, ctx={}): + def FwpmSubLayerAdd0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmSubLayerAdd0( HANDLE engineHandle, @@ -156,7 +156,7 @@ def FwpmSubLayerAdd0(self, emu, argv, ctx={}): return rv @apihook("FwpsCalloutRegister1", argc=3) - def FwpsCalloutRegister1(self, emu, argv, ctx={}): + def FwpsCalloutRegister1(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS FwpsCalloutRegister1( void *deviceObject, @@ -199,7 +199,7 @@ def FwpsCalloutRegister1(self, emu, argv, ctx={}): return rv @apihook("FwpmCalloutAdd0", argc=4) - def FwpmCalloutAdd0(self, emu, argv, ctx={}): + def FwpmCalloutAdd0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmCalloutAdd0( HANDLE engineHandle, @@ -240,7 +240,7 @@ def FwpmCalloutAdd0(self, emu, argv, ctx={}): return rv @apihook("FwpmFilterAdd0", argc=4) - def FwpmFilterAdd0(self, emu, argv, ctx={}): + def FwpmFilterAdd0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmFilterAdd0( HANDLE engineHandle, @@ -280,7 +280,7 @@ def FwpmFilterAdd0(self, emu, argv, ctx={}): return rv @apihook("FwpmFilterDeleteById0", argc=2) - def FwpmFilterDeleteById0(self, emu, argv, ctx={}): + def FwpmFilterDeleteById0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmFilterDeleteById0( HANDLE engineHandle, @@ -294,7 +294,7 @@ def FwpmFilterDeleteById0(self, emu, argv, ctx={}): return rv @apihook("FwpmCalloutDeleteById0", argc=2) - def FwpmCalloutDeleteById0(self, emu, argv, ctx={}): + def FwpmCalloutDeleteById0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmCalloutDeleteById0( HANDLE engineHandle, @@ -310,7 +310,7 @@ def FwpmCalloutDeleteById0(self, emu, argv, ctx={}): return rv @apihook("FwpsCalloutUnregisterById0", argc=1) - def FwpsCalloutUnregisterById0(self, emu, argv, ctx={}): + def FwpsCalloutUnregisterById0(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS FwpsCalloutUnregisterById0( const UINT32 calloutId @@ -325,7 +325,7 @@ def FwpsCalloutUnregisterById0(self, emu, argv, ctx={}): return rv @apihook("FwpmSubLayerDeleteByKey0", argc=2) - def FwpmSubLayerDeleteByKey0(self, emu, argv, ctx={}): + def FwpmSubLayerDeleteByKey0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmSubLayerDeleteByKey0( HANDLE engineHandle, @@ -345,7 +345,7 @@ def FwpmSubLayerDeleteByKey0(self, emu, argv, ctx={}): return rv @apihook("FwpmEngineClose0", argc=1) - def FwpmEngineClose0(self, emu, argv, ctx={}): + def FwpmEngineClose0(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FwpmEngineClose0( HANDLE engineHandle @@ -357,7 +357,7 @@ def FwpmEngineClose0(self, emu, argv, ctx={}): return rv @apihook("FwpsInjectionHandleDestroy0", argc=1) - def FwpsInjectionHandleDestroy0(self, emu, argv, ctx={}): + def FwpsInjectionHandleDestroy0(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS FwpsInjectionHandleDestroy0( HANDLE injectionHandle diff --git a/speakeasy/winenv/api/kernelmode/hal.py b/speakeasy/winenv/api/kernelmode/hal.py index 6c13f547..77e862e2 100644 --- a/speakeasy/winenv/api/kernelmode/hal.py +++ b/speakeasy/winenv/api/kernelmode/hal.py @@ -28,7 +28,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("KeGetCurrentIrql", argc=0) - def KeGetCurrentIrql(self, emu, argv, ctx={}): + def KeGetCurrentIrql(self, emu, argv, ctx: api.ApiContext = None): """ NTHALAPI KIRQL KeGetCurrentIrql(); """ @@ -36,7 +36,7 @@ def KeGetCurrentIrql(self, emu, argv, ctx={}): return irql @apihook("ExAcquireFastMutex", argc=1, conv=_arch.CALL_CONV_FASTCALL) - def ExAcquireFastMutex(self, emu, argv, ctx={}): + def ExAcquireFastMutex(self, emu, argv, ctx: api.ApiContext = None): """ VOID ExAcquireFastMutex( _Inout_ PFAST_MUTEX FastMutex @@ -45,7 +45,7 @@ def ExAcquireFastMutex(self, emu, argv, ctx={}): return @apihook("ExReleaseFastMutex", argc=1, conv=_arch.CALL_CONV_FASTCALL) - def ExReleaseFastMutex(self, emu, argv, ctx={}): + def ExReleaseFastMutex(self, emu, argv, ctx: api.ApiContext = None): """ VOID ExReleaseFastMutex( _Inout_ PFAST_MUTEX FastMutex diff --git a/speakeasy/winenv/api/kernelmode/ndis.py b/speakeasy/winenv/api/kernelmode/ndis.py index 7c046264..d3699297 100644 --- a/speakeasy/winenv/api/kernelmode/ndis.py +++ b/speakeasy/winenv/api/kernelmode/ndis.py @@ -53,7 +53,7 @@ def new_id(self): return tmp @apihook("NdisGetVersion", argc=0) - def NdisGetVersion(self, emu, argv, ctx={}): + def NdisGetVersion(self, emu, argv, ctx: api.ApiContext = None): """ UINT NdisGetVersion(); """ @@ -76,7 +76,7 @@ def NdisGetVersion(self, emu, argv, ctx={}): return out_ver @apihook("NdisGetRoutineAddress", argc=1) - def NdisGetRoutineAddress(self, emu, argv, ctx={}): + def NdisGetRoutineAddress(self, emu, argv, ctx: api.ApiContext = None): """ PVOID NdisGetRoutineAddress( PNDIS_STRING NdisRoutineName @@ -90,7 +90,7 @@ def NdisGetRoutineAddress(self, emu, argv, ctx={}): return addr @apihook("NdisMRegisterMiniportDriver", argc=5) - def NdisMRegisterMiniportDriver(self, emu, argv, ctx={}): + def NdisMRegisterMiniportDriver(self, emu, argv, ctx: api.ApiContext = None): """ NDIS_STATUS NdisMRegisterMiniportDriver( PDRIVER_OBJECT DriverObject, @@ -110,7 +110,7 @@ def NdisMRegisterMiniportDriver(self, emu, argv, ctx={}): return rv @apihook("NdisInitializeWrapper", argc=4) - def NdisInitializeWrapper(self, emu, argv, ctx={}): + def NdisInitializeWrapper(self, emu, argv, ctx: api.ApiContext = None): """ VOID NdisInitializeWrapper( PNDIS_HANDLE NdisWrapperHandle, @@ -125,7 +125,7 @@ def NdisInitializeWrapper(self, emu, argv, ctx={}): self.mem_write(pHandle, hnd.to_bytes(self.get_ptr_size(), "little")) @apihook("NdisTerminateWrapper", argc=2) - def NdisTerminateWrapper(self, emu, argv, ctx={}): + def NdisTerminateWrapper(self, emu, argv, ctx: api.ApiContext = None): """ VOID NdisTerminateWrapper( _In_ NDIS_HANDLE NdisWrapperHandle, @@ -135,7 +135,7 @@ def NdisTerminateWrapper(self, emu, argv, ctx={}): hnd, ss = argv @apihook("NdisInitializeReadWriteLock", argc=1) - def NdisInitializeReadWriteLock(self, emu, argv, ctx={}): + def NdisInitializeReadWriteLock(self, emu, argv, ctx: api.ApiContext = None): """ void NdisInitializeReadWriteLock( PNDIS_RW_LOCK Lock @@ -144,7 +144,7 @@ def NdisInitializeReadWriteLock(self, emu, argv, ctx={}): (lock,) = argv @apihook("NdisMRegisterUnloadHandler", argc=2) - def NdisMRegisterUnloadHandler(self, emu, argv, ctx={}): + def NdisMRegisterUnloadHandler(self, emu, argv, ctx: api.ApiContext = None): """ VOID NdisMRegisterUnloadHandler( _In_ NDIS_HANDLE NdisWrapperHandle, @@ -154,7 +154,7 @@ def NdisMRegisterUnloadHandler(self, emu, argv, ctx={}): hnd, unload = argv @apihook("NdisRegisterProtocol", argc=4) - def NdisRegisterProtocol(self, emu, argv, ctx={}): + def NdisRegisterProtocol(self, emu, argv, ctx: api.ApiContext = None): """ VOID NdisRegisterProtocol( _Out_ PNDIS_STATUS Status, @@ -177,7 +177,7 @@ def NdisRegisterProtocol(self, emu, argv, ctx={}): self.mem_write(pProtoHandle, hnd.to_bytes(4, "little")) @apihook("NdisIMRegisterLayeredMiniport", argc=4) - def NdisIMRegisterLayeredMiniport(self, emu, argv, ctx={}): + def NdisIMRegisterLayeredMiniport(self, emu, argv, ctx: api.ApiContext = None): """ NDIS_STATUS NdisIMRegisterLayeredMiniport( _In_ NDIS_HANDLE NdisWrapperHandle, @@ -202,7 +202,7 @@ def NdisIMRegisterLayeredMiniport(self, emu, argv, ctx={}): return rv @apihook("NdisIMAssociateMiniport", argc=2) - def NdisIMAssociateMiniport(self, emu, argv, ctx={}): + def NdisIMAssociateMiniport(self, emu, argv, ctx: api.ApiContext = None): """ void NdisIMAssociateMiniport( NDIS_HANDLE DriverHandle, @@ -212,7 +212,7 @@ def NdisIMAssociateMiniport(self, emu, argv, ctx={}): drv_hnd, phnd = argv @apihook("NdisAllocateGenericObject", argc=3) - def NdisAllocateGenericObject(self, emu, argv, ctx={}): + def NdisAllocateGenericObject(self, emu, argv, ctx: api.ApiContext = None): """ PNDIS_GENERIC_OBJECT NdisAllocateGenericObject( PDRIVER_OBJECT DriverObject, @@ -237,7 +237,7 @@ def NdisAllocateGenericObject(self, emu, argv, ctx={}): return ptr @apihook("NdisAllocateMemoryWithTag", argc=3) - def NdisAllocateMemoryWithTag(self, emu, argv, ctx={}): + def NdisAllocateMemoryWithTag(self, emu, argv, ctx: api.ApiContext = None): """ NDIS_STATUS NdisAllocateMemoryWithTag( _Out_ PVOID *VirtualAddress, @@ -258,7 +258,7 @@ def NdisAllocateMemoryWithTag(self, emu, argv, ctx={}): return rv @apihook("NdisAllocateNetBufferListPool", argc=2) - def NdisAllocateNetBufferListPool(self, emu, argv, ctx={}): + def NdisAllocateNetBufferListPool(self, emu, argv, ctx: api.ApiContext = None): """ NDIS_HANDLE NdisAllocateNetBufferListPool( NDIS_HANDLE NdisHandle, @@ -284,7 +284,7 @@ def NdisAllocateNetBufferListPool(self, emu, argv, ctx={}): return nbl_ptr @apihook("NdisFreeNetBufferListPool", argc=1) - def NdisFreeNetBufferListPool(self, emu, argv, ctx={}): + def NdisFreeNetBufferListPool(self, emu, argv, ctx: api.ApiContext = None): """ void NdisFreeNetBufferListPool( NDIS_HANDLE PoolHandle @@ -295,7 +295,7 @@ def NdisFreeNetBufferListPool(self, emu, argv, ctx={}): return @apihook("NdisFreeMemory", argc=3) - def NdisFreeMemory(self, emu, argv, ctx={}): + def NdisFreeMemory(self, emu, argv, ctx: api.ApiContext = None): """ void NdisFreeMemory( PVOID VirtualAddress, @@ -308,7 +308,7 @@ def NdisFreeMemory(self, emu, argv, ctx={}): return @apihook("NdisFreeGenericObject", argc=1) - def NdisFreeGenericObject(self, emu, argv, ctx={}): + def NdisFreeGenericObject(self, emu, argv, ctx: api.ApiContext = None): """ void NdisFreeGenericObject( PNDIS_GENERIC_OBJECT NdisObject diff --git a/speakeasy/winenv/api/kernelmode/netio.py b/speakeasy/winenv/api/kernelmode/netio.py index 5bbe97c2..aff1c813 100644 --- a/speakeasy/winenv/api/kernelmode/netio.py +++ b/speakeasy/winenv/api/kernelmode/netio.py @@ -114,7 +114,7 @@ def __init__(self, emu): self.prov_disp.WskGetNameInfo = addr @apihook("WskRegister", argc=2) - def WskRegister(self, emu, argv, ctx={}): + def WskRegister(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS WskRegister( PWSK_CLIENT_NPI WskClientNpi, PWSK_REGISTRATION WskRegistration @@ -128,7 +128,7 @@ def WskRegister(self, emu, argv, ctx={}): return rv @apihook("WskCaptureProviderNPI", argc=3) - def WskCaptureProviderNPI(self, emu, argv, ctx={}): + def WskCaptureProviderNPI(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS WskCaptureProviderNPI( PWSK_REGISTRATION WskRegistration, ULONG WaitTimeout, @@ -160,7 +160,7 @@ def WskCaptureProviderNPI(self, emu, argv, ctx={}): return rv @apihook("callback_WskSocket", argc=11) - def WskSocket(self, emu, argv, ctx={}): + def WskSocket(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskSocket( PWSK_CLIENT Client, ADDRESS_FAMILY AddressFamily, @@ -190,7 +190,7 @@ def WskSocket(self, emu, argv, ctx={}): return rv @apihook("callback_WskSocketConnect", argc=12) - def WskSocketConnect(self, emu, argv, ctx={}): + def WskSocketConnect(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskSocketConnect( PWSK_CLIENT Client, USHORT SocketType, @@ -212,7 +212,7 @@ def WskSocketConnect(self, emu, argv, ctx={}): return rv @apihook("callback_WskControlClient", argc=8) - def WskControlClient(self, emu, argv, ctx={}): + def WskControlClient(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskControlClient( PWSK_CLIENT Client, ULONG ControlCode, @@ -229,7 +229,7 @@ def WskControlClient(self, emu, argv, ctx={}): return rv @apihook("callback_WskGetAddressInfo", argc=10) - def WskGetAddressInfo(self, emu, argv, ctx={}): + def WskGetAddressInfo(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskGetAddressInfo( PWSK_CLIENT Client, PUNICODE_STRING NodeName, @@ -248,7 +248,7 @@ def WskGetAddressInfo(self, emu, argv, ctx={}): return rv @apihook("callback_WskFreeAddressInfo", argc=2) - def WskFreeAddressInfo(self, emu, argv, ctx={}): + def WskFreeAddressInfo(self, emu, argv, ctx: api.ApiContext = None): """void PfnWskFreeAddressInfo( PWSK_CLIENT Client, PADDRINFOEXW AddrInfo @@ -259,7 +259,7 @@ def WskFreeAddressInfo(self, emu, argv, ctx={}): return rv @apihook("callback_WskGetNameInfo", argc=9) - def WskGetNameInfo(self, emu, argv, ctx={}): + def WskGetNameInfo(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskGetNameInfo( PWSK_CLIENT Client, PSOCKADDR SockAddr, @@ -277,7 +277,7 @@ def WskGetNameInfo(self, emu, argv, ctx={}): return rv @apihook("callback_WskControlSocket", argc=10) - def WskControlSocket(self, emu, argv, ctx={}): + def WskControlSocket(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskControlSocket( PWSK_SOCKET Socket, WSK_CONTROL_SOCKET_TYPE RequestType, @@ -296,7 +296,7 @@ def WskControlSocket(self, emu, argv, ctx={}): return rv @apihook("callback_WskCloseSocket", argc=2) - def WskCloseSocket(self, emu, argv, ctx={}): + def WskCloseSocket(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskCloseSocket( PWSK_SOCKET Socket, PIRP Irp @@ -307,7 +307,7 @@ def WskCloseSocket(self, emu, argv, ctx={}): return rv @apihook("callback_WskBind", argc=4) - def WskBind(self, emu, argv, ctx={}): + def WskBind(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskBind( PWSK_SOCKET Socket, PSOCKADDR LocalAddress, @@ -327,7 +327,7 @@ def WskBind(self, emu, argv, ctx={}): return rv @apihook("callback_WskSendTo", argc=7) - def WskSendTo(self, emu, argv, ctx={}): + def WskSendTo(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskSendTo( PWSK_SOCKET Socket, PWSK_BUF Buffer, @@ -343,7 +343,7 @@ def WskSendTo(self, emu, argv, ctx={}): return rv @apihook("callback_WskReceiveFrom", argc=8) - def WskReceiveFrom(self, emu, argv, ctx={}): + def WskReceiveFrom(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskReceiveFrom( PWSK_SOCKET Socket, PWSK_BUF Buffer, @@ -360,7 +360,7 @@ def WskReceiveFrom(self, emu, argv, ctx={}): return rv @apihook("callback_WskRelease", argc=2) - def WskRelease(self, emu, argv, ctx={}): + def WskRelease(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS WSKAPI WSKAPI * WskRelease( _In_ PWSK_SOCKET Socket, _In_ PWSK_DATA_INDICATION DataIndication @@ -371,7 +371,7 @@ def WskRelease(self, emu, argv, ctx={}): return rv @apihook("callback_WskGetLocalAddress", argc=2) - def WskGetLocalAddress(self, emu, argv, ctx={}): + def WskGetLocalAddress(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS PfnWskGetLocalAddress( PWSK_SOCKET Socket, PSOCKADDR LocalAddress, @@ -383,7 +383,7 @@ def WskGetLocalAddress(self, emu, argv, ctx={}): return rv @apihook("WskReleaseProviderNPI", argc=1) - def WskReleaseProviderNPI(self, emu, argv, ctx={}): + def WskReleaseProviderNPI(self, emu, argv, ctx: api.ApiContext = None): """ void WskReleaseProviderNPI( PWSK_REGISTRATION WskRegistration @@ -394,14 +394,14 @@ def WskReleaseProviderNPI(self, emu, argv, ctx={}): return @apihook("NsiEnumerateObjectsAllParametersEx", argc=0) - def NsiEnumerateObjectsAllParametersEx(self, emu, argv, ctx={}): + def NsiEnumerateObjectsAllParametersEx(self, emu, argv, ctx: api.ApiContext = None): """ N/A """ return @apihook("WskDeregister", argc=1) - def WskDeregister(self, emu, argv, ctx={}): + def WskDeregister(self, emu, argv, ctx: api.ApiContext = None): """ void WskDeregister( PWSK_REGISTRATION WskRegistration diff --git a/speakeasy/winenv/api/kernelmode/ntoskrnl.py b/speakeasy/winenv/api/kernelmode/ntoskrnl.py index 50bd4297..7d8ba27e 100644 --- a/speakeasy/winenv/api/kernelmode/ntoskrnl.py +++ b/speakeasy/winenv/api/kernelmode/ntoskrnl.py @@ -101,7 +101,7 @@ def KdDebuggerEnabled(self, ptr=0): return ptr @apihook("ObfDereferenceObject", argc=1, conv=_arch.CALL_CONV_FASTCALL) - def ObfDereferenceObject(self, emu, argv, ctx={}): + def ObfDereferenceObject(self, emu, argv, ctx: api.ApiContext = None): """ void ObfDereferenceObject(a); """ @@ -112,7 +112,7 @@ def ObfDereferenceObject(self, emu, argv, ctx={}): obj.ref_cnt -= 1 @apihook("ZwClose", argc=1) - def ZwClose(self, emu, argv, ctx={}): + def ZwClose(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS ZwClose( HANDLE Handle @@ -124,7 +124,7 @@ def ZwClose(self, emu, argv, ctx={}): return rv @apihook("DbgPrint", argc=_arch.VAR_ARGS, conv=_arch.CALL_CONV_CDECL) - def DbgPrint(self, emu, argv, ctx={}): + def DbgPrint(self, emu, argv, ctx: api.ApiContext = None): """ ULONG DbgPrint( PCSTR Format, @@ -144,7 +144,7 @@ def DbgPrint(self, emu, argv, ctx={}): return len(fin) @apihook("DbgPrintEx", argc=_arch.VAR_ARGS, conv=_arch.CALL_CONV_CDECL) - def DbgPrintEx(self, emu, argv, ctx={}): + def DbgPrintEx(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI ULONG DbgPrintEx( ULONG ComponentId, @@ -171,7 +171,7 @@ def DbgPrintEx(self, emu, argv, ctx={}): return len(fin) @apihook("_vsnprintf", argc=4, conv=_arch.CALL_CONV_CDECL) - def _vsnprintf(self, emu, argv, ctx={}): + def _vsnprintf(self, emu, argv, ctx: api.ApiContext = None): """ int _vsnprintf( char *buffer, @@ -199,11 +199,12 @@ def _vsnprintf(self, emu, argv, ctx={}): return rv @apihook("vsprintf_s", argc=4, conv=_arch.CALL_CONV_CDECL) - def vsprintf_s(self, emu, argv, ctx={}): + def vsprintf_s(self, emu, argv, ctx: api.ApiContext = None): + ctx = ctx or {} return self._vsnprintf(emu, argv, ctx) @apihook("RtlAnsiStringToUnicodeString", argc=3) - def RtlAnsiStringToUnicodeString(self, emu, argv, ctx={}): + def RtlAnsiStringToUnicodeString(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlAnsiStringToUnicodeString( PUNICODE_STRING DestinationString, @@ -247,7 +248,7 @@ def RtlAnsiStringToUnicodeString(self, emu, argv, ctx={}): return nts @apihook("RtlInitAnsiString", argc=2) - def RtlInitAnsiString(self, emu, argv, ctx={}): + def RtlInitAnsiString(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI VOID RtlInitAnsiString( PANSI_STRING DestinationString, @@ -270,7 +271,7 @@ def RtlInitAnsiString(self, emu, argv, ctx={}): argv[1] = ansi_str @apihook("RtlInitUnicodeString", argc=2) - def RtlInitUnicodeString(self, emu, argv, ctx={}): + def RtlInitUnicodeString(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI VOID RtlInitUnicodeString( PUNICODE_STRING DestinationString, @@ -298,7 +299,7 @@ def RtlInitUnicodeString(self, emu, argv, ctx={}): argv[1] = uni_str @apihook("RtlFreeUnicodeString", argc=1) - def RtlFreeUnicodeString(self, emu, argv, ctx={}): + def RtlFreeUnicodeString(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI VOID RtlFreeUnicodeString( PUNICODE_STRING UnicodeString @@ -314,7 +315,7 @@ def RtlFreeUnicodeString(self, emu, argv, ctx={}): self.mem_free(us.Buffer) @apihook("ExAllocatePoolWithTag", argc=3, conv=_arch.CALL_CONV_STDCALL) - def ExAllocatePoolWithTag(self, emu, argv, ctx={}): + def ExAllocatePoolWithTag(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI PVOID ExAllocatePoolWithTag( POOL_TYPE PoolType, @@ -336,7 +337,7 @@ def ExAllocatePoolWithTag(self, emu, argv, ctx={}): return chunk @apihook("ExFreePoolWithTag", argc=2) - def ExFreePoolWithTag(self, emu, argv, ctx={}): + def ExFreePoolWithTag(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID ExFreePoolWithTag( PVOID P, @@ -354,7 +355,7 @@ def ExFreePoolWithTag(self, emu, argv, ctx={}): self.mem_free(P) @apihook("ExAllocatePool", argc=2) - def ExAllocatePool(self, emu, argv, ctx={}): + def ExAllocatePool(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI PVOID ExAllocatePool( POOL_TYPE PoolType, @@ -367,7 +368,7 @@ def ExAllocatePool(self, emu, argv, ctx={}): return chunk @apihook("ExFreePool", argc=1) - def ExFreePool(self, emu, argv, ctx={}): + def ExFreePool(self, emu, argv, ctx: api.ApiContext = None): """ void ExFreePool( addr @@ -377,7 +378,7 @@ def ExFreePool(self, emu, argv, ctx={}): self.mem_free(addr) @apihook("memmove", argc=3) - def memmove(self, emu, argv, ctx={}): + def memmove(self, emu, argv, ctx: api.ApiContext = None): """ void *memmove( void *dest, @@ -392,7 +393,7 @@ def memmove(self, emu, argv, ctx={}): return dest @apihook("IoDeleteDriver", argc=1) - def IoDeleteDriver(self, emu, argv, ctx={}): + def IoDeleteDriver(self, emu, argv, ctx: api.ApiContext = None): """ VOID IoDeleteDriver(PDRIVER_OBJECT DriverObject) """ @@ -401,7 +402,7 @@ def IoDeleteDriver(self, emu, argv, ctx={}): return @apihook("IoCreateDevice", argc=7) - def IoCreateDevice(self, emu, argv, ctx={}): + def IoCreateDevice(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS IoCreateDevice( PDRIVER_OBJECT DriverObject, @@ -432,7 +433,7 @@ def IoCreateDevice(self, emu, argv, ctx={}): return nts @apihook("IoCreateDeviceSecure", argc=9) - def IoCreateDeviceSecure(self, emu, argv, ctx={}): + def IoCreateDeviceSecure(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS IoCreateDeviceSecure( _In_ PDRIVER_OBJECT DriverObject, @@ -463,7 +464,7 @@ def IoCreateDeviceSecure(self, emu, argv, ctx={}): return nts @apihook("IoCreateSymbolicLink", argc=2) - def IoCreateSymbolicLink(self, emu, argv, ctx={}): + def IoCreateSymbolicLink(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS IoCreateSymbolicLink( PUNICODE_STRING SymbolicLinkName, @@ -482,7 +483,7 @@ def IoCreateSymbolicLink(self, emu, argv, ctx={}): return nts @apihook("IofCompleteRequest", argc=2, conv=_arch.CALL_CONV_FASTCALL) - def IofCompleteRequest(self, emu, argv, ctx={}): + def IofCompleteRequest(self, emu, argv, ctx: api.ApiContext = None): """ VOID IoCompleteRequest( _In_ PIRP Irp, @@ -495,7 +496,7 @@ def IofCompleteRequest(self, emu, argv, ctx={}): return @apihook("IoDeleteSymbolicLink", argc=1) - def IoDeleteSymbolicLink(self, emu, argv, ctx={}): + def IoDeleteSymbolicLink(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS IoDeleteSymbolicLink( PUNICODE_STRING SymbolicLinkName @@ -509,11 +510,11 @@ def IoDeleteSymbolicLink(self, emu, argv, ctx={}): return nts @apihook("KeInitializeMutex", argc=2) - def KeInitializeMutex(self, emu, argv, ctx={}): + def KeInitializeMutex(self, emu, argv, ctx: api.ApiContext = None): return @apihook("IoDeleteDevice", argc=1) - def IoDeleteDevice(self, emu, argv, ctx={}): + def IoDeleteDevice(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID IoDeleteDevice( __drv_freesMem(Mem)PDEVICE_OBJECT DeviceObject @@ -525,7 +526,7 @@ def IoDeleteDevice(self, emu, argv, ctx={}): return nts @apihook("MmIsAddressValid", argc=1) - def MmIsAddressValid(self, emu, argv, ctx={}): + def MmIsAddressValid(self, emu, argv, ctx: api.ApiContext = None): """ BOOLEAN MmIsAddressValid( PVOID VirtualAddress @@ -539,7 +540,7 @@ def MmIsAddressValid(self, emu, argv, ctx={}): return rv @apihook("ZwQuerySystemInformation", argc=4) - def ZwQuerySystemInformation(self, emu, argv, ctx={}): + def ZwQuerySystemInformation(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WINAPI ZwQuerySystemInformation( _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass, @@ -669,7 +670,7 @@ def ZwQuerySystemInformation(self, emu, argv, ctx={}): return nts @apihook("_allshl", argc=2, conv=_arch.CALL_CONV_CDECL) - def _allshl(self, emu, argv, ctx={}): + def _allshl(self, emu, argv, ctx: api.ApiContext = None): """ LONGLONG _allshl ( @@ -683,7 +684,7 @@ def _allshl(self, emu, argv, ctx={}): return rv @apihook("wcscpy", argc=2, conv=_arch.CALL_CONV_CDECL) - def wcscpy(self, emu, argv, ctx={}): + def wcscpy(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcscpy( wchar_t *strDestination, @@ -699,7 +700,7 @@ def wcscpy(self, emu, argv, ctx={}): return len(ws) @apihook("wcsncpy", argc=3, conv=_arch.CALL_CONV_CDECL) - def wcsncpy(self, emu, argv, ctx={}): + def wcsncpy(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcsncpy( wchar_t *strDest, @@ -715,7 +716,7 @@ def wcsncpy(self, emu, argv, ctx={}): return len(ws) @apihook("RtlMoveMemory", argc=3) - def RtlMoveMemory(self, emu, argv, ctx={}): + def RtlMoveMemory(self, emu, argv, ctx: api.ApiContext = None): """ void RtlMoveMemory( void* Destination, @@ -726,7 +727,7 @@ def RtlMoveMemory(self, emu, argv, ctx={}): self.memcpy(emu, argv) @apihook("memcpy", argc=3, conv=_arch.CALL_CONV_CDECL) - def memcpy(self, emu, argv, ctx={}): + def memcpy(self, emu, argv, ctx: api.ApiContext = None): """ void *memcpy( void *dest, @@ -741,7 +742,7 @@ def memcpy(self, emu, argv, ctx={}): return dest @apihook("memset", argc=3, conv=_arch.CALL_CONV_CDECL) - def memset(self, emu, argv, ctx={}): + def memset(self, emu, argv, ctx: api.ApiContext = None): """ void *memset( void *dest, @@ -756,7 +757,7 @@ def memset(self, emu, argv, ctx={}): return dest @apihook("sprintf", argc=_arch.VAR_ARGS, conv=_arch.CALL_CONV_CDECL) - def sprintf(self, emu, argv, ctx={}): + def sprintf(self, emu, argv, ctx: api.ApiContext = None): """ int sprintf( char *buffer, @@ -780,7 +781,7 @@ def sprintf(self, emu, argv, ctx={}): return len(fin) @apihook("_snprintf", argc=_arch.VAR_ARGS, conv=_arch.CALL_CONV_CDECL) - def _snprintf(self, emu, argv, ctx={}): + def _snprintf(self, emu, argv, ctx: api.ApiContext = None): """ int _snprintf( char *buffer, @@ -805,7 +806,7 @@ def _snprintf(self, emu, argv, ctx={}): return len(fin) @apihook("wcslen", argc=1, conv=_arch.CALL_CONV_CDECL) - def wcslen(self, emu, argv, ctx={}): + def wcslen(self, emu, argv, ctx: api.ApiContext = None): """ size_t wcslen( const wchar_t *str @@ -823,7 +824,7 @@ def wcslen(self, emu, argv, ctx={}): return slen @apihook("wcschr", argc=2, conv=_arch.CALL_CONV_CDECL) - def wcschr(self, emu, argv, ctx={}): + def wcschr(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcschr( const wchar_t *str, @@ -847,7 +848,7 @@ def wcschr(self, emu, argv, ctx={}): return rv @apihook("wcscat", argc=2, conv=_arch.CALL_CONV_CDECL) - def wcscat(self, emu, argv, ctx={}): + def wcscat(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcscat( wchar_t *strDestination, @@ -870,7 +871,7 @@ def wcscat(self, emu, argv, ctx={}): return dest @apihook("strrchr", argc=2, conv=_arch.CALL_CONV_CDECL) - def strrchr(self, emu, argv, ctx={}): + def strrchr(self, emu, argv, ctx: api.ApiContext = None): """ char *strrchr( const char *str, @@ -894,7 +895,7 @@ def strrchr(self, emu, argv, ctx={}): return rv @apihook("strchr", argc=2, conv=_arch.CALL_CONV_CDECL) - def strchr(self, emu, argv, ctx={}): + def strchr(self, emu, argv, ctx: api.ApiContext = None): """ char *strchr( const char *str, @@ -918,7 +919,7 @@ def strchr(self, emu, argv, ctx={}): return rv @apihook("_wcsnicmp", argc=3, conv=_arch.CALL_CONV_CDECL) - def _wcsnicmp(self, emu, argv, ctx={}): + def _wcsnicmp(self, emu, argv, ctx: api.ApiContext = None): """ int _wcsnicmp( const wchar_t *string1, @@ -941,7 +942,7 @@ def _wcsnicmp(self, emu, argv, ctx={}): return rv @apihook("_stricmp", argc=2, conv=_arch.CALL_CONV_CDECL) - def _stricmp(self, emu, argv, ctx={}): + def _stricmp(self, emu, argv, ctx: api.ApiContext = None): """ int _stricmp( const char *string1, @@ -966,7 +967,7 @@ def _stricmp(self, emu, argv, ctx={}): return rv @apihook("_wcsicmp", argc=2, conv=_arch.CALL_CONV_CDECL) - def _wcsicmp(self, emu, argv, ctx={}): + def _wcsicmp(self, emu, argv, ctx: api.ApiContext = None): """ int _wcsicmp( const wchar_t *string1, @@ -988,7 +989,7 @@ def _wcsicmp(self, emu, argv, ctx={}): return rv @apihook("PsCreateSystemThread", argc=7) - def PsCreateSystemThread(self, emu, argv, ctx={}): + def PsCreateSystemThread(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS PsCreateSystemThread( PHANDLE ThreadHandle, @@ -1020,7 +1021,7 @@ def PsCreateSystemThread(self, emu, argv, ctx={}): return rv @apihook("RtlCopyUnicodeString", argc=2) - def RtlCopyUnicodeString(self, emu, argv, ctx={}): + def RtlCopyUnicodeString(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI VOID RtlCopyUnicodeString( PUNICODE_STRING DestinationString, @@ -1053,7 +1054,7 @@ def RtlCopyUnicodeString(self, emu, argv, ctx={}): return @apihook("RtlEqualUnicodeString", argc=3) - def RtlEqualUnicodeString(self, emu, argv, ctx={}): + def RtlEqualUnicodeString(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI BOOLEAN RtlEqualUnicodeString( PCUNICODE_STRING String1, @@ -1079,7 +1080,7 @@ def RtlEqualUnicodeString(self, emu, argv, ctx={}): return int(rv) @apihook("IoAllocateIrp", argc=2) - def IoAllocateIrp(self, emu, argv, ctx={}): + def IoAllocateIrp(self, emu, argv, ctx: api.ApiContext = None): """ PIRP IoAllocateIrp( CCHAR StackSize, @@ -1098,7 +1099,7 @@ def IoAllocateIrp(self, emu, argv, ctx={}): return rv @apihook("IoFreeIrp", argc=1) - def IoFreeIrp(self, emu, argv, ctx={}): + def IoFreeIrp(self, emu, argv, ctx: api.ApiContext = None): """ void IoFreeIrp( PIRP Irp @@ -1109,7 +1110,7 @@ def IoFreeIrp(self, emu, argv, ctx={}): return @apihook("IoReuseIrp", argc=2) - def IoReuseIrp(self, emu, argv, ctx={}): + def IoReuseIrp(self, emu, argv, ctx: api.ApiContext = None): """ void IoReuseIrp( PIRP Irp, @@ -1121,7 +1122,7 @@ def IoReuseIrp(self, emu, argv, ctx={}): return @apihook("IoAllocateMdl", argc=5) - def IoAllocateMdl(self, emu, argv, ctx={}): + def IoAllocateMdl(self, emu, argv, ctx: api.ApiContext = None): """ PMDL IoAllocateMdl( __drv_aliasesMem PVOID VirtualAddress, @@ -1148,7 +1149,7 @@ def IoAllocateMdl(self, emu, argv, ctx={}): return ptr @apihook("MmProbeAndLockPages", argc=3) - def MmProbeAndLockPages(self, emu, argv, ctx={}): + def MmProbeAndLockPages(self, emu, argv, ctx: api.ApiContext = None): """ void MmProbeAndLockPages( PMDL MemoryDescriptorList, @@ -1159,7 +1160,7 @@ def MmProbeAndLockPages(self, emu, argv, ctx={}): return @apihook("KeDelayExecutionThread", argc=3) - def KeDelayExecutionThread(self, emu, argv, ctx={}): + def KeDelayExecutionThread(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS KeDelayExecutionThread( KPROCESSOR_MODE WaitMode, @@ -1173,7 +1174,7 @@ def KeDelayExecutionThread(self, emu, argv, ctx={}): return rv @apihook("KeSetEvent", argc=3) - def KeSetEvent(self, emu, argv, ctx={}): + def KeSetEvent(self, emu, argv, ctx: api.ApiContext = None): """ LONG KeSetEvent( PRKEVENT Event, @@ -1187,7 +1188,7 @@ def KeSetEvent(self, emu, argv, ctx={}): return rv @apihook("IoCreateSynchronizationEvent", argc=2) - def IoCreateSynchronizationEvent(self, emu, argv, ctx={}): + def IoCreateSynchronizationEvent(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI PKEVENT IoCreateSynchronizationEvent( PUNICODE_STRING EventName, @@ -1207,7 +1208,7 @@ def IoCreateSynchronizationEvent(self, emu, argv, ctx={}): return evt.address @apihook("KeInitializeEvent", argc=3) - def KeInitializeEvent(self, emu, argv, ctx={}): + def KeInitializeEvent(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID KeInitializeEvent( PRKEVENT Event, @@ -1219,7 +1220,7 @@ def KeInitializeEvent(self, emu, argv, ctx={}): return @apihook("KeResetEvent", argc=1) - def KeResetEvent(self, emu, argv, ctx={}): + def KeResetEvent(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI LONG KeResetEvent( PRKEVENT Event @@ -1230,7 +1231,7 @@ def KeResetEvent(self, emu, argv, ctx={}): return rv @apihook("KeClearEvent", argc=1) - def KeClearEvent(self, emu, argv, ctx={}): + def KeClearEvent(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID KeClearEvent( PRKEVENT Event @@ -1239,7 +1240,7 @@ def KeClearEvent(self, emu, argv, ctx={}): return @apihook("KeInitializeTimer", argc=1) - def KeInitializeTimer(self, emu, argv, ctx={}): + def KeInitializeTimer(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID KeInitializeTimer( PKTIMER Timer @@ -1248,7 +1249,7 @@ def KeInitializeTimer(self, emu, argv, ctx={}): return @apihook("KeSetTimer", argc=3) - def KeSetTimer(self, emu, argv, ctx={}): + def KeSetTimer(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI BOOLEAN KeSetTimer( PKTIMER Timer, @@ -1259,7 +1260,7 @@ def KeSetTimer(self, emu, argv, ctx={}): return True @apihook("PsLookupProcessByProcessId", argc=2) - def PsLookupProcessByProcessId(self, emu, argv, ctx={}): + def PsLookupProcessByProcessId(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS PsLookupProcessByProcessId( HANDLE ProcessId, @@ -1285,7 +1286,7 @@ def PsLookupProcessByProcessId(self, emu, argv, ctx={}): return rv @apihook("ObOpenObjectByPointer", argc=7) - def ObOpenObjectByPointer(self, emu, argv, ctx={}): + def ObOpenObjectByPointer(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS ObOpenObjectByPointer( PVOID Object, @@ -1309,7 +1310,7 @@ def ObOpenObjectByPointer(self, emu, argv, ctx={}): return rv @apihook("PsGetProcessPeb", argc=1) - def PsGetProcessPeb(self, emu, argv, ctx={}): + def PsGetProcessPeb(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI PPEB PsGetProcessPeb( PEPROCESS Object, @@ -1322,7 +1323,7 @@ def PsGetProcessPeb(self, emu, argv, ctx={}): return peb.address @apihook("KeStackAttachProcess", argc=2) - def KeStackAttachProcess(self, emu, argv, ctx={}): + def KeStackAttachProcess(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID KeStackAttachProcess( PRKPROCESS PROCESS, @@ -1336,7 +1337,7 @@ def KeStackAttachProcess(self, emu, argv, ctx={}): emu.set_current_process(proc) @apihook("KeUnstackDetachProcess", argc=1) - def KeUnstackDetachProcess(self, emu, argv, ctx={}): + def KeUnstackDetachProcess(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID KeUnstackDetachProcess( PRKAPC_STATE ApcState @@ -1346,7 +1347,7 @@ def KeUnstackDetachProcess(self, emu, argv, ctx={}): return @apihook("ZwProtectVirtualMemory", argc=5) - def ZwProtectVirtualMemory(self, emu, argv, ctx={}): + def ZwProtectVirtualMemory(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS ZwProtectVirtualMemory( IN HANDLE ProcessHandle, @@ -1370,7 +1371,7 @@ def ZwProtectVirtualMemory(self, emu, argv, ctx={}): return rv @apihook("ZwWriteVirtualMemory", argc=5) - def ZwWriteVirtualMemory(self, emu, argv, ctx={}): + def ZwWriteVirtualMemory(self, emu, argv, ctx: api.ApiContext = None): """ ZwWriteVirtualMemory( HANDLE ProcessHandle, @@ -1406,7 +1407,7 @@ def ZwWriteVirtualMemory(self, emu, argv, ctx={}): return rv @apihook("ZwAllocateVirtualMemory", argc=6) - def ZwAllocateVirtualMemory(self, emu, argv, ctx={}): + def ZwAllocateVirtualMemory(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS ZwAllocateVirtualMemory( HANDLE ProcessHandle, @@ -1438,7 +1439,7 @@ def ZwAllocateVirtualMemory(self, emu, argv, ctx={}): return rv @apihook("PsLookupThreadByThreadId", argc=2) - def PsLookupThreadByThreadId(self, emu, argv, ctx={}): + def PsLookupThreadByThreadId(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS PsLookupThreadByThreadId( HANDLE ThreadId, @@ -1460,7 +1461,7 @@ def PsLookupThreadByThreadId(self, emu, argv, ctx={}): return rv @apihook("RtlGetVersion", argc=1) - def RtlGetVersion(self, emu, argv, ctx={}): + def RtlGetVersion(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlGetVersion( PRTL_OSVERSIONINFOW lpVersionInformation @@ -1488,7 +1489,7 @@ def RtlGetVersion(self, emu, argv, ctx={}): return rv @apihook("KeWaitForSingleObject", argc=5) - def KeWaitForSingleObject(self, emu, argv, ctx={}): + def KeWaitForSingleObject(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS KeWaitForSingleObject( PVOID Object, @@ -1504,7 +1505,7 @@ def KeWaitForSingleObject(self, emu, argv, ctx={}): return rv @apihook("KeInitializeApc", argc=8) - def KeInitializeApc(self, emu, argv, ctx={}): + def KeInitializeApc(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID KeInitializeApc( PKAPC Apc, @@ -1517,6 +1518,7 @@ def KeInitializeApc(self, emu, argv, ctx={}): PVOID NormalContext ); """ + ctx = ctx or {} pApc, Thread, env, KernelRoutine, rundown, NormalRoutine, procmode, ctx = argv apc = self.win.KAPC(emu.get_ptr_size()) @@ -1532,7 +1534,7 @@ def KeInitializeApc(self, emu, argv, ctx={}): apc.NormalContext = ctx @apihook("MmMapLockedPagesSpecifyCache", argc=6) - def MmMapLockedPagesSpecifyCache(self, emu, argv, ctx={}): + def MmMapLockedPagesSpecifyCache(self, emu, argv, ctx: api.ApiContext = None): """ PVOID MmMapLockedPagesSpecifyCache( PMDL MemoryDescriptorList, @@ -1553,7 +1555,7 @@ def MmMapLockedPagesSpecifyCache(self, emu, argv, ctx={}): return rv @apihook("KeInsertQueueApc", argc=4) - def KeInsertQueueApc(self, emu, argv, ctx={}): + def KeInsertQueueApc(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI BOOLEAN KeInsertQueueApc( PKAPC Apc, @@ -1567,7 +1569,7 @@ def KeInsertQueueApc(self, emu, argv, ctx={}): return rv @apihook("KeInitializeDpc", argc=3) - def KeInitializeDpc(self, emu, argv, ctx={}): + def KeInitializeDpc(self, emu, argv, ctx: api.ApiContext = None): """ void KeInitializeDpc( __drv_aliasesMem PRKDPC Dpc, @@ -1580,7 +1582,7 @@ def KeInitializeDpc(self, emu, argv, ctx={}): return @apihook("ObReferenceObjectByName", argc=8) - def ObReferenceObjectByName(self, emu, argv, ctx={}): + def ObReferenceObjectByName(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS NTAPI @@ -1620,7 +1622,7 @@ def ObReferenceObjectByName(self, emu, argv, ctx={}): return rv @apihook("IoGetDeviceObjectPointer", argc=4) - def IoGetDeviceObjectPointer(self, emu, argv, ctx={}): + def IoGetDeviceObjectPointer(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS IoGetDeviceObjectPointer( PUNICODE_STRING ObjectName, @@ -1645,7 +1647,7 @@ def IoGetDeviceObjectPointer(self, emu, argv, ctx={}): return rv @apihook("PsTerminateSystemThread", argc=1) - def PsTerminateSystemThread(self, emu, argv, ctx={}): + def PsTerminateSystemThread(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS PsTerminateSystemThread( NTSTATUS ExitStatus @@ -1657,7 +1659,7 @@ def PsTerminateSystemThread(self, emu, argv, ctx={}): return rv @apihook("IoRegisterBootDriverReinitialization", argc=3) - def IoRegisterBootDriverReinitialization(self, emu, argv, ctx={}): + def IoRegisterBootDriverReinitialization(self, emu, argv, ctx: api.ApiContext = None): """ void IoRegisterBootDriverReinitialization( PDRIVER_OBJECT DriverObject, @@ -1673,14 +1675,14 @@ def IoRegisterBootDriverReinitialization(self, emu, argv, ctx={}): return @apihook("KdDisableDebugger", argc=0) - def KdDisableDebugger(self, emu, argv, ctx={}): + def KdDisableDebugger(self, emu, argv, ctx: api.ApiContext = None): """NTKERNELAPI NTSTATUS KdDisableDebugger();""" rv = ddk.STATUS_DEBUGGER_INACTIVE return rv @apihook("KdChangeOption", argc=0) - def KdChangeOption(self, emu, argv, ctx={}): + def KdChangeOption(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS KdChangeOption( KD_OPTION Option, @@ -1696,7 +1698,7 @@ def KdChangeOption(self, emu, argv, ctx={}): return rv @apihook("MmGetSystemRoutineAddress", argc=1) - def MmGetSystemRoutineAddress(self, emu, argv, ctx={}): + def MmGetSystemRoutineAddress(self, emu, argv, ctx: api.ApiContext = None): """ DECLSPEC_IMPORT PVOID MmGetSystemRoutineAddress( PUNICODE_STRING SystemRoutineName @@ -1710,7 +1712,7 @@ def MmGetSystemRoutineAddress(self, emu, argv, ctx={}): return addr @apihook("KeQuerySystemTime", argc=1) - def KeQuerySystemTime(self, emu, argv, ctx={}): + def KeQuerySystemTime(self, emu, argv, ctx: api.ApiContext = None): """ void KeQuerySystemTime( PLARGE_INTEGER CurrentTime @@ -1722,7 +1724,7 @@ def KeQuerySystemTime(self, emu, argv, ctx={}): self.mem_write(CurrentTime, data) @apihook("RtlTimeToTimeFields", argc=2) - def RtlTimeToTimeFields(self, emu, argv, ctx={}): + def RtlTimeToTimeFields(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI VOID RtlTimeToTimeFields( PLARGE_INTEGER Time, @@ -1735,7 +1737,7 @@ def RtlTimeToTimeFields(self, emu, argv, ctx={}): sys_time @apihook("ExSystemTimeToLocalTime", argc=2) - def ExSystemTimeToLocalTime(self, emu, argv, ctx={}): + def ExSystemTimeToLocalTime(self, emu, argv, ctx: api.ApiContext = None): """ void ExSystemTimeToLocalTime( PLARGE_INTEGER SystemTime, @@ -1749,7 +1751,7 @@ def ExSystemTimeToLocalTime(self, emu, argv, ctx={}): self.mem_write(LocalTime, int_sys_time.to_bytes(8, "little")) @apihook("CmRegisterCallbackEx", argc=6) - def CmRegisterCallbackEx(self, emu, argv, ctx={}): + def CmRegisterCallbackEx(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS CmRegisterCallbackEx( PEX_CALLBACK_FUNCTION Function, @@ -1766,7 +1768,7 @@ def CmRegisterCallbackEx(self, emu, argv, ctx={}): return rv @apihook("CmRegisterCallback", argc=3) - def CmRegisterCallback(self, emu, argv, ctx={}): + def CmRegisterCallback(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS CmRegisterCallback( PEX_CALLBACK_FUNCTION Function, @@ -1782,7 +1784,7 @@ def CmRegisterCallback(self, emu, argv, ctx={}): return rv @apihook("CmUnRegisterCallback", argc=1) - def CmUnRegisterCallback(self, emu, argv, ctx={}): + def CmUnRegisterCallback(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS CmUnRegisterCallback( LARGE_INTEGER Cookie @@ -1794,7 +1796,7 @@ def CmUnRegisterCallback(self, emu, argv, ctx={}): return rv @apihook("EtwRegister", argc=4) - def EtwRegister(self, emu, argv, ctx={}): + def EtwRegister(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS EtwRegister( LPCGUID ProviderId, @@ -1814,7 +1816,7 @@ def EtwRegister(self, emu, argv, ctx={}): return rv @apihook("RtlImageDirectoryEntryToData", argc=4) - def RtlImageDirectoryEntryToData(self, emu, argv, ctx={}): + def RtlImageDirectoryEntryToData(self, emu, argv, ctx: api.ApiContext = None): """ PVOID IMAGEAPI ImageDirectoryEntryToData( PVOID Base, @@ -1835,7 +1837,7 @@ def RtlImageDirectoryEntryToData(self, emu, argv, ctx={}): return rv @apihook("ZwOpenEvent", argc=3) - def ZwOpenEvent(self, emu, argv, ctx={}): + def ZwOpenEvent(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSCALLAPI NTSTATUS ZwOpenEvent( PHANDLE EventHandle, @@ -1862,7 +1864,7 @@ def ZwOpenEvent(self, emu, argv, ctx={}): return rv @apihook("ZwCreateEvent", argc=5) - def ZwCreateEvent(self, emu, argv, ctx={}): + def ZwCreateEvent(self, emu, argv, ctx: api.ApiContext = None): """NTSYSAPI NTSTATUS ZwCreateEvent( PHANDLE EventHandle, ACCESS_MASK DesiredAccess, @@ -1889,7 +1891,7 @@ def ZwCreateEvent(self, emu, argv, ctx={}): return rv @apihook("ExInitializeResourceLite", argc=1) - def ExInitializeResourceLite(self, emu, argv, ctx={}): + def ExInitializeResourceLite(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS ExInitializeResourceLite( PERESOURCE Resource @@ -1900,13 +1902,13 @@ def ExInitializeResourceLite(self, emu, argv, ctx={}): return ddk.STATUS_SUCCESS @apihook("KeEnterCriticalRegion", argc=0) - def KeEnterCriticalRegion(self, emu, argv, ctx={}): + def KeEnterCriticalRegion(self, emu, argv, ctx: api.ApiContext = None): """NTKERNELAPI VOID KeEnterCriticalRegion();""" return @apihook("ExAcquireResourceExclusiveLite", argc=2) - def ExAcquireResourceExclusiveLite(self, emu, argv, ctx={}): + def ExAcquireResourceExclusiveLite(self, emu, argv, ctx: api.ApiContext = None): """ BOOLEAN ExAcquireResourceExclusiveLite( PERESOURCE Resource, @@ -1917,7 +1919,7 @@ def ExAcquireResourceExclusiveLite(self, emu, argv, ctx={}): return rv @apihook("ExAcquireResourceSharedLite", argc=2) - def ExAcquireResourceSharedLite(self, emu, argv, ctx={}): + def ExAcquireResourceSharedLite(self, emu, argv, ctx: api.ApiContext = None): """ BOOLEAN ExAcquireResourceSharedLite( _Inout_ PERESOURCE Resource, @@ -1928,7 +1930,7 @@ def ExAcquireResourceSharedLite(self, emu, argv, ctx={}): return rv @apihook("ExReleaseResourceLite", argc=1, conv=_arch.CALL_CONV_FASTCALL) - def ExReleaseResourceLite(self, emu, argv, ctx={}): + def ExReleaseResourceLite(self, emu, argv, ctx: api.ApiContext = None): """ VOID ExReleaseResourceLite( _Inout_ PERESOURCE Resource @@ -1937,7 +1939,7 @@ def ExReleaseResourceLite(self, emu, argv, ctx={}): return @apihook("ExAcquireFastMutex", argc=1) - def ExAcquireFastMutex(self, emu, argv, ctx={}): + def ExAcquireFastMutex(self, emu, argv, ctx: api.ApiContext = None): """ VOID ExAcquireFastMutex( _Inout_ PFAST_MUTEX FastMutex @@ -1948,7 +1950,7 @@ def ExAcquireFastMutex(self, emu, argv, ctx={}): return @apihook("ExReleaseFastMutex", argc=1) - def ExReleaseFastMutex(self, emu, argv, ctx={}): + def ExReleaseFastMutex(self, emu, argv, ctx: api.ApiContext = None): """ VOID ExReleaseFastMutex( _Inout_ PFAST_MUTEX FastMutex @@ -1959,7 +1961,7 @@ def ExReleaseFastMutex(self, emu, argv, ctx={}): return @apihook("ObfReferenceObject", argc=1) - def ObfReferenceObject(self, emu, argv, ctx={}): + def ObfReferenceObject(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI LONG_PTR ObfReferenceObject( PVOID Object @@ -1968,7 +1970,7 @@ def ObfReferenceObject(self, emu, argv, ctx={}): return 0 @apihook("RtlLengthRequiredSid", argc=1) - def RtlLengthRequiredSid(self, emu, argv, ctx={}): + def RtlLengthRequiredSid(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI ULONG RtlLengthRequiredSid( ULONG SubAuthorityCount @@ -1980,7 +1982,7 @@ def RtlLengthRequiredSid(self, emu, argv, ctx={}): return rv @apihook("RtlInitializeSid", argc=3) - def RtlInitializeSid(self, emu, argv, ctx={}): + def RtlInitializeSid(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlInitializeSid( PSID Sid, @@ -1994,7 +1996,7 @@ def RtlInitializeSid(self, emu, argv, ctx={}): return rv @apihook("RtlSubAuthoritySid", argc=2) - def RtlSubAuthoritySid(self, emu, argv, ctx={}): + def RtlSubAuthoritySid(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI PULONG RtlSubAuthoritySid( PSID Sid, @@ -2007,7 +2009,7 @@ def RtlSubAuthoritySid(self, emu, argv, ctx={}): return sid @apihook("RtlCreateAcl", argc=3) - def RtlCreateAcl(self, emu, argv, ctx={}): + def RtlCreateAcl(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlCreateAcl( PACL Acl, @@ -2022,7 +2024,7 @@ def RtlCreateAcl(self, emu, argv, ctx={}): return rv @apihook("RtlSetDaclSecurityDescriptor", argc=4) - def RtlSetDaclSecurityDescriptor(self, emu, argv, ctx={}): + def RtlSetDaclSecurityDescriptor(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlSetDaclSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor, @@ -2038,7 +2040,7 @@ def RtlSetDaclSecurityDescriptor(self, emu, argv, ctx={}): return rv @apihook("ObSetSecurityObjectByPointer", argc=3) - def ObSetSecurityObjectByPointer(self, emu, argv, ctx={}): + def ObSetSecurityObjectByPointer(self, emu, argv, ctx: api.ApiContext = None): """ ObSetSecurityObjectByPointer(IN PVOID Object, IN SECURITY_INFORMATION SecurityInformation, @@ -2052,7 +2054,7 @@ def ObSetSecurityObjectByPointer(self, emu, argv, ctx={}): return rv @apihook("RtlCreateSecurityDescriptor", argc=2) - def RtlCreateSecurityDescriptor(self, emu, argv, ctx={}): + def RtlCreateSecurityDescriptor(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlCreateSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor, @@ -2066,7 +2068,7 @@ def RtlCreateSecurityDescriptor(self, emu, argv, ctx={}): return rv @apihook("RtlAddAccessAllowedAce", argc=4) - def RtlAddAccessAllowedAce(self, emu, argv, ctx={}): + def RtlAddAccessAllowedAce(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlAddAccessAllowedAce( PACL Acl, @@ -2082,7 +2084,7 @@ def RtlAddAccessAllowedAce(self, emu, argv, ctx={}): return rv @apihook("PoDeletePowerRequest", argc=1) - def PoDeletePowerRequest(self, emu, argv, ctx={}): + def PoDeletePowerRequest(self, emu, argv, ctx: api.ApiContext = None): """ void PoDeletePowerRequest( PVOID PowerRequest @@ -2091,7 +2093,7 @@ def PoDeletePowerRequest(self, emu, argv, ctx={}): return @apihook("IoWMIRegistrationControl", argc=2) - def IoWMIRegistrationControl(self, emu, argv, ctx={}): + def IoWMIRegistrationControl(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS IoWMIRegistrationControl( PDEVICE_OBJECT DeviceObject, @@ -2107,7 +2109,7 @@ def IoWMIRegistrationControl(self, emu, argv, ctx={}): return rv @apihook("ObMakeTemporaryObject", argc=1) - def ObMakeTemporaryObject(self, emu, argv, ctx={}): + def ObMakeTemporaryObject(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI VOID ObMakeTemporaryObject( PVOID Object @@ -2116,7 +2118,7 @@ def ObMakeTemporaryObject(self, emu, argv, ctx={}): return None @apihook("RtlGetCompressionWorkSpaceSize", argc=3) - def RtlGetCompressionWorkSpaceSize(self, emu, argv, ctx={}): + def RtlGetCompressionWorkSpaceSize(self, emu, argv, ctx: api.ApiContext = None): """ NT_RTL_COMPRESS_API NTSTATUS RtlGetCompressionWorkSpaceSize( USHORT CompressionFormatAndEngine, @@ -2132,7 +2134,7 @@ def RtlGetCompressionWorkSpaceSize(self, emu, argv, ctx={}): return ddk.STATUS_SUCCESS @apihook("RtlDecompressBuffer", argc=6) - def RtlDecompressBuffer(self, emu, argv, ctx={}): + def RtlDecompressBuffer(self, emu, argv, ctx: api.ApiContext = None): """ NT_RTL_COMPRESS_API NTSTATUS RtlDecompressBuffer( USHORT CompressionFormat, @@ -2169,7 +2171,7 @@ def RtlDecompressBuffer(self, emu, argv, ctx={}): return nts @apihook("FsRtlAllocatePool", argc=2) - def FsRtlAllocatePool(self, emu, argv, ctx={}): + def FsRtlAllocatePool(self, emu, argv, ctx: api.ApiContext = None): """ void FsRtlAllocatePool( PoolType, @@ -2181,7 +2183,7 @@ def FsRtlAllocatePool(self, emu, argv, ctx={}): return chunk @apihook("IofCallDriver", argc=2, conv=_arch.CALL_CONV_FASTCALL) - def IofCallDriver(self, emu, argv, ctx={}): + def IofCallDriver(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS IofCallDriver( PDEVICE_OBJECT DeviceObject, @@ -2200,7 +2202,7 @@ def IofCallDriver(self, emu, argv, ctx={}): return rv @apihook("IoSetCompletionRoutineEx", argc=7) - def IoSetCompletionRoutineEx(self, emu, argv, ctx={}): + def IoSetCompletionRoutineEx(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS IoSetCompletionRoutineEx( PDEVICE_OBJECT DeviceObject, @@ -2218,7 +2220,7 @@ def IoSetCompletionRoutineEx(self, emu, argv, ctx={}): return rv @apihook("ExQueueWorkItem", argc=2) - def ExQueueWorkItem(self, emu, argv, ctx={}): + def ExQueueWorkItem(self, emu, argv, ctx: api.ApiContext = None): """ DECLSPEC_DEPRECATED_DDK NTKERNELAPI VOID ExQueueWorkItem( __drv_aliasesMem PWORK_QUEUE_ITEM WorkItem, @@ -2230,7 +2232,7 @@ def ExQueueWorkItem(self, emu, argv, ctx={}): return @apihook("ZwDeviceIoControlFile", argc=10) - def ZwDeviceIoControlFile(self, emu, argv, ctx={}): + def ZwDeviceIoControlFile(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS NtDeviceIoControlFile( HANDLE FileHandle, @@ -2266,7 +2268,7 @@ def ZwDeviceIoControlFile(self, emu, argv, ctx={}): return nts @apihook("_snwprintf", argc=_arch.VAR_ARGS, conv=_arch.CALL_CONV_CDECL) - def _snwprintf(self, emu, argv, ctx={}): + def _snwprintf(self, emu, argv, ctx: api.ApiContext = None): """ int _snwprintf( wchar_t *buffer, @@ -2295,7 +2297,7 @@ def _snwprintf(self, emu, argv, ctx={}): return len(fin) @apihook("ObReferenceObjectByHandle", argc=6) - def ObReferenceObjectByHandle(self, emu, argv, ctx={}): + def ObReferenceObjectByHandle(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS ObReferenceObjectByHandle( HANDLE Handle, @@ -2320,7 +2322,7 @@ def ObReferenceObjectByHandle(self, emu, argv, ctx={}): return nts @apihook("ObGetFilterVersion", argc=0) - def ObGetFilterVersion(self, emu, argv, ctx={}): + def ObGetFilterVersion(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI USHORT @@ -2331,7 +2333,7 @@ def ObGetFilterVersion(self, emu, argv, ctx={}): return 256 @apihook("ObRegisterCallbacks", argc=2) - def ObRegisterCallbacks(self, emu, argv, ctx={}): + def ObRegisterCallbacks(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS @@ -2346,7 +2348,7 @@ def ObRegisterCallbacks(self, emu, argv, ctx={}): return nts @apihook("ZwDeleteKey", argc=1) - def ZwDeleteKey(self, emu, argv, ctx={}): + def ZwDeleteKey(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS ZwDeleteKey( HANDLE KeyHandle @@ -2358,7 +2360,7 @@ def ZwDeleteKey(self, emu, argv, ctx={}): return nts @apihook("ZwQueryInformationProcess", argc=5) - def ZwQueryInformationProcess(self, emu, argv, ctx={}): + def ZwQueryInformationProcess(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSTATUS ZwQueryInformationProcess( IN HANDLE ProcessHandle, @@ -2399,14 +2401,14 @@ def ZwQueryInformationProcess(self, emu, argv, ctx={}): return nts @apihook("IoGetCurrentProcess", argc=0) - def IoGetCurrentProcess(self, emu, argv, ctx={}): + def IoGetCurrentProcess(self, emu, argv, ctx: api.ApiContext = None): """NTKERNELAPI PEPROCESS IoGetCurrentProcess();""" p = emu.get_current_process() return p.address @apihook("NtSetInformationThread", argc=4) - def NtSetInformationThread(self, emu, argv, ctx={}): + def NtSetInformationThread(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS NtSetInformationThread( HANDLE ThreadHandle, @@ -2420,7 +2422,7 @@ def NtSetInformationThread(self, emu, argv, ctx={}): return nts @apihook("wcsnlen", argc=2) - def wcsnlen(self, emu, argv, ctx={}): + def wcsnlen(self, emu, argv, ctx: api.ApiContext = None): """s ize_t wcsnlen( const wchar_t *str, @@ -2436,7 +2438,7 @@ def wcsnlen(self, emu, argv, ctx={}): return len(ws) @apihook("IoRegisterShutdownNotification", argc=1) - def IoRegisterShutdownNotification(self, emu, argv, ctx={}): + def IoRegisterShutdownNotification(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS IoRegisterShutdownNotification( PDEVICE_OBJECT DeviceObject @@ -2448,7 +2450,7 @@ def IoRegisterShutdownNotification(self, emu, argv, ctx={}): return rv @apihook("IoUnregisterShutdownNotification", argc=1) - def IoUnregisterShutdownNotification(self, emu, argv, ctx={}): + def IoUnregisterShutdownNotification(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS IoRegisterShutdownNotification( PDEVICE_OBJECT DeviceObject @@ -2458,7 +2460,7 @@ def IoUnregisterShutdownNotification(self, emu, argv, ctx={}): return ddk.STATUS_SUCCESS @apihook("KeAcquireSpinLockRaiseToDpc", argc=1) - def KeAcquireSpinLockRaiseToDpc(self, emu, argv, ctx={}): + def KeAcquireSpinLockRaiseToDpc(self, emu, argv, ctx: api.ApiContext = None): """ KIRQL KeAcquireSpinLockRaiseToDpc( _Inout_ PKSPIN_LOCK SpinLock @@ -2470,7 +2472,7 @@ def KeAcquireSpinLockRaiseToDpc(self, emu, argv, ctx={}): return irql @apihook("MmUnlockPages", argc=1) - def MmUnlockPages(self, emu, argv, ctx={}): + def MmUnlockPages(self, emu, argv, ctx: api.ApiContext = None): """ void MmUnlockPages( PMDL MemoryDescriptorList @@ -2480,7 +2482,7 @@ def MmUnlockPages(self, emu, argv, ctx={}): return @apihook("IoFreeMdl", argc=1) - def IoFreeMdl(self, emu, argv, ctx={}): + def IoFreeMdl(self, emu, argv, ctx: api.ApiContext = None): """ void IoFreeMdl( PMDL Mdl @@ -2490,7 +2492,7 @@ def IoFreeMdl(self, emu, argv, ctx={}): return @apihook("KeCancelTimer", argc=1) - def KeCancelTimer(self, emu, argv, ctx={}): + def KeCancelTimer(self, emu, argv, ctx: api.ApiContext = None): """ BOOLEAN KeCancelTimer( PKTIMER Arg1 @@ -2500,7 +2502,7 @@ def KeCancelTimer(self, emu, argv, ctx={}): return rv @apihook("PsGetVersion", argc=4) - def PsGetVersion(self, emu, argv, ctx={}): + def PsGetVersion(self, emu, argv, ctx: api.ApiContext = None): """ BOOLEAN PsGetVersion( PULONG MajorVersion, @@ -2526,7 +2528,7 @@ def PsGetVersion(self, emu, argv, ctx={}): return 0 @apihook("PsSetCreateProcessNotifyRoutineEx", argc=2) - def PsSetCreateProcessNotifyRoutineEx(self, emu, argv, ctx={}): + def PsSetCreateProcessNotifyRoutineEx(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS @@ -2541,7 +2543,7 @@ def PsSetCreateProcessNotifyRoutineEx(self, emu, argv, ctx={}): return rv @apihook("PsSetLoadImageNotifyRoutine", argc=1) - def PsSetLoadImageNotifyRoutine(self, emu, argv, ctx={}): + def PsSetLoadImageNotifyRoutine(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS @@ -2555,7 +2557,7 @@ def PsSetLoadImageNotifyRoutine(self, emu, argv, ctx={}): return rv @apihook("PsRemoveLoadImageNotifyRoutine", argc=1) - def PsRemoveLoadImageNotifyRoutine(self, emu, argv, ctx={}): + def PsRemoveLoadImageNotifyRoutine(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS @@ -2569,7 +2571,7 @@ def PsRemoveLoadImageNotifyRoutine(self, emu, argv, ctx={}): return rv @apihook("PsSetCreateThreadNotifyRoutine", argc=1) - def PsSetCreateThreadNotifyRoutine(self, emu, argv, ctx={}): + def PsSetCreateThreadNotifyRoutine(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS @@ -2583,7 +2585,7 @@ def PsSetCreateThreadNotifyRoutine(self, emu, argv, ctx={}): return rv @apihook("PsRemoveCreateThreadNotifyRoutine", argc=1) - def PsRemoveCreateThreadNotifyRoutine(self, emu, argv, ctx={}): + def PsRemoveCreateThreadNotifyRoutine(self, emu, argv, ctx: api.ApiContext = None): """ NTKERNELAPI NTSTATUS @@ -2597,7 +2599,7 @@ def PsRemoveCreateThreadNotifyRoutine(self, emu, argv, ctx={}): return rv @apihook("mbstowcs", argc=3) - def mbstowcs(self, emu, argv, ctx={}): + def mbstowcs(self, emu, argv, ctx: api.ApiContext = None): """ size_t mbstowcs( wchar_t *wcstr, @@ -2621,7 +2623,7 @@ def mbstowcs(self, emu, argv, ctx={}): return rv @apihook("ZwOpenKey", argc=3) - def ZwOpenKey(self, emu, argv, ctx={}): + def ZwOpenKey(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS ZwOpenKey( PHANDLE KeyHandle, @@ -2648,7 +2650,7 @@ def ZwOpenKey(self, emu, argv, ctx={}): return rv @apihook("ZwQueryValueKey", argc=6) - def ZwQueryValueKey(self, emu, argv, ctx={}): + def ZwQueryValueKey(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS ZwQueryValueKey( HANDLE KeyHandle, @@ -2699,7 +2701,7 @@ def ZwQueryValueKey(self, emu, argv, ctx={}): return rv @apihook("ZwCreateFile", argc=11) - def ZwCreateFile(self, emu, argv, ctx={}): + def ZwCreateFile(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS NtCreateFile( PHANDLE FileHandle, @@ -2783,7 +2785,7 @@ def ZwCreateFile(self, emu, argv, ctx={}): return nts @apihook("ZwOpenFile", argc=6) - def ZwOpenFile(self, emu, argv, ctx={}): + def ZwOpenFile(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS NtOpenFile( PHANDLE FileHandle, @@ -2830,7 +2832,7 @@ def ZwOpenFile(self, emu, argv, ctx={}): return nts @apihook("ZwQueryInformationFile", argc=5) - def ZwQueryInformationFile(self, emu, argv, ctx={}): + def ZwQueryInformationFile(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS NtQueryInformationFile( HANDLE FileHandle, @@ -2860,7 +2862,7 @@ def ZwQueryInformationFile(self, emu, argv, ctx={}): return nts @apihook("RtlCompareMemory", argc=3) - def RtlCompareMemory(self, emu, argv, ctx={}): + def RtlCompareMemory(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI SIZE_T RtlCompareMemory( const VOID *Source1, @@ -2882,7 +2884,7 @@ def RtlCompareMemory(self, emu, argv, ctx={}): return i @apihook("RtlQueryRegistryValuesEx", argc=5) - def RtlQueryRegistryValuesEx(self, emu, argv, ctx={}): + def RtlQueryRegistryValuesEx(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS RtlQueryRegistryValuesEx( ULONG RelativeTo, @@ -2911,7 +2913,7 @@ def RtlQueryRegistryValuesEx(self, emu, argv, ctx={}): return rv @apihook("ZwWriteFile", argc=9) - def ZwWriteFile(self, emu, argv, ctx={}): + def ZwWriteFile(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS NtWriteFile( HANDLE FileHandle, @@ -2952,7 +2954,7 @@ def ZwWriteFile(self, emu, argv, ctx={}): return nts @apihook("ZwReadFile", argc=9) - def ZwReadFile(self, emu, argv, ctx={}): + def ZwReadFile(self, emu, argv, ctx: api.ApiContext = None): """ __kernel_entry NTSYSCALLAPI NTSTATUS NtReadFile( HANDLE FileHandle, @@ -2988,7 +2990,7 @@ def ZwReadFile(self, emu, argv, ctx={}): return nts @apihook("MmIsDriverVerifying", argc=1) - def MmIsDriverVerifying(self, emu, argv, ctx={}): + def MmIsDriverVerifying(self, emu, argv, ctx: api.ApiContext = None): """ LOGICAL MmIsDriverVerifying( _DRIVER_OBJECT *DriverObject @@ -3001,7 +3003,7 @@ def MmIsDriverVerifying(self, emu, argv, ctx={}): return rv @apihook("ZwCreateSection", argc=7) - def ZwCreateSection(self, emu, argv, ctx={}): + def ZwCreateSection(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS ZwCreateSection( PHANDLE SectionHandle, @@ -3048,7 +3050,7 @@ def ZwCreateSection(self, emu, argv, ctx={}): return ddk.STATUS_SUCCESS @apihook("ZwUnmapViewOfSection", argc=2) - def ZwUnmapViewOfSection(self, emu, argv, ctx={}): + def ZwUnmapViewOfSection(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS ZwUnmapViewOfSection( HANDLE ProcessHandle, @@ -3059,7 +3061,7 @@ def ZwUnmapViewOfSection(self, emu, argv, ctx={}): return 0 @apihook("ZwMapViewOfSection", argc=10) - def ZwMapViewOfSection(self, emu, argv, ctx={}): + def ZwMapViewOfSection(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS ZwMapViewOfSection( HANDLE SectionHandle, @@ -3159,7 +3161,7 @@ def ZwMapViewOfSection(self, emu, argv, ctx={}): return rv @apihook("RtlAllocateHeap", argc=3) - def RtlAllocateHeap(self, emu, argv, ctx={}): + def RtlAllocateHeap(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI PVOID RtlAllocateHeap( PVOID HeapHandle, @@ -3174,7 +3176,7 @@ def RtlAllocateHeap(self, emu, argv, ctx={}): return block @apihook("ZwGetContextThread", argc=2) - def ZwGetContextThread(self, emu, argv, ctx={}): + def ZwGetContextThread(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ZwGetContextThread( HANDLE hThread, @@ -3194,7 +3196,7 @@ def ZwGetContextThread(self, emu, argv, ctx={}): return True @apihook("ZwSetContextThread", argc=2) - def ZwSetContextThread(self, emu, argv, ctx={}): + def ZwSetContextThread(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ZwSetContextThread( HANDLE hThread, @@ -3215,7 +3217,7 @@ def ZwSetContextThread(self, emu, argv, ctx={}): return True @apihook("RtlFreeHeap", argc=3) - def RtlFreeHeap(self, emu, argv, ctx={}): + def RtlFreeHeap(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI RtlFreeHeap( PVOID HeapHandle, diff --git a/speakeasy/winenv/api/kernelmode/usbd.py b/speakeasy/winenv/api/kernelmode/usbd.py index 9b847082..95d0600b 100644 --- a/speakeasy/winenv/api/kernelmode/usbd.py +++ b/speakeasy/winenv/api/kernelmode/usbd.py @@ -26,7 +26,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("USBD_ValidateConfigurationDescriptor", argc=5) - def USBD_ValidateConfigurationDescriptor(self, emu, argv, ctx={}): + def USBD_ValidateConfigurationDescriptor(self, emu, argv, ctx: api.ApiContext = None): """ USBD_STATUS USBD_ValidateConfigurationDescriptor( PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, diff --git a/speakeasy/winenv/api/kernelmode/wdfldr.py b/speakeasy/winenv/api/kernelmode/wdfldr.py index d52bf24a..74415417 100644 --- a/speakeasy/winenv/api/kernelmode/wdfldr.py +++ b/speakeasy/winenv/api/kernelmode/wdfldr.py @@ -195,7 +195,7 @@ def parse_usb_config(self, data): return interfaces @apihook("WdfVersionBind", argc=4) - def WdfVersionBind(self, emu, argv, ctx={}): + def WdfVersionBind(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfVersionBind( @@ -228,7 +228,7 @@ def WdfVersionBind(self, emu, argv, ctx={}): return rv @apihook("WdfDriverCreate", argc=6) - def WdfDriverCreate(self, emu, argv, ctx={}): + def WdfDriverCreate(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfDriverCreate( PWDF_DRIVER_GLOBALS DriverGlobals, @@ -258,7 +258,7 @@ def WdfDriverCreate(self, emu, argv, ctx={}): return rv @apihook("WdfDeviceInitSetPnpPowerEventCallbacks", argc=3) - def WdfDeviceInitSetPnpPowerEventCallbacks(self, emu, argv, ctx={}): + def WdfDeviceInitSetPnpPowerEventCallbacks(self, emu, argv, ctx: api.ApiContext = None): """ void WdfDeviceInitSetPnpPowerEventCallbacks( PWDFDEVICE_INIT DeviceInit, @@ -270,7 +270,7 @@ def WdfDeviceInitSetPnpPowerEventCallbacks(self, emu, argv, ctx={}): return @apihook("WdfDeviceInitSetRequestAttributes", argc=3) - def WdfDeviceInitSetRequestAttributes(self, emu, argv, ctx={}): + def WdfDeviceInitSetRequestAttributes(self, emu, argv, ctx: api.ApiContext = None): """ void WdfDeviceInitSetRequestAttributes( PWDFDEVICE_INIT DeviceInit, @@ -282,7 +282,7 @@ def WdfDeviceInitSetRequestAttributes(self, emu, argv, ctx={}): return @apihook("WdfDeviceInitSetFileObjectConfig", argc=4) - def WdfDeviceInitSetFileObjectConfig(self, emu, argv, ctx={}): + def WdfDeviceInitSetFileObjectConfig(self, emu, argv, ctx: api.ApiContext = None): """ void WdfDeviceInitSetFileObjectConfig( PWDFDEVICE_INIT DeviceInit, @@ -295,7 +295,7 @@ def WdfDeviceInitSetFileObjectConfig(self, emu, argv, ctx={}): return @apihook("WdfDeviceInitSetIoType", argc=3) - def WdfDeviceInitSetIoType(self, emu, argv, ctx={}): + def WdfDeviceInitSetIoType(self, emu, argv, ctx: api.ApiContext = None): """ void WdfDeviceInitSetIoType( PWDFDEVICE_INIT DeviceInit, @@ -307,7 +307,7 @@ def WdfDeviceInitSetIoType(self, emu, argv, ctx={}): return @apihook("WdfDeviceCreate", argc=4) - def WdfDeviceCreate(self, emu, argv, ctx={}): + def WdfDeviceCreate(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfDeviceCreate( PWDFDEVICE_INIT *DeviceInit, @@ -336,7 +336,7 @@ def WdfDeviceCreate(self, emu, argv, ctx={}): return rv @apihook("WdfObjectGetTypedContextWorker", argc=3, conv=e_arch.CALL_CONV_FASTCALL) - def WdfObjectGetTypedContextWorker(self, emu, argv, ctx={}): + def WdfObjectGetTypedContextWorker(self, emu, argv, ctx: api.ApiContext = None): """ PVOID WdfObjectGetTypedContextWorker( WDFOBJECT Handle, @@ -355,7 +355,7 @@ def WdfObjectGetTypedContextWorker(self, emu, argv, ctx={}): return rv @apihook("WdfDriverOpenParametersRegistryKey", argc=5) - def WdfDriverOpenParametersRegistryKey(self, emu, argv, ctx={}): + def WdfDriverOpenParametersRegistryKey(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfDriverOpenParametersRegistryKey( WDFDRIVER Driver, @@ -379,7 +379,7 @@ def WdfDriverOpenParametersRegistryKey(self, emu, argv, ctx={}): return rv @apihook("WdfRegistryQueryULong", argc=4) - def WdfRegistryQueryULong(self, emu, argv, ctx={}): + def WdfRegistryQueryULong(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfRegistryQueryULong( WDFKEY Key, @@ -403,7 +403,7 @@ def WdfRegistryQueryULong(self, emu, argv, ctx={}): return rv @apihook("WdfRegistryClose", argc=2) - def WdfRegistryClose(self, emu, argv, ctx={}): + def WdfRegistryClose(self, emu, argv, ctx: api.ApiContext = None): """ void WdfRegistryClose( WDFKEY Key @@ -413,7 +413,7 @@ def WdfRegistryClose(self, emu, argv, ctx={}): return @apihook("WdfDeviceSetPnpCapabilities", argc=3) - def WdfDeviceSetPnpCapabilities(self, emu, argv, ctx={}): + def WdfDeviceSetPnpCapabilities(self, emu, argv, ctx: api.ApiContext = None): """ void WdfDeviceSetPnpCapabilities( WDFDEVICE Device, @@ -424,7 +424,7 @@ def WdfDeviceSetPnpCapabilities(self, emu, argv, ctx={}): return @apihook("WdfIoQueueReadyNotify", argc=4) - def WdfIoQueueReadyNotify(self, emu, argv, ctx={}): + def WdfIoQueueReadyNotify(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfIoQueueReadyNotify( WDFQUEUE Queue, @@ -438,7 +438,7 @@ def WdfIoQueueReadyNotify(self, emu, argv, ctx={}): return rv @apihook("WdfDeviceCreateDeviceInterface", argc=4) - def WdfDeviceCreateDeviceInterface(self, emu, argv, ctx={}): + def WdfDeviceCreateDeviceInterface(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfDeviceCreateDeviceInterface( WDFDEVICE Device, @@ -461,7 +461,7 @@ def WdfDeviceCreateDeviceInterface(self, emu, argv, ctx={}): return rv @apihook("WdfIoQueueCreate", argc=5) - def WdfIoQueueCreate(self, emu, argv, ctx={}): + def WdfIoQueueCreate(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfIoQueueCreate( WDFDEVICE Device, @@ -486,7 +486,7 @@ def WdfIoQueueCreate(self, emu, argv, ctx={}): return rv @apihook("WdfDeviceWdmGetAttachedDevice", argc=2) - def WdfDeviceWdmGetAttachedDevice(self, emu, argv, ctx={}): + def WdfDeviceWdmGetAttachedDevice(self, emu, argv, ctx: api.ApiContext = None): """ PDEVICE_OBJECT WdfDeviceWdmGetAttachedDevice( WDFDEVICE Device @@ -502,7 +502,7 @@ def WdfDeviceWdmGetAttachedDevice(self, emu, argv, ctx={}): return rv @apihook("WdfUsbTargetDeviceCreateWithParameters", argc=5) - def WdfUsbTargetDeviceCreateWithParameters(self, emu, argv, ctx={}): + def WdfUsbTargetDeviceCreateWithParameters(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfUsbTargetDeviceCreateWithParameters( WDFDEVICE Device, @@ -523,7 +523,7 @@ def WdfUsbTargetDeviceCreateWithParameters(self, emu, argv, ctx={}): return rv @apihook("WdfDeviceWdmGetDeviceObject", argc=2) - def WdfDeviceWdmGetDeviceObject(self, emu, argv, ctx={}): + def WdfDeviceWdmGetDeviceObject(self, emu, argv, ctx: api.ApiContext = None): """ PDEVICE_OBJECT WdfDeviceWdmGetDeviceObject( WDFDEVICE Device @@ -538,7 +538,7 @@ def WdfDeviceWdmGetDeviceObject(self, emu, argv, ctx={}): return rv @apihook("WdfUsbTargetDeviceGetDeviceDescriptor", argc=3) - def WdfUsbTargetDeviceGetDeviceDescriptor(self, emu, argv, ctx={}): + def WdfUsbTargetDeviceGetDeviceDescriptor(self, emu, argv, ctx: api.ApiContext = None): """ void WdfUsbTargetDeviceGetDeviceDescriptor( WDFUSBDEVICE UsbDevice, @@ -554,7 +554,7 @@ def WdfUsbTargetDeviceGetDeviceDescriptor(self, emu, argv, ctx={}): return @apihook("WdfMemoryCreate", argc=7) - def WdfMemoryCreate(self, emu, argv, ctx={}): + def WdfMemoryCreate(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfMemoryCreate( PWDF_OBJECT_ATTRIBUTES Attributes, @@ -579,7 +579,7 @@ def WdfMemoryCreate(self, emu, argv, ctx={}): return rv @apihook("WdfUsbTargetDeviceSelectConfig", argc=4) - def WdfUsbTargetDeviceSelectConfig(self, emu, argv, ctx={}): + def WdfUsbTargetDeviceSelectConfig(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfUsbTargetDeviceSelectConfig( WDFUSBDEVICE UsbDevice, @@ -614,7 +614,7 @@ def WdfUsbTargetDeviceSelectConfig(self, emu, argv, ctx={}): return rv @apihook("WdfUsbTargetDeviceRetrieveConfigDescriptor", argc=4) - def WdfUsbTargetDeviceRetrieveConfigDescriptor(self, emu, argv, ctx={}): + def WdfUsbTargetDeviceRetrieveConfigDescriptor(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfUsbTargetDeviceRetrieveConfigDescriptor( WDFUSBDEVICE UsbDevice, @@ -647,7 +647,7 @@ def WdfUsbTargetDeviceRetrieveConfigDescriptor(self, emu, argv, ctx={}): return rv @apihook("WdfUsbInterfaceSelectSetting", argc=4) - def WdfUsbInterfaceSelectSetting(self, emu, argv, ctx={}): + def WdfUsbInterfaceSelectSetting(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfUsbInterfaceSelectSetting( WDFUSBINTERFACE UsbInterface, @@ -671,7 +671,7 @@ def WdfUsbInterfaceSelectSetting(self, emu, argv, ctx={}): return rv @apihook("WdfUsbTargetDeviceGetNumInterfaces", argc=2) - def WdfUsbTargetDeviceGetNumInterfaces(self, emu, argv, ctx={}): + def WdfUsbTargetDeviceGetNumInterfaces(self, emu, argv, ctx: api.ApiContext = None): """ UCHAR WdfUsbTargetDeviceGetNumInterfaces( WDFUSBDEVICE UsbDevice @@ -687,7 +687,7 @@ def WdfUsbTargetDeviceGetNumInterfaces(self, emu, argv, ctx={}): return rv @apihook("WdfUsbInterfaceGetNumConfiguredPipes", argc=2) - def WdfUsbInterfaceGetNumConfiguredPipes(self, emu, argv, ctx={}): + def WdfUsbInterfaceGetNumConfiguredPipes(self, emu, argv, ctx: api.ApiContext = None): """ BYTE WdfUsbInterfaceGetNumConfiguredPipes( WDFUSBINTERFACE UsbInterface @@ -708,7 +708,7 @@ def WdfUsbInterfaceGetNumConfiguredPipes(self, emu, argv, ctx={}): return rv @apihook("WdfUsbInterfaceGetNumSettings", argc=2) - def WdfUsbInterfaceGetNumSettings(self, emu, argv, ctx={}): + def WdfUsbInterfaceGetNumSettings(self, emu, argv, ctx: api.ApiContext = None): """ BYTE WdfUsbInterfaceGetNumSettings( WDFUSBINTERFACE UsbInterface @@ -728,7 +728,7 @@ def WdfUsbInterfaceGetNumSettings(self, emu, argv, ctx={}): return rv @apihook("WdfUsbTargetDeviceRetrieveInformation", argc=3) - def WdfUsbTargetDeviceRetrieveInformation(self, emu, argv, ctx={}): + def WdfUsbTargetDeviceRetrieveInformation(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS WdfUsbTargetDeviceRetrieveInformation( WDFUSBDEVICE UsbDevice, @@ -750,7 +750,7 @@ def WdfUsbTargetDeviceRetrieveInformation(self, emu, argv, ctx={}): return rv @apihook("WdfUsbInterfaceGetConfiguredPipe", argc=4) - def WdfUsbInterfaceGetConfiguredPipe(self, emu, argv, ctx={}): + def WdfUsbInterfaceGetConfiguredPipe(self, emu, argv, ctx: api.ApiContext = None): """ WDFUSBPIPE WdfUsbInterfaceGetConfiguredPipe( WDFUSBINTERFACE UsbInterface, @@ -796,7 +796,7 @@ def WdfUsbInterfaceGetConfiguredPipe(self, emu, argv, ctx={}): return rv @apihook("WdfUsbTargetPipeGetInformation", argc=3) - def WdfUsbTargetPipeGetInformation(self, emu, argv, ctx={}): + def WdfUsbTargetPipeGetInformation(self, emu, argv, ctx: api.ApiContext = None): """ void WdfUsbTargetPipeGetInformation( WDFUSBPIPE Pipe, @@ -835,7 +835,7 @@ def WdfUsbTargetPipeGetInformation(self, emu, argv, ctx={}): return @apihook("WdfUsbInterfaceGetInterfaceNumber", argc=2) - def WdfUsbInterfaceGetInterfaceNumber(self, emu, argv, ctx={}): + def WdfUsbInterfaceGetInterfaceNumber(self, emu, argv, ctx: api.ApiContext = None): """ BYTE WdfUsbInterfaceGetInterfaceNumber( WDFUSBINTERFACE UsbInterface diff --git a/speakeasy/winenv/api/usermode/advapi32.py b/speakeasy/winenv/api/usermode/advapi32.py index 84a26554..c8e84668 100644 --- a/speakeasy/winenv/api/usermode/advapi32.py +++ b/speakeasy/winenv/api/usermode/advapi32.py @@ -48,7 +48,7 @@ def get_handle(self): return self.curr_handle @apihook("RegOpenKey", argc=3, conv=_arch.CALL_CONV_STDCALL) - def RegOpenKey(self, emu, argv, ctx={}): + def RegOpenKey(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegOpenKeyA( HKEY hKey, @@ -56,6 +56,7 @@ def RegOpenKey(self, emu, argv, ctx={}): PHKEY phkResult ); """ + ctx = ctx or {} hKey, lpSubKey, phkResult = argv rv = windefs.ERROR_SUCCESS @@ -94,7 +95,7 @@ def RegOpenKey(self, emu, argv, ctx={}): return rv @apihook("RegOpenKeyEx", argc=5, conv=_arch.CALL_CONV_STDCALL) - def RegOpenKeyEx(self, emu, argv, ctx={}): + def RegOpenKeyEx(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegOpenKeyEx( HKEY hKey, @@ -104,6 +105,7 @@ def RegOpenKeyEx(self, emu, argv, ctx={}): PHKEY phkResult ); """ + ctx = ctx or {} hKey, lpSubKey, ulOptions, samDesired, phkResult = argv rv = windefs.ERROR_SUCCESS @@ -138,7 +140,7 @@ def RegOpenKeyEx(self, emu, argv, ctx={}): return rv @apihook("RegQueryValueEx", argc=6, conv=_arch.CALL_CONV_STDCALL) - def RegQueryValueEx(self, emu, argv, ctx={}): + def RegQueryValueEx(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegQueryValueEx( HKEY hKey, @@ -149,6 +151,7 @@ def RegQueryValueEx(self, emu, argv, ctx={}): LPDWORD lpcbData ); """ + ctx = ctx or {} hKey, lpValueName, lpReserved, lpType, lpData, lpcbData = argv rv = windefs.ERROR_SUCCESS @@ -215,7 +218,7 @@ def RegQueryValueEx(self, emu, argv, ctx={}): return rv @apihook("RegSetValueEx", argc=6, conv=_arch.CALL_CONV_STDCALL) - def RegSetValueEx(self, emu, argv, ctx={}): + def RegSetValueEx(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegSetValueEx( HKEY hKey, @@ -226,6 +229,7 @@ def RegSetValueEx(self, emu, argv, ctx={}): DWORD cbData ); """ + ctx = ctx or {} hKey, lpValueName, _reserved, dwType, lpData, cbData = argv @@ -273,7 +277,7 @@ def RegSetValueEx(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("RegCloseKey", argc=1, conv=_arch.CALL_CONV_STDCALL) - def RegCloseKey(self, emu, argv, ctx={}): + def RegCloseKey(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegCloseKey( HKEY hKey @@ -290,7 +294,7 @@ def RegCloseKey(self, emu, argv, ctx={}): return rv @apihook("RegEnumKey", argc=4, conv=_arch.CALL_CONV_STDCALL) - def RegEnumKey(self, emu, argv, ctx={}): + def RegEnumKey(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegEnumKey( HKEY hKey, @@ -299,6 +303,7 @@ def RegEnumKey(self, emu, argv, ctx={}): DWORD cchName ); """ + ctx = ctx or {} hKey, dwIndex, lpName, cchName = argv @@ -309,7 +314,7 @@ def RegEnumKey(self, emu, argv, ctx={}): return rv @apihook("RegEnumKeyEx", argc=8, conv=_arch.CALL_CONV_STDCALL) - def RegEnumKeyEx(self, emu, argv, ctx={}): + def RegEnumKeyEx(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegEnumKeyEx( HKEY hKey, @@ -322,6 +327,7 @@ def RegEnumKeyEx(self, emu, argv, ctx={}): PFILETIME lpftLastWriteTime ); """ + ctx = ctx or {} hKey, dwIndex, lpName, cchName, res, pcls, cchcls, last_write = argv @@ -350,7 +356,7 @@ def RegEnumKeyEx(self, emu, argv, ctx={}): return rv @apihook("RegCreateKey", argc=3) - def RegCreateKey(self, emu, argv, ctx={}): + def RegCreateKey(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegCreateKey( HKEY hKey, @@ -358,6 +364,7 @@ def RegCreateKey(self, emu, argv, ctx={}): PHKEY phkResult ); """ + ctx = ctx or {} hkey, lpSubKey, phkResult = argv rv = windefs.ERROR_INVALID_HANDLE if hkey: @@ -380,7 +387,7 @@ def RegCreateKey(self, emu, argv, ctx={}): return rv @apihook("RegCreateKeyEx", argc=9, conv=_arch.CALL_CONV_STDCALL) - def RegCreateKeyEx(self, emu, argv, ctx={}): + def RegCreateKeyEx(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegCreateKeyExA( HKEY hKey, @@ -394,6 +401,7 @@ def RegCreateKeyEx(self, emu, argv, ctx={}): LPDWORD lpdwDisposition ); """ + ctx = ctx or {} hKey, lpSubKey, _reserved, _lpClass, _dwOptions, _samDesired, _sa, phkResult, lpdwDisposition = argv key_path = "" @@ -432,13 +440,14 @@ def RegCreateKeyEx(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("RegDeleteValue", argc=2, conv=_arch.CALL_CONV_STDCALL) - def RegDeleteValue(self, emu, argv, ctx={}): + def RegDeleteValue(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegDeleteValueA( HKEY hKey, LPCSTR lpValueName ); """ + ctx = ctx or {} hKey, lpValueName = argv key = self.reg_get_key(hKey) @@ -459,7 +468,7 @@ def RegDeleteValue(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("RegQueryInfoKey", argc=12, conv=_arch.CALL_CONV_STDCALL) - def RegQueryInfoKey(self, emu, argv, ctx={}): + def RegQueryInfoKey(self, emu, argv, ctx: api.ApiContext = None): # TODO: stub """ LSTATUS RegQueryInfoKeyA( @@ -506,7 +515,7 @@ def RegQueryInfoKey(self, emu, argv, ctx={}): return rv @apihook("OpenProcessToken", argc=3, conv=_arch.CALL_CONV_STDCALL) - def OpenProcessToken(self, emu, argv, ctx={}): + def OpenProcessToken(self, emu, argv, ctx: api.ApiContext = None): """ BOOL OpenProcessToken( HANDLE ProcessHandle, @@ -538,7 +547,7 @@ def OpenProcessToken(self, emu, argv, ctx={}): return rv @apihook("OpenThreadToken", argc=4, conv=_arch.CALL_CONV_STDCALL) - def OpenThreadToken(self, emu, argv, ctx={}): + def OpenThreadToken(self, emu, argv, ctx: api.ApiContext = None): """ BOOL OpenThreadToken( HANDLE ThreadHandle, @@ -571,7 +580,7 @@ def OpenThreadToken(self, emu, argv, ctx={}): return rv @apihook("DuplicateTokenEx", argc=6, conv=_arch.CALL_CONV_STDCALL) - def DuplicateTokenEx(self, emu, argv, ctx={}): + def DuplicateTokenEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DuplicateTokenEx( HANDLE hExistingToken, @@ -603,7 +612,7 @@ def DuplicateTokenEx(self, emu, argv, ctx={}): return rv @apihook("SetTokenInformation", argc=4, conv=_arch.CALL_CONV_STDCALL) - def SetTokenInformation(self, emu, argv, ctx={}): + def SetTokenInformation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetTokenInformation( HANDLE TokenHandle, @@ -620,12 +629,13 @@ def SetTokenInformation(self, emu, argv, ctx={}): return rv @apihook("StartServiceCtrlDispatcher", argc=1) - def StartServiceCtrlDispatcher(self, emu, argv, ctx={}): + def StartServiceCtrlDispatcher(self, emu, argv, ctx: api.ApiContext = None): """ BOOL StartServiceCtrlDispatcher( const SERVICE_TABLE_ENTRY *lpServiceStartTable ); """ + ctx = ctx or {} (lpServiceStartTable,) = argv try: @@ -666,7 +676,7 @@ def StartServiceCtrlDispatcher(self, emu, argv, ctx={}): return rv @apihook("RegisterServiceCtrlHandler", argc=2) - def RegisterServiceCtrlHandler(self, emu, argv, ctx={}): + def RegisterServiceCtrlHandler(self, emu, argv, ctx: api.ApiContext = None): """ SERVICE_STATUS_HANDLE RegisterServiceCtrlHandlerA( LPCSTR lpServiceName, @@ -684,7 +694,7 @@ def RegisterServiceCtrlHandler(self, emu, argv, ctx={}): return self.service_status_handle @apihook("RegisterServiceCtrlHandlerEx", argc=3) - def RegisterServiceCtrlHandlerEx(self, emu, argv, ctx={}): + def RegisterServiceCtrlHandlerEx(self, emu, argv, ctx: api.ApiContext = None): """ SERVICE_STATUS_HANDLE RegisterServiceCtrlHandlerExA( LPCSTR lpServiceName, @@ -692,12 +702,13 @@ def RegisterServiceCtrlHandlerEx(self, emu, argv, ctx={}): LPVOID lpContext ); """ + ctx = ctx or {} lpServiceName, lpHandlerProc, lpContext = argv return self.RegisterServiceCtrlHandler(self, emu, [lpServiceName, lpHandlerProc], ctx) @apihook("SetServiceStatus", argc=2) - def SetServiceStatus(self, emu, argv, ctx={}): + def SetServiceStatus(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetServiceStatus( SERVICE_STATUS_HANDLE hServiceStatus, @@ -712,14 +723,14 @@ def SetServiceStatus(self, emu, argv, ctx={}): return 0x1 @apihook("RevertToSelf", argc=0) - def RevertToSelf(self, emu, argv, ctx={}): + def RevertToSelf(self, emu, argv, ctx: api.ApiContext = None): """ BOOL RevertToSelf(); """ return 1 @apihook("ImpersonateLoggedOnUser", argc=1) - def ImpersonateLoggedOnUser(self, emu, argv, ctx={}): + def ImpersonateLoggedOnUser(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ImpersonateLoggedOnUser( HANDLE hToken @@ -728,7 +739,7 @@ def ImpersonateLoggedOnUser(self, emu, argv, ctx={}): return 1 @apihook("OpenSCManager", argc=3) - def OpenSCManager(self, emu, argv, ctx={}): + def OpenSCManager(self, emu, argv, ctx: api.ApiContext = None): """ SC_HANDLE OpenSCManager( LPCSTR lpMachineName, @@ -744,7 +755,7 @@ def OpenSCManager(self, emu, argv, ctx={}): return hScm @apihook("CreateService", argc=13) - def CreateService(self, emu, argv, ctx={}): + def CreateService(self, emu, argv, ctx: api.ApiContext = None): """ SC_HANDLE CreateServiceA( SC_HANDLE hSCManager, @@ -762,6 +773,7 @@ def CreateService(self, emu, argv, ctx={}): LPCSTR lpPassword ); """ + ctx = ctx or {} ( hScm, svc_name, @@ -796,7 +808,7 @@ def CreateService(self, emu, argv, ctx={}): return hSvc @apihook("StartService", argc=3) - def StartService(self, emu, argv, ctx={}): + def StartService(self, emu, argv, ctx: api.ApiContext = None): """ BOOL StartService( SC_HANDLE hService, @@ -813,11 +825,12 @@ def StartService(self, emu, argv, ctx={}): return rv @apihook("StartServiceA", argc=3) - def StartServiceA(self, emu, argv, ctx={}): + def StartServiceA(self, emu, argv, ctx: api.ApiContext = None): + ctx = ctx or {} return self.StartService(emu, argv, ctx) @apihook("ControlService", argc=3) - def ControlService(self, emu, argv, ctx={}): + def ControlService(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ControlService( [in] SC_HANDLE hService, @@ -834,7 +847,7 @@ def ControlService(self, emu, argv, ctx={}): return rv @apihook("QueryServiceStatus", argc=2) - def QueryServiceStatus(self, emu, argv, ctx={}): + def QueryServiceStatus(self, emu, argv, ctx: api.ApiContext = None): """ BOOL QueryServiceStatus( SC_HANDLE hService, @@ -865,7 +878,7 @@ def QueryServiceStatus(self, emu, argv, ctx={}): @apihook("QueryServiceConfig", argc=4) @apihook("QueryServiceConfigA", argc=4) @apihook("QueryServiceConfigW", argc=4) - def QueryServiceConfig(self, emu, argv, ctx={}): + def QueryServiceConfig(self, emu, argv, ctx: api.ApiContext = None): """ BOOL QueryServiceConfigA( SC_HANDLE hService, @@ -906,7 +919,7 @@ def QueryServiceConfig(self, emu, argv, ctx={}): return 1 @apihook("CloseServiceHandle", argc=1) - def CloseServiceHandle(self, emu, argv, ctx={}): + def CloseServiceHandle(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CloseServiceHandle( SC_HANDLE hSCObject @@ -923,7 +936,7 @@ def CloseServiceHandle(self, emu, argv, ctx={}): return rv @apihook("ChangeServiceConfig", argc=11) - def ChangeServiceConfig(self, emu, argv, ctx={}): + def ChangeServiceConfig(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ChangeServiceConfigA( SC_HANDLE hService, @@ -939,6 +952,7 @@ def ChangeServiceConfig(self, emu, argv, ctx={}): LPCSTR lpDisplayName ); """ + ctx = ctx or {} ( _hService, _dwServiceType, @@ -972,7 +986,7 @@ def ChangeServiceConfig(self, emu, argv, ctx={}): return 1 @apihook("ChangeServiceConfig2", argc=3) - def ChangeServiceConfig2(self, emu, argv, ctx={}): + def ChangeServiceConfig2(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ChangeServiceConfig2( SC_HANDLE hService, @@ -989,7 +1003,7 @@ def ChangeServiceConfig2(self, emu, argv, ctx={}): return rv @apihook("SystemFunction036", argc=2) - def RtlGenRandom(self, emu, argv, ctx={}): + def RtlGenRandom(self, emu, argv, ctx: api.ApiContext = None): """ BOOLEAN RtlGenRandom( PVOID RandomBuffer, @@ -1007,7 +1021,7 @@ def RtlGenRandom(self, emu, argv, ctx={}): return rv @apihook("CryptAcquireContext", argc=5) - def CryptAcquireContext(self, emu, argv, ctx={}): + def CryptAcquireContext(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptAcquireContext( HCRYPTPROV *phProv, @@ -1017,6 +1031,7 @@ def CryptAcquireContext(self, emu, argv, ctx={}): DWORD dwFlags ); """ + ctx = ctx or {} phProv, szContainer, szProvider, dwProvType, dwFlags = argv cont_str, prov_str = "", "" cw = self.get_char_width(ctx) @@ -1040,7 +1055,7 @@ def CryptAcquireContext(self, emu, argv, ctx={}): return rv @apihook("CryptGenRandom", argc=3) - def CryptGenRandom(self, emu, argv, ctx={}): + def CryptGenRandom(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptGenRandom( HCRYPTPROV hProv, @@ -1059,7 +1074,7 @@ def CryptGenRandom(self, emu, argv, ctx={}): return rv @apihook("AllocateAndInitializeSid", argc=11) - def AllocateAndInitializeSid(self, emu, argv, ctx={}): + def AllocateAndInitializeSid(self, emu, argv, ctx: api.ApiContext = None): """ BOOL AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, @@ -1086,7 +1101,7 @@ def AllocateAndInitializeSid(self, emu, argv, ctx={}): return rv @apihook("CheckTokenMembership", argc=3) - def CheckTokenMembership(self, emu, argv, ctx={}): + def CheckTokenMembership(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CheckTokenMembership( HANDLE TokenHandle, @@ -1103,7 +1118,7 @@ def CheckTokenMembership(self, emu, argv, ctx={}): return rv @apihook("FreeSid", argc=1) - def FreeSid(self, emu, argv, ctx={}): + def FreeSid(self, emu, argv, ctx: api.ApiContext = None): """ PVOID FreeSid( PSID pSid @@ -1118,7 +1133,7 @@ def FreeSid(self, emu, argv, ctx={}): return rv @apihook("CryptReleaseContext", argc=2) - def CryptReleaseContext(self, emu, argv, ctx={}): + def CryptReleaseContext(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptReleaseContext( HCRYPTPROV hProv, @@ -1134,12 +1149,13 @@ def CryptReleaseContext(self, emu, argv, ctx={}): return rv @apihook("GetCurrentHwProfile", argc=1) - def GetCurrentHwProfile(self, emu, argv, ctx={}): + def GetCurrentHwProfile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetCurrentHwProfileA( LPHW_PROFILE_INFOA lpHwProfileInfo ); """ + ctx = ctx or {} (lpHwProfileInfo,) = argv if not lpHwProfileInfo: @@ -1167,13 +1183,14 @@ def GetCurrentHwProfile(self, emu, argv, ctx={}): return 1 @apihook("GetUserName", argc=2) - def GetUserName(self, emu, argv, ctx={}): + def GetUserName(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetUserName( LPSTR lpBuffer, LPDWORD pcbBuffer ); """ + ctx = ctx or {} lpBuffer, pcbBuffer = argv rv = False cw = self.get_char_width(ctx) @@ -1194,7 +1211,7 @@ def GetUserName(self, emu, argv, ctx={}): return rv @apihook("LookupPrivilegeValue", argc=3) - def LookupPrivilegeValue(self, emu, argv, ctx={}): + def LookupPrivilegeValue(self, emu, argv, ctx: api.ApiContext = None): """ BOOL LookupPrivilegeValue( LPCSTR lpSystemName, @@ -1202,6 +1219,7 @@ def LookupPrivilegeValue(self, emu, argv, ctx={}): PLUID lpLuid ); """ + ctx = ctx or {} sysname, name, luid = argv rv = False cw = self.get_char_width(ctx) @@ -1217,7 +1235,7 @@ def LookupPrivilegeValue(self, emu, argv, ctx={}): return rv @apihook("AdjustTokenPrivileges", argc=6) - def AdjustTokenPrivileges(self, emu, argv, ctx={}): + def AdjustTokenPrivileges(self, emu, argv, ctx: api.ApiContext = None): """ BOOL AdjustTokenPrivileges( HANDLE TokenHandle, @@ -1233,7 +1251,7 @@ def AdjustTokenPrivileges(self, emu, argv, ctx={}): return rv @apihook("GetTokenInformation", argc=5) - def GetTokenInformation(self, emu, argv, ctx={}): + def GetTokenInformation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetTokenInformation( HANDLE TokenHandle, @@ -1258,7 +1276,7 @@ def GetTokenInformation(self, emu, argv, ctx={}): return rv @apihook("EqualSid", argc=2) - def EqualSid(self, emu, argv, ctx={}): + def EqualSid(self, emu, argv, ctx: api.ApiContext = None): """ BOOL EqualSid( PSID pSid1, @@ -1277,7 +1295,7 @@ def EqualSid(self, emu, argv, ctx={}): return rv @apihook("GetSidIdentifierAuthority", argc=1) - def GetSidIdentifierAuthority(self, emu, argv, ctx={}): + def GetSidIdentifierAuthority(self, emu, argv, ctx: api.ApiContext = None): """ PSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority( [in] PSID pSid @@ -1289,7 +1307,7 @@ def GetSidIdentifierAuthority(self, emu, argv, ctx={}): return sid + 2 @apihook("GetSidSubAuthorityCount", argc=1) - def GetSidSubAuthorityCount(self, emu, argv, ctx={}): + def GetSidSubAuthorityCount(self, emu, argv, ctx: api.ApiContext = None): """ PUCHAR GetSidSubAuthorityCount( PSID pSid @@ -1304,7 +1322,7 @@ def GetSidSubAuthorityCount(self, emu, argv, ctx={}): return rv @apihook("GetSidSubAuthority", argc=2) - def GetSidSubAuthority(self, emu, argv, ctx={}): + def GetSidSubAuthority(self, emu, argv, ctx: api.ApiContext = None): """ PDWORD GetSidSubAuthority( [in] PSID pSid, @@ -1317,7 +1335,7 @@ def GetSidSubAuthority(self, emu, argv, ctx={}): return sid + 8 + (nsub * 4) @apihook("LookupAccountName", argc=7) - def LookupAccountName(self, emu, argv, ctx={}): + def LookupAccountName(self, emu, argv, ctx: api.ApiContext = None): """ BOOL LookupAccountNameA( [in, optional] LPCSTR lpSystemName, @@ -1329,6 +1347,7 @@ def LookupAccountName(self, emu, argv, ctx={}): [out] PSID_NAME_USE peUse ); """ + ctx = ctx or {} ptr_sysname, ptr_acctname, ptr_sid, ptr_cbsid, ptr_domname, ptr_cchdomname, ptr_peuse = argv rv = 0 @@ -1391,7 +1410,7 @@ def LookupAccountName(self, emu, argv, ctx={}): return rv @apihook("LookupAccountSid", argc=7) - def LookupAccountSid(self, emu, argv, ctx={}): + def LookupAccountSid(self, emu, argv, ctx: api.ApiContext = None): """ BOOL LookupAccountSid( LPCSTR lpSystemName, @@ -1403,6 +1422,7 @@ def LookupAccountSid(self, emu, argv, ctx={}): PSID_NAME_USE peUse ); """ + ctx = ctx or {} sysname, sid, name, cchname, domname, cchdomname, peuse = argv rv = False @@ -1428,7 +1448,7 @@ def LookupAccountSid(self, emu, argv, ctx={}): return rv @apihook("CreateProcessAsUser", argc=11, conv=_arch.CALL_CONV_STDCALL) - def CreateProcessAsUser(self, emu, argv, ctx={}): + def CreateProcessAsUser(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CreateProcessAsUser( HANDLE hToken, @@ -1444,6 +1464,7 @@ def CreateProcessAsUser(self, emu, argv, ctx={}): LPPROCESS_INFORMATION lpProcessInformation ); """ + ctx = ctx or {} token, app, cmd, pa, ta, inherit, flags, env, cd, si, ppi = argv cw = self.get_char_width(ctx) @@ -1479,7 +1500,7 @@ def CreateProcessAsUser(self, emu, argv, ctx={}): return rv @apihook("CryptCreateHash", argc=5) - def CryptCreateHash(self, emu, argv, ctx={}): + def CryptCreateHash(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptCreateHash( HCRYPTPROV hProv, @@ -1514,7 +1535,7 @@ def CryptCreateHash(self, emu, argv, ctx={}): return 1 @apihook("CryptHashData", argc=4) - def CryptHashData(self, emu, argv, ctx={}): + def CryptHashData(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptHashData( HCRYPTHASH hHash, @@ -1538,7 +1559,7 @@ def CryptHashData(self, emu, argv, ctx={}): return 1 @apihook("CryptGetHashParam", argc=5) - def CryptGetHashParam(self, emu, argv, ctx={}): + def CryptGetHashParam(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptGetHashParam( HCRYPTHASH hHash, @@ -1558,7 +1579,7 @@ def CryptGetHashParam(self, emu, argv, ctx={}): return 1 @apihook("CryptDestroyHash", argc=1) - def CryptDestroyHash(self, emu, argv, ctx={}): + def CryptDestroyHash(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptDestroyHash( HCRYPTHASH hHash @@ -1567,7 +1588,7 @@ def CryptDestroyHash(self, emu, argv, ctx={}): return 1 @apihook("CryptDeriveKey", argc=5) - def CryptDeriveKey(self, emu, argv, ctx={}): + def CryptDeriveKey(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptDeriveKey( HCRYPTPROV hProv, @@ -1612,7 +1633,7 @@ def CryptDeriveKey(self, emu, argv, ctx={}): return 1 @apihook("CryptDecrypt", argc=6) - def CryptDecrypt(self, emu, argv, ctx={}): + def CryptDecrypt(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptDecrypt( HCRYPTKEY hKey, @@ -1660,7 +1681,7 @@ def CryptDecrypt(self, emu, argv, ctx={}): return 1 @apihook("RegGetValue", argc=7, conv=_arch.CALL_CONV_STDCALL) - def RegGetValue(self, emu, argv, ctx={}): + def RegGetValue(self, emu, argv, ctx: api.ApiContext = None): """ LSTATUS RegGetValueW( HKEY hkey, @@ -1672,6 +1693,7 @@ def RegGetValue(self, emu, argv, ctx={}): LPDWORD pcbData ); """ + ctx = ctx or {} hKey, lpSubKey, lpValue, dwFlags, lpType, lpData, lpcbData = argv rv = windefs.ERROR_SUCCESS @@ -1727,7 +1749,7 @@ def RegGetValue(self, emu, argv, ctx={}): return rv @apihook("EnumServicesStatus", argc=8, conv=_arch.CALL_CONV_STDCALL) - def EnumServicesStatus(self, emu, argv, ctx={}): + def EnumServicesStatus(self, emu, argv, ctx: api.ApiContext = None): """ BOOL EnumServicesStatusA( SC_HANDLE hSCManager, @@ -1763,7 +1785,7 @@ def EnumServicesStatus(self, emu, argv, ctx={}): return 1 @apihook("OpenService", argc=3, conv=_arch.CALL_CONV_STDCALL) - def OpenService(self, emu, argv, ctx={}): + def OpenService(self, emu, argv, ctx: api.ApiContext = None): """ SC_HANDLE OpenServiceA( SC_HANDLE hSCManager, @@ -1771,6 +1793,7 @@ def OpenService(self, emu, argv, ctx={}): DWORD dwDesiredAccess ); """ + ctx = ctx or {} hSCManager, lpServiceName, dwDesiredAccess = argv cw = self.get_char_width(ctx) svcname = self.read_mem_string(lpServiceName, cw) @@ -1778,7 +1801,7 @@ def OpenService(self, emu, argv, ctx={}): return self.get_handle() @apihook("DeleteService", argc=1, conv=_arch.CALL_CONV_STDCALL) - def DeleteService(self, emu, argv, ctx={}): + def DeleteService(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DeleteService( SC_HANDLE hService diff --git a/speakeasy/winenv/api/usermode/advpack.py b/speakeasy/winenv/api/usermode/advpack.py index c4c8c183..990a3c99 100644 --- a/speakeasy/winenv/api/usermode/advpack.py +++ b/speakeasy/winenv/api/usermode/advpack.py @@ -22,7 +22,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("IsNTAdmin", argc=2) - def IsNTAdmin(self, emu, argv, ctx={}): + def IsNTAdmin(self, emu, argv, ctx: api.ApiContext = None): """ bool IsNTAdmin(); """ diff --git a/speakeasy/winenv/api/usermode/bcrypt.py b/speakeasy/winenv/api/usermode/bcrypt.py index 513299a7..5d14570b 100644 --- a/speakeasy/winenv/api/usermode/bcrypt.py +++ b/speakeasy/winenv/api/usermode/bcrypt.py @@ -26,7 +26,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("BCryptOpenAlgorithmProvider", argc=4) - def BCryptOpenAlgorithmProvider(self, emu, argv, ctx={}): + def BCryptOpenAlgorithmProvider(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS BCryptOpenAlgorithmProvider( BCRYPT_ALG_HANDLE *phAlgorithm, @@ -56,7 +56,7 @@ def BCryptOpenAlgorithmProvider(self, emu, argv, ctx={}): return ntdefs.STATUS_SUCCESS @apihook("BCryptImportKeyPair", argc=7) - def BCryptImportKeyPair(self, emu, argv, ctx={}): + def BCryptImportKeyPair(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS BCryptImportKeyPair( BCRYPT_ALG_HANDLE hAlgorithm, @@ -68,6 +68,7 @@ def BCryptImportKeyPair(self, emu, argv, ctx={}): ULONG dwFlags ); """ + ctx = ctx or {} hAlgorithm, hImportKey, pszBlobType, phKey, pbInput, cbInput, dwFlags = argv blob_type = self.read_wide_string(pszBlobType) @@ -88,7 +89,7 @@ def BCryptImportKeyPair(self, emu, argv, ctx={}): return ntdefs.STATUS_SUCCESS @apihook("BCryptCloseAlgorithmProvider", argc=2) - def BCryptCloseAlgorithmProvider(self, emu, argv, ctx={}): + def BCryptCloseAlgorithmProvider(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS BCryptCloseAlgorithmProvider( BCRYPT_ALG_HANDLE hAlgorithm, @@ -104,7 +105,7 @@ def BCryptCloseAlgorithmProvider(self, emu, argv, ctx={}): return ntdefs.STATUS_SUCCESS @apihook("BCryptGetProperty", argc=6) - def BCryptGetProperty(self, emu, argv, ctx={}): + def BCryptGetProperty(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS BCryptGetProperty( BCRYPT_HANDLE hObject, @@ -126,12 +127,13 @@ def BCryptGetProperty(self, emu, argv, ctx={}): return ntdefs.STATUS_SUCCESS @apihook("BCryptDestroyKey", argc=1) - def BCryptDestroyKey(self, emu, argv, ctx={}): + def BCryptDestroyKey(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS BCryptDestroyKey( BCRYPT_KEY_HANDLE hKey ); """ + ctx = ctx or {} (hKey,) = argv cm = emu.get_crypt_manager() for hnd, ctx in cm.ctx_handles.items(): diff --git a/speakeasy/winenv/api/usermode/com_api.py b/speakeasy/winenv/api/usermode/com_api.py index 5e84d760..2c474bfb 100644 --- a/speakeasy/winenv/api/usermode/com_api.py +++ b/speakeasy/winenv/api/usermode/com_api.py @@ -25,7 +25,7 @@ def __init__(self, emu): # First argument (self) is not reflected in method definitions; note this increases argc by 1 @apihook("IUnknown.QueryInterface", argc=3) - def IUnknown_QueryInterface(self, emu, argv, ctx={}): + def IUnknown_QueryInterface(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT QueryInterface( REFIID riid, @@ -36,7 +36,7 @@ def IUnknown_QueryInterface(self, emu, argv, ctx={}): return comdefs.S_OK @apihook("IUnknown.AddRef", argc=1) - def IUnknown_AddRef(self, emu, argv, ctx={}): + def IUnknown_AddRef(self, emu, argv, ctx: api.ApiContext = None): """ ULONG AddRef(); """ @@ -44,7 +44,7 @@ def IUnknown_AddRef(self, emu, argv, ctx={}): return 1 @apihook("IUnknown.Release", argc=1) - def IUnknown_Release(self, emu, argv, ctx={}): + def IUnknown_Release(self, emu, argv, ctx: api.ApiContext = None): """ ULONG Release(); """ @@ -52,7 +52,7 @@ def IUnknown_Release(self, emu, argv, ctx={}): return 0 @apihook("IWbemLocator.ConnectServer", argc=9) - def IWbemLocator_ConnectServer(self, emu, argv, ctx={}): + def IWbemLocator_ConnectServer(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT ConnectServer( const BSTR strNetworkResource, @@ -77,7 +77,7 @@ def IWbemLocator_ConnectServer(self, emu, argv, ctx={}): return comdefs.S_OK @apihook("IWbemServices.ExecQuery", argc=6) - def IWbemServices_ExecQuery(self, emu, argv, ctx={}): + def IWbemServices_ExecQuery(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT ExecQuery( const BSTR strQueryLanguage, diff --git a/speakeasy/winenv/api/usermode/comctl32.py b/speakeasy/winenv/api/usermode/comctl32.py index 2b21eada..431e3f2d 100644 --- a/speakeasy/winenv/api/usermode/comctl32.py +++ b/speakeasy/winenv/api/usermode/comctl32.py @@ -19,7 +19,7 @@ def __init__(self, emu): self.names = {} @apihook("InitCommonControlsEx", argc=1) - def InitCommonControlsEx(self, emu, argv, ctx={}): + def InitCommonControlsEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL InitCommonControlsEx( const INITCOMMONCONTROLSEX *picce @@ -31,7 +31,7 @@ def InitCommonControlsEx(self, emu, argv, ctx={}): return rv @apihook("InitCommonControls", argc=0) - def InitCommonControls(self, emu, argv, ctx={}): + def InitCommonControls(self, emu, argv, ctx: api.ApiContext = None): """ void InitCommonControls(); diff --git a/speakeasy/winenv/api/usermode/crypt32.py b/speakeasy/winenv/api/usermode/crypt32.py index d27f48a2..53abcb0d 100644 --- a/speakeasy/winenv/api/usermode/crypt32.py +++ b/speakeasy/winenv/api/usermode/crypt32.py @@ -28,7 +28,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("CryptStringToBinary", argc=7) - def CryptStringToBinary(self, emu, argv, ctx={}): + def CryptStringToBinary(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CryptStringToBinaryA( LPCSTR pszString, @@ -40,6 +40,7 @@ def CryptStringToBinary(self, emu, argv, ctx={}): DWORD *pdwFlags ); """ + ctx = ctx or {} cw = self.get_char_width(ctx) diff --git a/speakeasy/winenv/api/usermode/dnsapi.py b/speakeasy/winenv/api/usermode/dnsapi.py index bac2bf41..e2dc8e27 100644 --- a/speakeasy/winenv/api/usermode/dnsapi.py +++ b/speakeasy/winenv/api/usermode/dnsapi.py @@ -44,7 +44,7 @@ def __init__(self, emu): self.names = {} @apihook("DnsQuery_", argc=6) - def DnsQuery_(self, emu, argv, ctx={}): + def DnsQuery_(self, emu, argv, ctx: api.ApiContext = None): """ DNS_STATUS DnsQuery_A( PCSTR pszName, @@ -55,6 +55,7 @@ def DnsQuery_(self, emu, argv, ctx={}): PVOID *pReserved ); """ + ctx = ctx or {} pszName, wType, Options, pExtra, ppQueryResults, pReserved = argv rv = windefs.ERROR_INVALID_PARAMETER diff --git a/speakeasy/winenv/api/usermode/gdi32.py b/speakeasy/winenv/api/usermode/gdi32.py index 5d1c02db..38e49e93 100644 --- a/speakeasy/winenv/api/usermode/gdi32.py +++ b/speakeasy/winenv/api/usermode/gdi32.py @@ -28,7 +28,7 @@ def get_handle(self): return hnd @apihook("CreateBitmap", argc=5) - def CreateBitmap(self, emu, argv, ctx={}): + def CreateBitmap(self, emu, argv, ctx: api.ApiContext = None): """ HBITMAP CreateBitmap( int nWidth, @@ -41,7 +41,7 @@ def CreateBitmap(self, emu, argv, ctx={}): return self.get_handle() @apihook("MoveToEx", argc=1) - def MoveToEx(self, emu, argv, ctx={}): + def MoveToEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL MoveToEx( HDC hdc, @@ -53,7 +53,7 @@ def MoveToEx(self, emu, argv, ctx={}): return 1 @apihook("LineTo", argc=1) - def LineTo(self, emu, argv, ctx={}): + def LineTo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL LineTo( HDC hdc, @@ -64,7 +64,7 @@ def LineTo(self, emu, argv, ctx={}): return 1 @apihook("GetStockObject", argc=1) - def GetStockObject(self, emu, argv, ctx={}): + def GetStockObject(self, emu, argv, ctx: api.ApiContext = None): """ HGDIOBJ GetStockObject( int i @@ -73,7 +73,7 @@ def GetStockObject(self, emu, argv, ctx={}): return 0 @apihook("GetMapMode", argc=1) - def GetMapMode(self, emu, argv, ctx={}): + def GetMapMode(self, emu, argv, ctx: api.ApiContext = None): """ int GetMapMode( HDC hdc @@ -82,7 +82,7 @@ def GetMapMode(self, emu, argv, ctx={}): return 1 @apihook("GetDeviceCaps", argc=2) - def GetDeviceCaps(self, emu, argv, ctx={}): + def GetDeviceCaps(self, emu, argv, ctx: api.ApiContext = None): """ int GetDeviceCaps( HDC hdc, @@ -92,7 +92,7 @@ def GetDeviceCaps(self, emu, argv, ctx={}): return 16 @apihook("GdiSetBatchLimit", argc=1) - def GdiSetBatchLimit(self, emu, argv, ctx={}): + def GdiSetBatchLimit(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GdiSetBatchLimit( DWORD dw @@ -101,7 +101,7 @@ def GdiSetBatchLimit(self, emu, argv, ctx={}): return 0 @apihook("MaskBlt", argc=12) - def MaskBlt(self, emu, argv, ctx={}): + def MaskBlt(self, emu, argv, ctx: api.ApiContext = None): """ BOOL MaskBlt( HDC hdcDest, @@ -121,7 +121,7 @@ def MaskBlt(self, emu, argv, ctx={}): return 1 @apihook("BitBlt", argc=9) - def BitBlt(self, emu, argv, ctx={}): + def BitBlt(self, emu, argv, ctx: api.ApiContext = None): """ BOOL BitBlt( HDC hdc, @@ -137,7 +137,7 @@ def BitBlt(self, emu, argv, ctx={}): return 1 @apihook("DeleteDC", argc=1) - def DeleteDC(self, emu, argv, ctx={}): + def DeleteDC(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DeleteDC( HDC hdc @@ -146,7 +146,7 @@ def DeleteDC(self, emu, argv, ctx={}): return 1 @apihook("SelectObject", argc=2) - def SelectObject(self, emu, argv, ctx={}): + def SelectObject(self, emu, argv, ctx: api.ApiContext = None): """ HGDIOBJ SelectObject( HDC hdc, @@ -156,7 +156,7 @@ def SelectObject(self, emu, argv, ctx={}): return 0 @apihook("DeleteObject", argc=1) - def DeleteObject(self, emu, argv, ctx={}): + def DeleteObject(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DeleteObject( HGDIOBJ ho @@ -165,7 +165,7 @@ def DeleteObject(self, emu, argv, ctx={}): return 1 @apihook("CreateCompatibleBitmap", argc=3) - def CreateCompatibleBitmap(self, emu, argv, ctx={}): + def CreateCompatibleBitmap(self, emu, argv, ctx: api.ApiContext = None): """ HBITMAP CreateCompatibleBitmap( HDC hdc, @@ -176,7 +176,7 @@ def CreateCompatibleBitmap(self, emu, argv, ctx={}): return 0 @apihook("CreateCompatibleDC", argc=1) - def CreateCompatibleDC(self, emu, argv, ctx={}): + def CreateCompatibleDC(self, emu, argv, ctx: api.ApiContext = None): """ HDC CreateCompatibleDC( HDC hdc @@ -185,7 +185,7 @@ def CreateCompatibleDC(self, emu, argv, ctx={}): return 0 @apihook("GetDIBits", argc=7) - def GetDIBits(self, emu, argv, ctx={}): + def GetDIBits(self, emu, argv, ctx: api.ApiContext = None): """ int GetDIBits( HDC hdc, @@ -200,7 +200,7 @@ def GetDIBits(self, emu, argv, ctx={}): return 0 @apihook("CreateDIBSection", argc=6) - def CreateDIBSection(self, emu, argv, ctx={}): + def CreateDIBSection(self, emu, argv, ctx: api.ApiContext = None): """ HBITMAP CreateDIBSection( [in] HDC hdc, @@ -214,7 +214,7 @@ def CreateDIBSection(self, emu, argv, ctx={}): return 0 @apihook("CreateDCA", argc=4) - def CreateDCA(self, emu, argv, ctx={}): + def CreateDCA(self, emu, argv, ctx: api.ApiContext = None): """ HDC CreateDCA( LPCSTR pwszDriver, @@ -226,7 +226,7 @@ def CreateDCA(self, emu, argv, ctx={}): return 0 @apihook("GetTextCharacterExtra", argc=1) - def GetTextCharacterExtra(self, emu, argv, ctx={}): + def GetTextCharacterExtra(self, emu, argv, ctx: api.ApiContext = None): """ int GetTextCharacterExtra( HDC hdc @@ -235,7 +235,7 @@ def GetTextCharacterExtra(self, emu, argv, ctx={}): return 0x8000000 @apihook("StretchBlt", argc=11) - def StretchBlt(self, emu, argv, ctx={}): + def StretchBlt(self, emu, argv, ctx: api.ApiContext = None): """ BOOL StretchBlt( HDC hdcDest, @@ -254,7 +254,7 @@ def StretchBlt(self, emu, argv, ctx={}): return 0 @apihook("CreateFontIndirectA", argc=1) - def CreateFontIndirectA(self, emu, argv, ctx={}): + def CreateFontIndirectA(self, emu, argv, ctx: api.ApiContext = None): """ HFONT CreateFontIndirectA( const LOGFONTA *lplf @@ -265,7 +265,7 @@ def CreateFontIndirectA(self, emu, argv, ctx={}): return 0x6000 @apihook("GetObjectA", argc=3) - def GetObjectA(self, emu, argv, ctx={}): + def GetObjectA(self, emu, argv, ctx: api.ApiContext = None): """ int GetObjectA( HANDLE h, @@ -292,7 +292,7 @@ def GetObjectA(self, emu, argv, ctx={}): return c @apihook("WidenPath", argc=1) - def WidenPath(self, emu, argv, ctx={}): + def WidenPath(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WidenPath( HDC hdc diff --git a/speakeasy/winenv/api/usermode/iphlpapi.py b/speakeasy/winenv/api/usermode/iphlpapi.py index 60233b49..797876c1 100644 --- a/speakeasy/winenv/api/usermode/iphlpapi.py +++ b/speakeasy/winenv/api/usermode/iphlpapi.py @@ -24,7 +24,7 @@ def __init__(self, emu): self.iphlpapi_types = iphlpapi_types @apihook("GetAdaptersInfo", argc=2) - def GetAdaptersInfo(self, emu, argv, ctx={}): + def GetAdaptersInfo(self, emu, argv, ctx: api.ApiContext = None): ptr_adapter_info, size_ptr = argv rv = 0 diff --git a/speakeasy/winenv/api/usermode/kernel32.py b/speakeasy/winenv/api/usermode/kernel32.py index 11429907..f8b4d179 100644 --- a/speakeasy/winenv/api/usermode/kernel32.py +++ b/speakeasy/winenv/api/usermode/kernel32.py @@ -241,14 +241,14 @@ def find_resource(self, pe, name, type_): return None @apihook("GetThreadLocale", argc=0) - def GetThreadLocale(self, emu, argv, ctx={}): + def GetThreadLocale(self, emu, argv, ctx: api.ApiContext = None): """ LCID GetThreadLocale(); """ return 0xC000 @apihook("SetThreadLocale", argc=1) - def SetThreadLocale(self, emu, argv, ctx={}): + def SetThreadLocale(self, emu, argv, ctx: api.ApiContext = None): """ LCID SetThreadLocale( LCID Locale @@ -259,7 +259,7 @@ def SetThreadLocale(self, emu, argv, ctx={}): return lcid @apihook("IsValidLocale", argc=2) - def IsValidLocale(self, emu, argv, ctx={}): + def IsValidLocale(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsValidLocale( LCID Locale, @@ -271,18 +271,19 @@ def IsValidLocale(self, emu, argv, ctx={}): return True @apihook("OutputDebugString", argc=1) - def OutputDebugString(self, emu, argv, ctx={}): + def OutputDebugString(self, emu, argv, ctx: api.ApiContext = None): """ void OutputDebugStringA( LPCSTR lpOutputString ); """ + ctx = ctx or {} (_str,) = argv cw = self.get_char_width(ctx) argv[0] = self.read_mem_string(_str, cw) @apihook("GetThreadTimes", argc=5) - def GetThreadTimes(self, emu, argv, ctx={}): + def GetThreadTimes(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetThreadTimes( HANDLE hThread, @@ -299,7 +300,7 @@ def GetThreadTimes(self, emu, argv, ctx={}): return True @apihook("GetProcessHeap", argc=0) - def GetProcessHeap(self, emu, argv, ctx={}): + def GetProcessHeap(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE GetProcessHeap(); """ @@ -311,7 +312,7 @@ def GetProcessHeap(self, emu, argv, ctx={}): return heap @apihook("GetProcessVersion", argc=1) - def GetProcessVersion(self, emu, argv, ctx={}): + def GetProcessVersion(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetProcessVersion( DWORD ProcessId @@ -327,7 +328,7 @@ def GetProcessVersion(self, emu, argv, ctx={}): return rv @apihook("DisableThreadLibraryCalls", argc=1) - def DisableThreadLibraryCalls(self, emu, argv, ctx={}): + def DisableThreadLibraryCalls(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DisableThreadLibraryCalls( HMODULE hLibModule @@ -339,7 +340,7 @@ def DisableThreadLibraryCalls(self, emu, argv, ctx={}): return True @apihook("CreateMutex", argc=3) - def CreateMutex(self, emu, argv, ctx={}): + def CreateMutex(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateMutex( LPSECURITY_ATTRIBUTES lpMutexAttributes, @@ -347,6 +348,7 @@ def CreateMutex(self, emu, argv, ctx={}): LPCSTR lpName ); """ + ctx = ctx or {} attrs, owner, name = argv @@ -369,7 +371,7 @@ def CreateMutex(self, emu, argv, ctx={}): return hnd @apihook("CreateMutexEx", argc=4) - def CreateMutexEx(self, emu, argv, ctx={}): + def CreateMutexEx(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateMutexExA( LPSECURITY_ATTRIBUTES lpMutexAttributes, @@ -378,6 +380,7 @@ def CreateMutexEx(self, emu, argv, ctx={}): DWORD dwDesiredAccess ); """ + ctx = ctx or {} attrs, name, flags, access = argv cw = self.get_char_width(ctx) @@ -399,10 +402,11 @@ def CreateMutexEx(self, emu, argv, ctx={}): return hnd @apihook("LoadLibrary", argc=1) - def LoadLibrary(self, emu, argv, ctx={}): + def LoadLibrary(self, emu, argv, ctx: api.ApiContext = None): """HMODULE LoadLibrary( LPTSTR lpLibFileName );""" + ctx = ctx or {} (lib_name,) = argv hmod = windefs.NULL @@ -417,7 +421,7 @@ def LoadLibrary(self, emu, argv, ctx={}): return hmod @apihook("CreateToolhelp32Snapshot", argc=2) - def CreateToolhelp32Snapshot(self, emu, argv, ctx={}): + def CreateToolhelp32Snapshot(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateToolhelp32Snapshot( DWORD dwFlags, @@ -495,13 +499,14 @@ def CreateToolhelp32Snapshot(self, emu, argv, ctx={}): return hnd @apihook("Process32First", argc=2) - def Process32First(self, emu, argv, ctx={}): + def Process32First(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Process32First( HANDLE hSnapshot, LPPROCESSENTRY32 lppe ); """ + ctx = ctx or {} ( hSnapshot, @@ -535,13 +540,14 @@ def Process32First(self, emu, argv, ctx={}): return rv @apihook("Process32Next", argc=2) - def Process32Next(self, emu, argv, ctx={}): + def Process32Next(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Process32Next( HANDLE hSnapshot, LPPROCESSENTRY32 lppe ); """ + ctx = ctx or {} ( hSnapshot, @@ -577,7 +583,7 @@ def Process32Next(self, emu, argv, ctx={}): return rv @apihook("Thread32First", argc=2) - def Thread32First(self, emu, argv, ctx={}): + def Thread32First(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Thread32First( HANDLE hSnapshot, @@ -609,7 +615,7 @@ def Thread32First(self, emu, argv, ctx={}): return rv @apihook("Thread32Next", argc=2) - def Thread32Next(self, emu, argv, ctx={}): + def Thread32Next(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Thread32Next( HANDLE hSnapshot, @@ -643,13 +649,14 @@ def Thread32Next(self, emu, argv, ctx={}): return rv @apihook("Module32First", argc=2) - def Module32First(self, emu, argv, ctx={}): + def Module32First(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Module32First( HANDLE hSnapshot, LPMODULEENTRY32 lpme ); """ + ctx = ctx or {} ( hSnapshot, @@ -689,13 +696,14 @@ def Module32First(self, emu, argv, ctx={}): return rv @apihook("Module32Next", argc=2) - def Module32Next(self, emu, argv, ctx={}): + def Module32Next(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Module32Next( HANDLE hSnapshot, LPMODULEENTRY32 lpme ); """ + ctx = ctx or {} ( hSnapshot, @@ -736,7 +744,7 @@ def Module32Next(self, emu, argv, ctx={}): return rv @apihook("OpenProcess", argc=3) - def OpenProcess(self, emu, argv, ctx={}): + def OpenProcess(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE OpenProcess( DWORD dwDesiredAccess, @@ -764,7 +772,7 @@ def OpenProcess(self, emu, argv, ctx={}): return hnd @apihook("OpenMutex", argc=3) - def OpenMutex(self, emu, argv, ctx={}): + def OpenMutex(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE OpenMutex( DWORD dwDesiredAccess, @@ -772,6 +780,7 @@ def OpenMutex(self, emu, argv, ctx={}): LPCWSTR lpName ); """ + ctx = ctx or {} access, inherit, name = argv @@ -791,7 +800,7 @@ def OpenMutex(self, emu, argv, ctx={}): return hnd @apihook("TerminateProcess", argc=2) - def TerminateProcess(self, emu, argv, ctx={}): + def TerminateProcess(self, emu, argv, ctx: api.ApiContext = None): """ BOOL TerminateProcess( HANDLE hProcess, @@ -810,7 +819,7 @@ def TerminateProcess(self, emu, argv, ctx={}): rv = True @apihook("FreeLibraryAndExitThread", argc=2) - def FreeLibraryAndExitThread(self, emu, argv, ctx={}): + def FreeLibraryAndExitThread(self, emu, argv, ctx: api.ApiContext = None): """ void FreeLibraryAndExitThread( HMODULE hLibModule, @@ -821,7 +830,7 @@ def FreeLibraryAndExitThread(self, emu, argv, ctx={}): return @apihook("ExitThread", argc=1) - def ExitThread(self, emu, argv, ctx={}): + def ExitThread(self, emu, argv, ctx: api.ApiContext = None): """ void ExitThread( DWORD dwExitCode @@ -831,7 +840,7 @@ def ExitThread(self, emu, argv, ctx={}): return @apihook("WinExec", argc=2) - def WinExec(self, emu, argv, ctx={}): + def WinExec(self, emu, argv, ctx: api.ApiContext = None): """ UINT WinExec( LPCSTR lpCmdLine, @@ -853,12 +862,13 @@ def WinExec(self, emu, argv, ctx={}): return rv @apihook("LoadLibraryEx", argc=3) - def LoadLibraryEx(self, emu, argv, ctx={}): + def LoadLibraryEx(self, emu, argv, ctx: api.ApiContext = None): """HMODULE LoadLibraryExA( LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags );""" + ctx = ctx or {} lib_name, _, dwFlags = argv @@ -896,7 +906,7 @@ def LoadLibraryEx(self, emu, argv, ctx={}): return hmod @apihook("CreateProcessInternal", argc=12) - def CreateProcessInternal(self, emu, argv, ctx={}): + def CreateProcessInternal(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CreateProcessInternal( PVOID Reserved1, @@ -913,6 +923,7 @@ def CreateProcessInternal(self, emu, argv, ctx={}): PVOID Reserved2 ); """ + ctx = ctx or {} # Args are the same as CreateProcess except for argv[0] and argv[-1] _argv = argv[1:-1] rv = self.CreateProcess(emu, _argv, ctx) @@ -920,7 +931,7 @@ def CreateProcessInternal(self, emu, argv, ctx={}): return rv @apihook("CreateProcess", argc=10) - def CreateProcess(self, emu, argv, ctx={}): + def CreateProcess(self, emu, argv, ctx: api.ApiContext = None): """BOOL CreateProcess( LPTSTR lpApplicationName, LPTSTR lpCommandLine, @@ -933,6 +944,7 @@ def CreateProcess(self, emu, argv, ctx={}): LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation );""" + ctx = ctx or {} app, cmd, pa, ta, inherit, flags, env, cd, si, ppi = argv cw = self.get_char_width(ctx) @@ -974,7 +986,7 @@ def CreateProcess(self, emu, argv, ctx={}): return rv @apihook("VirtualAlloc", argc=4) - def VirtualAlloc(self, emu, argv, ctx={}): + def VirtualAlloc(self, emu, argv, ctx: api.ApiContext = None): """LPVOID WINAPI VirtualAlloc( _In_opt_ LPVOID lpAddress, _In_ SIZE_T dwSize, @@ -1033,7 +1045,7 @@ def VirtualAlloc(self, emu, argv, ctx={}): return buf @apihook("VirtualAllocEx", argc=5) - def VirtualAllocEx(self, emu, argv, ctx={}): + def VirtualAllocEx(self, emu, argv, ctx: api.ApiContext = None): """ LPVOID VirtualAllocEx( HANDLE hProcess, @@ -1095,7 +1107,7 @@ def VirtualAllocEx(self, emu, argv, ctx={}): return buf @apihook("WriteProcessMemory", argc=5) - def WriteProcessMemory(self, emu, argv, ctx={}): + def WriteProcessMemory(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WriteProcessMemory( HANDLE hProcess, @@ -1133,7 +1145,7 @@ def WriteProcessMemory(self, emu, argv, ctx={}): return rv @apihook("ReadProcessMemory", argc=5) - def ReadProcessMemory(self, emu, argv, ctx={}): + def ReadProcessMemory(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ReadProcessMemory( HANDLE hProcess, @@ -1175,7 +1187,7 @@ def ReadProcessMemory(self, emu, argv, ctx={}): return rv @apihook("CreateRemoteThread", argc=7) - def CreateRemoteThread(self, emu, argv, ctx={}): + def CreateRemoteThread(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateRemoteThread( HANDLE hProcess, @@ -1223,7 +1235,7 @@ def CreateRemoteThread(self, emu, argv, ctx={}): return handle @apihook("CreateThread", argc=6) - def CreateThread(self, emu, argv, ctx={}): + def CreateThread(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateThread( LPSECURITY_ATTRIBUTES lpThreadAttributes, @@ -1261,7 +1273,7 @@ def CreateThread(self, emu, argv, ctx={}): return handle @apihook("ResumeThread", argc=1) - def ResumeThread(self, emu, argv, ctx={}): + def ResumeThread(self, emu, argv, ctx: api.ApiContext = None): """ DWORD ResumeThread( HANDLE hThread @@ -1300,7 +1312,7 @@ def ResumeThread(self, emu, argv, ctx={}): return rv @apihook("SuspendThread", argc=1) - def SuspendThread(self, emu, argv, ctx={}): + def SuspendThread(self, emu, argv, ctx: api.ApiContext = None): """ DWORD SuspendThread( HANDLE hThread @@ -1317,7 +1329,7 @@ def SuspendThread(self, emu, argv, ctx={}): return rv @apihook("TerminateThread", argc=2) - def TerminateThread(self, emu, argv, ctx={}): + def TerminateThread(self, emu, argv, ctx: api.ApiContext = None): """ BOOL TerminateThread( [in, out] HANDLE hThread, @@ -1336,7 +1348,7 @@ def TerminateThread(self, emu, argv, ctx={}): return rv @apihook("GetThreadId", argc=1) - def GetThreadId(self, emu, argv, ctx={}): + def GetThreadId(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetThreadId( HANDLE Thread @@ -1355,7 +1367,7 @@ def GetThreadId(self, emu, argv, ctx={}): return obj.id @apihook("VirtualQuery", argc=3) - def VirtualQuery(self, emu, argv, ctx={}): + def VirtualQuery(self, emu, argv, ctx: api.ApiContext = None): """ SIZE_T VirtualQuery( LPCVOID lpAddress, @@ -1391,7 +1403,7 @@ def VirtualQuery(self, emu, argv, ctx={}): return mbi.sizeof() @apihook("VirtualProtect", argc=4) - def VirtualProtect(self, emu, argv, ctx={}): + def VirtualProtect(self, emu, argv, ctx: api.ApiContext = None): """BOOL WINAPI VirtualProtect( _In_ LPVOID lpAddress, _In_ SIZE_T dwSize, @@ -1436,7 +1448,7 @@ def VirtualProtect(self, emu, argv, ctx={}): return rv @apihook("VirtualProtectEx", argc=5) - def VirtualProtectEx(self, emu, argv, ctx={}): + def VirtualProtectEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL VirtualProtectEx( HANDLE hProcess, @@ -1446,6 +1458,7 @@ def VirtualProtectEx(self, emu, argv, ctx={}): PDWORD lpflOldProtect ); """ + ctx = ctx or {} hProcess, lpAddress, dwSize, flNewProtect, lpflOldProtect = argv proc_obj = self.get_object_from_handle(hProcess) @@ -1464,7 +1477,7 @@ def VirtualProtectEx(self, emu, argv, ctx={}): return rv @apihook("VirtualFree", argc=3) - def VirtualFree(self, emu, argv, ctx={}): + def VirtualFree(self, emu, argv, ctx: api.ApiContext = None): """ BOOL VirtualFree( LPVOID lpAddress, @@ -1487,7 +1500,7 @@ def VirtualFree(self, emu, argv, ctx={}): return rv @apihook("GetCurrentProcess", argc=0) - def GetCurrentProcess(self, emu, argv, ctx={}): + def GetCurrentProcess(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE GetCurrentProcess(); """ @@ -1497,7 +1510,7 @@ def GetCurrentProcess(self, emu, argv, ctx={}): return rv @apihook("GetVersion", argc=0) - def GetVersion(self, emu, argv, ctx={}): + def GetVersion(self, emu, argv, ctx: api.ApiContext = None): """NOT_BUILD_WINDOWS_DEPRECATE DWORD GetVersion();""" ver = self.emu.config.os_ver @@ -1510,7 +1523,7 @@ def GetVersion(self, emu, argv, ctx={}): return rv @apihook("GetLastError", argc=0) - def GetLastError(self, emu, argv, ctx={}): + def GetLastError(self, emu, argv, ctx: api.ApiContext = None): """DWORD WINAPI GetLastError(void);""" rv = emu.get_last_error() @@ -1521,7 +1534,7 @@ def GetLastError(self, emu, argv, ctx={}): return rv @apihook("SetLastError", argc=1) - def SetLastError(self, emu, argv, ctx={}): + def SetLastError(self, emu, argv, ctx: api.ApiContext = None): """ void SetLastError( DWORD dwErrCode @@ -1534,7 +1547,7 @@ def SetLastError(self, emu, argv, ctx={}): return None @apihook("SetHandleInformation", argc=3) - def SetHandleInformation(self, emu, argv, ctx={}): + def SetHandleInformation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetHandleInformation( HANDLE hObject, @@ -1549,7 +1562,7 @@ def SetHandleInformation(self, emu, argv, ctx={}): return rv @apihook("GetHandleInformation", argc=2) - def GetHandleInformation(self, emu, argv, ctx={}): + def GetHandleInformation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetHandleInformation( HANDLE hObject, @@ -1563,7 +1576,7 @@ def GetHandleInformation(self, emu, argv, ctx={}): return rv @apihook("ExitProcess", argc=1) - def ExitProcess(self, emu, argv, ctx={}): + def ExitProcess(self, emu, argv, ctx: api.ApiContext = None): """void ExitProcess( UINT uExitCode );""" @@ -1572,7 +1585,7 @@ def ExitProcess(self, emu, argv, ctx={}): return 0 @apihook("SystemTimeToTzSpecificLocalTime", argc=3) - def SystemTimeToTzSpecificLocalTime(self, emu, argv, ctx={}): + def SystemTimeToTzSpecificLocalTime(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SystemTimeToTzSpecificLocalTime( const TIME_ZONE_INFORMATION *lpTimeZoneInformation, @@ -1583,7 +1596,7 @@ def SystemTimeToTzSpecificLocalTime(self, emu, argv, ctx={}): return True @apihook("FileTimeToSystemTime", argc=2) - def FileTimeToSystemTime(self, emu, argv, ctx={}): + def FileTimeToSystemTime(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FileTimeToSystemTime( const FILETIME *lpFileTime, @@ -1617,7 +1630,7 @@ def FileTimeToSystemTime(self, emu, argv, ctx={}): return True @apihook("GetSystemTimeAsFileTime", argc=1) - def GetSystemTimeAsFileTime(self, emu, argv, ctx={}): + def GetSystemTimeAsFileTime(self, emu, argv, ctx: api.ApiContext = None): """void GetSystemTimeAsFileTime( LPFILETIME lpSystemTimeAsFileTime );""" @@ -1634,13 +1647,14 @@ def GetSystemTimeAsFileTime(self, emu, argv, ctx={}): return @apihook("SystemTimeToFileTime", argc=2) - def SystemTimeToFileTime(self, emu, argv, ctx={}): + def SystemTimeToFileTime(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SystemTimeToFileTime( const SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime ); """ + ctx = ctx or {} lpSystemTime, lpFileTime = argv self.GetSystemTimeAsFileTime(emu, argv[1:], ctx) @@ -1648,7 +1662,7 @@ def SystemTimeToFileTime(self, emu, argv, ctx={}): return True @apihook("SetThreadErrorMode", argc=2) - def SetThreadErrorMode(self, emu, argv, ctx={}): + def SetThreadErrorMode(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetThreadErrorMode( DWORD dwNewMode, @@ -1661,7 +1675,7 @@ def SetThreadErrorMode(self, emu, argv, ctx={}): return True @apihook("SetDefaultDllDirectories", argc=1) - def SetDefaultDllDirectories(self, emu, argv, ctx={}): + def SetDefaultDllDirectories(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetDefaultDllDirectories( DWORD DirectoryFlags @@ -1671,12 +1685,13 @@ def SetDefaultDllDirectories(self, emu, argv, ctx={}): return True @apihook("SetConsoleTitle", argc=1) - def SetConsoleTitle(self, emu, argv, ctx={}): + def SetConsoleTitle(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WINAPI SetConsoleTitle( _In_ LPCTSTR lpConsoleTitle ); """ + ctx = ctx or {} (lpConsoleTitle,) = argv if lpConsoleTitle: @@ -1686,7 +1701,7 @@ def SetConsoleTitle(self, emu, argv, ctx={}): return True @apihook("GetLocalTime", argc=1) - def GetLocalTime(self, emu, argv, ctx={}): + def GetLocalTime(self, emu, argv, ctx: api.ApiContext = None): """ void GetLocalTime( LPSYSTEMTIME lpSystemTime @@ -1695,7 +1710,7 @@ def GetLocalTime(self, emu, argv, ctx={}): return self.GetSystemTime(emu, argv) @apihook("GetSystemTime", argc=1) - def GetSystemTime(self, emu, argv, ctx={}): + def GetSystemTime(self, emu, argv, ctx: api.ApiContext = None): """ void GetSystemTime( LPSYSTEMTIME lpSystemTime @@ -1718,7 +1733,7 @@ def GetSystemTime(self, emu, argv, ctx={}): return @apihook("GetTimeZoneInformation", argc=1) - def GetTimeZoneInformation(self, emu, argv, ctx={}): + def GetTimeZoneInformation(self, emu, argv, ctx: api.ApiContext = None): """DWORD GetTimeZoneInformation( LPTIME_ZONE_INFORMATION lpTimeZoneInformation );""" @@ -1730,7 +1745,7 @@ def GetTimeZoneInformation(self, emu, argv, ctx={}): return 0 @apihook("GetCurrentThreadId", argc=0) - def GetCurrentThreadId(self, emu, argv, ctx={}): + def GetCurrentThreadId(self, emu, argv, ctx: api.ApiContext = None): """DWORD GetCurrentThreadId();""" thread = emu.get_current_thread() @@ -1739,7 +1754,7 @@ def GetCurrentThreadId(self, emu, argv, ctx={}): return rv @apihook("GetCurrentProcessId", argc=0) - def GetCurrentProcessId(self, emu, argv, ctx={}): + def GetCurrentProcessId(self, emu, argv, ctx: api.ApiContext = None): """DWORD GetCurrentProcessId();""" proc = emu.get_current_process() @@ -1748,7 +1763,7 @@ def GetCurrentProcessId(self, emu, argv, ctx={}): return rv @apihook("IsProcessorFeaturePresent", argc=1, conv=e_arch.CALL_CONV_STDCALL) - def IsProcessorFeaturePresent(self, emu, argv, ctx={}): + def IsProcessorFeaturePresent(self, emu, argv, ctx: api.ApiContext = None): """BOOL IsProcessorFeaturePresent( DWORD ProcessorFeature );""" @@ -1818,11 +1833,12 @@ def IsProcessorFeaturePresent(self, emu, argv, ctx={}): return rv @apihook("lstrcmpi", argc=2) - def lstrcmpi(self, emu, argv, ctx={}): + def lstrcmpi(self, emu, argv, ctx: api.ApiContext = None): """int lstrcmpiA( LPCSTR lpString1, LPCSTR lpString2 );""" + ctx = ctx or {} cw = self.get_char_width(ctx) string1, string2 = argv @@ -1840,11 +1856,12 @@ def lstrcmpi(self, emu, argv, ctx={}): return rv @apihook("lstrcmp", argc=2) - def lstrcmp(self, emu, argv, ctx={}): + def lstrcmp(self, emu, argv, ctx: api.ApiContext = None): """int lstrcmpiA( LPCSTR lpString1, LPCSTR lpString2 );""" + ctx = ctx or {} cw = self.get_char_width(ctx) string1, string2 = argv @@ -1862,7 +1879,7 @@ def lstrcmp(self, emu, argv, ctx={}): return rv @apihook("QueryPerformanceCounter", argc=1) - def QueryPerformanceCounter(self, emu, argv, ctx={}): + def QueryPerformanceCounter(self, emu, argv, ctx: api.ApiContext = None): """BOOL WINAPI QueryPerformanceCounter( _Out_ LARGE_INTEGER *lpPerformanceCount );""" @@ -1874,12 +1891,13 @@ def QueryPerformanceCounter(self, emu, argv, ctx={}): return rv @apihook("lstrlen", argc=1) - def lstrlen(self, emu, argv, ctx={}): + def lstrlen(self, emu, argv, ctx: api.ApiContext = None): """ int lstrlen( LPCSTR lpString ); """ + ctx = ctx or {} (src,) = argv try: cw = self.get_char_width(ctx) @@ -1892,7 +1910,7 @@ def lstrlen(self, emu, argv, ctx={}): return len(s) @apihook("GetModuleHandleEx", argc=3) - def GetModuleHandleEx(self, emu, argv, ctx={}): + def GetModuleHandleEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetModuleHandleExA( DWORD dwFlags, @@ -1900,6 +1918,7 @@ def GetModuleHandleEx(self, emu, argv, ctx={}): HMODULE *phModule ); """ + ctx = ctx or {} dwFlags, lpModuleName, phModule = argv hmod = self.GetModuleHandle(emu, [lpModuleName], ctx) @@ -1909,10 +1928,11 @@ def GetModuleHandleEx(self, emu, argv, ctx={}): return hmod @apihook("GetModuleHandle", argc=1) - def GetModuleHandle(self, emu, argv, ctx={}): + def GetModuleHandle(self, emu, argv, ctx: api.ApiContext = None): """HMODULE GetModuleHandle( LPCSTR lpModuleName );""" + ctx = ctx or {} (mod_name,) = argv @@ -1938,7 +1958,7 @@ def GetModuleHandle(self, emu, argv, ctx={}): return rv @apihook("GetProcAddress", argc=2) - def GetProcAddress(self, emu, argv, ctx={}): + def GetProcAddress(self, emu, argv, ctx: api.ApiContext = None): """FARPROC GetProcAddress( HMODULE hModule, LPCSTR lpProcName @@ -1973,14 +1993,14 @@ def GetProcAddress(self, emu, argv, ctx={}): return rv @apihook("AllocConsole", argc=0) - def AllocConsole(self, emu, argv, ctx={}): + def AllocConsole(self, emu, argv, ctx: api.ApiContext = None): """BOOL WINAPI AllocConsole(void);""" # On success, return != 0 return 1 @apihook("GetConsoleWindow", argc=0) - def GetConsoleWindow(self, emu, argv, ctx={}): + def GetConsoleWindow(self, emu, argv, ctx: api.ApiContext = None): """HWND WINAPI GetConsoleWindow(void);""" hwnd = 0 @@ -1993,21 +2013,21 @@ def GetConsoleWindow(self, emu, argv, ctx={}): return hwnd @apihook("Sleep", argc=1) - def Sleep(self, emu, argv, ctx={}): + def Sleep(self, emu, argv, ctx: api.ApiContext = None): """void Sleep(DWORD dwMilliseconds);""" (millisec,) = argv return @apihook("SleepEx", argc=2) - def SleepEx(self, emu, argv, ctx={}): + def SleepEx(self, emu, argv, ctx: api.ApiContext = None): """DWORD SleepEx(DWORD dwMilliseconds, BOOL bAlertable);""" millisec, bAlertable = argv return @apihook("GlobalAlloc", argc=2) - def GlobalAlloc(self, emu, argv, ctx={}): + def GlobalAlloc(self, emu, argv, ctx: api.ApiContext = None): """ DECLSPEC_ALLOCATOR HGLOBAL GlobalAlloc( UINT uFlags, @@ -2022,7 +2042,7 @@ def GlobalAlloc(self, emu, argv, ctx={}): return chunk @apihook("GlobalSize", argc=1) - def GlobalSize(self, emu, argv, ctx={}): + def GlobalSize(self, emu, argv, ctx: api.ApiContext = None): """ SIZE_T GlobalSize( [in] HGLOBAL hMem @@ -2043,7 +2063,7 @@ def GlobalSize(self, emu, argv, ctx={}): return size @apihook("GlobalFlags", argc=1) - def GlobalFlags(self, emu, argv, ctx={}): + def GlobalFlags(self, emu, argv, ctx: api.ApiContext = None): """ UINT GlobalFlags( [in] HGLOBAL hMem @@ -2063,7 +2083,7 @@ def GlobalFlags(self, emu, argv, ctx={}): return flags @apihook("LocalAlloc", argc=2) - def LocalAlloc(self, emu, argv, ctx={}): + def LocalAlloc(self, emu, argv, ctx: api.ApiContext = None): """ DECLSPEC_ALLOCATOR HLOCAL LocalAlloc( UINT uFlags, @@ -2078,7 +2098,7 @@ def LocalAlloc(self, emu, argv, ctx={}): return chunk @apihook("HeapAlloc", argc=3) - def HeapAlloc(self, emu, argv, ctx={}): + def HeapAlloc(self, emu, argv, ctx: api.ApiContext = None): """ DECLSPEC_ALLOCATOR LPVOID HeapAlloc( HANDLE hHeap, @@ -2096,7 +2116,7 @@ def HeapAlloc(self, emu, argv, ctx={}): return chunk @apihook("HeapSize", argc=3) - def HeapSize(self, emu, argv, ctx={}): + def HeapSize(self, emu, argv, ctx: api.ApiContext = None): """ SIZE_T HeapSize( HANDLE hHeap, @@ -2119,7 +2139,7 @@ def HeapSize(self, emu, argv, ctx={}): return size @apihook("GetTickCount", argc=0) - def GetTickCount(self, emu, argv, ctx={}): + def GetTickCount(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetTickCount(); """ @@ -2129,7 +2149,7 @@ def GetTickCount(self, emu, argv, ctx={}): return self.tick_counter @apihook("GetTickCount64", argc=0) - def GetTickCount64(self, emu, argv, ctx={}): + def GetTickCount64(self, emu, argv, ctx: api.ApiContext = None): """ ULONGLONG GetTickCount64(); """ @@ -2139,13 +2159,14 @@ def GetTickCount64(self, emu, argv, ctx={}): return self.tick_counter @apihook("lstrcat", argc=2) - def lstrcat(self, emu, argv, ctx={}): + def lstrcat(self, emu, argv, ctx: api.ApiContext = None): """ LPSTR lstrcat( LPSTR lpString1, LPCSTR lpString2 ); """ + ctx = ctx or {} lpString1, lpString2 = argv cw = self.get_char_width(ctx) @@ -2165,7 +2186,7 @@ def lstrcat(self, emu, argv, ctx={}): return lpString1 @apihook("lstrcpyn", argc=3) - def lstrcpyn(self, emu, argv, ctx={}): + def lstrcpyn(self, emu, argv, ctx: api.ApiContext = None): """ LPSTR lstrcpynA( LPSTR lpString1, @@ -2173,6 +2194,7 @@ def lstrcpyn(self, emu, argv, ctx={}): int iMaxLength ); """ + ctx = ctx or {} dest, src, iMaxLength = argv cw = self.get_char_width(ctx) @@ -2186,13 +2208,14 @@ def lstrcpyn(self, emu, argv, ctx={}): return dest @apihook("lstrcpy", argc=2) - def lstrcpy(self, emu, argv, ctx={}): + def lstrcpy(self, emu, argv, ctx: api.ApiContext = None): """ LPSTR lstrcpyA( LPSTR lpString1, LPCSTR lpString2 ); """ + ctx = ctx or {} dest, src = argv cw = self.get_char_width(ctx) @@ -2205,7 +2228,7 @@ def lstrcpy(self, emu, argv, ctx={}): return dest @apihook("IsBadReadPtr", argc=2) - def IsBadReadPtr(self, emu, argv, ctx={}): + def IsBadReadPtr(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsBadReadPtr( const VOID *lp, @@ -2227,7 +2250,7 @@ def IsBadReadPtr(self, emu, argv, ctx={}): return rv @apihook("HeapReAlloc", argc=4) - def HeapReAlloc(self, emu, argv, ctx={}): + def HeapReAlloc(self, emu, argv, ctx: api.ApiContext = None): """ DECLSPEC_ALLOCATOR LPVOID HeapReAlloc( HANDLE hHeap, @@ -2253,7 +2276,7 @@ def HeapReAlloc(self, emu, argv, ctx={}): return new_buf @apihook("LocalReAlloc", argc=3) - def LocalReAlloc(self, emu, argv, ctx={}): + def LocalReAlloc(self, emu, argv, ctx: api.ApiContext = None): """ DECLSPEC_ALLOCATOR HLOCAL LocalReAlloc( _Frees_ptr_opt_ HLOCAL hMem, @@ -2278,7 +2301,7 @@ def LocalReAlloc(self, emu, argv, ctx={}): return new_buf @apihook("HeapCreate", argc=3) - def HeapCreate(self, emu, argv, ctx={}): + def HeapCreate(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE HeapCreate( DWORD flOptions, @@ -2294,7 +2317,7 @@ def HeapCreate(self, emu, argv, ctx={}): return heap @apihook("GetCurrentThread", argc=0) - def GetCurrentThread(self, emu, argv, ctx={}): + def GetCurrentThread(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE GetCurrentThread(); """ @@ -2303,7 +2326,7 @@ def GetCurrentThread(self, emu, argv, ctx={}): return emu.get_object_handle(obj) @apihook("TlsAlloc", argc=0) - def TlsAlloc(self, emu, argv, ctx={}): + def TlsAlloc(self, emu, argv, ctx: api.ApiContext = None): """ DWORD TlsAlloc(); """ @@ -2318,7 +2341,7 @@ def TlsAlloc(self, emu, argv, ctx={}): return idx @apihook("TlsSetValue", argc=2) - def TlsSetValue(self, emu, argv, ctx={}): + def TlsSetValue(self, emu, argv, ctx: api.ApiContext = None): """ BOOL TlsSetValue( DWORD dwTlsIndex, @@ -2343,7 +2366,7 @@ def TlsSetValue(self, emu, argv, ctx={}): return rv @apihook("TlsGetValue", argc=1) - def TlsGetValue(self, emu, argv, ctx={}): + def TlsGetValue(self, emu, argv, ctx: api.ApiContext = None): """ LPVOID TlsGetValue( DWORD dwTlsIndex @@ -2365,7 +2388,7 @@ def TlsGetValue(self, emu, argv, ctx={}): return rv @apihook("FlsAlloc", argc=1) - def FlsAlloc(self, emu, argv, ctx={}): + def FlsAlloc(self, emu, argv, ctx: api.ApiContext = None): """ DWORD FlsAlloc( PFLS_CALLBACK_FUNCTION lpCallback @@ -2382,7 +2405,7 @@ def FlsAlloc(self, emu, argv, ctx={}): return idx @apihook("FlsSetValue", argc=2) - def FlsSetValue(self, emu, argv, ctx={}): + def FlsSetValue(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FlsSetValue( DWORD dwFlsIndex, @@ -2410,7 +2433,7 @@ def FlsSetValue(self, emu, argv, ctx={}): return rv @apihook("FlsGetValue", argc=1) - def FlsGetValue(self, emu, argv, ctx={}): + def FlsGetValue(self, emu, argv, ctx: api.ApiContext = None): """ PVOID FlsGetValue( DWORD dwFlsIndex @@ -2431,7 +2454,7 @@ def FlsGetValue(self, emu, argv, ctx={}): return rv @apihook("EncodePointer", argc=1) - def EncodePointer(self, emu, argv, ctx={}): + def EncodePointer(self, emu, argv, ctx: api.ApiContext = None): """ PVOID EncodePointer( _In_ PVOID Ptr @@ -2445,7 +2468,7 @@ def EncodePointer(self, emu, argv, ctx={}): return rv @apihook("DecodePointer", argc=1) - def DecodePointer(self, emu, argv, ctx={}): + def DecodePointer(self, emu, argv, ctx: api.ApiContext = None): """ PVOID DecodePointer( PVOID Ptr @@ -2459,7 +2482,7 @@ def DecodePointer(self, emu, argv, ctx={}): return rv @apihook("InitializeCriticalSectionAndSpinCount", argc=2) - def InitializeCriticalSectionAndSpinCount(self, emu, argv, ctx={}): + def InitializeCriticalSectionAndSpinCount(self, emu, argv, ctx: api.ApiContext = None): """ BOOL InitializeCriticalSectionAndSpinCount( LPCRITICAL_SECTION lpCriticalSection, @@ -2473,7 +2496,7 @@ def InitializeCriticalSectionAndSpinCount(self, emu, argv, ctx={}): return rv @apihook("EnterCriticalSection", argc=1) - def EnterCriticalSection(self, emu, argv, ctx={}): + def EnterCriticalSection(self, emu, argv, ctx: api.ApiContext = None): """ void EnterCriticalSection( LPCRITICAL_SECTION lpCriticalSection @@ -2483,7 +2506,7 @@ def EnterCriticalSection(self, emu, argv, ctx={}): return @apihook("LeaveCriticalSection", argc=1) - def LeaveCriticalSection(self, emu, argv, ctx={}): + def LeaveCriticalSection(self, emu, argv, ctx: api.ApiContext = None): """ void LeaveCriticalSection( LPCRITICAL_SECTION lpCriticalSection @@ -2493,7 +2516,7 @@ def LeaveCriticalSection(self, emu, argv, ctx={}): return @apihook("InterlockedIncrement", argc=1) - def InterlockedIncrement(self, emu, argv, ctx={}): + def InterlockedIncrement(self, emu, argv, ctx: api.ApiContext = None): """ LONG InterlockedIncrement( LONG volatile *Addend @@ -2511,7 +2534,7 @@ def InterlockedIncrement(self, emu, argv, ctx={}): return ival @apihook("InterlockedDecrement", argc=1) - def InterlockedDecrement(self, emu, argv, ctx={}): + def InterlockedDecrement(self, emu, argv, ctx: api.ApiContext = None): """ LONG InterlockedDecrement( LONG volatile *Addend @@ -2529,10 +2552,11 @@ def InterlockedDecrement(self, emu, argv, ctx={}): return ival @apihook("GetCommandLine", argc=0) - def GetCommandLine(self, emu, argv, ctx={}): + def GetCommandLine(self, emu, argv, ctx: api.ApiContext = None): """ LPTSTR GetCommandLine(); """ + ctx = ctx or {} fn = ctx["func_name"] cw = self.get_char_width(ctx) @@ -2555,7 +2579,7 @@ def GetCommandLine(self, emu, argv, ctx={}): return cmd_ptr @apihook("ExpandEnvironmentStrings", argc=3) - def ExpandEnvironmentStrings(self, emu, argv, ctx={}): + def ExpandEnvironmentStrings(self, emu, argv, ctx: api.ApiContext = None): """ DWORD ExpandEnvironmentStringsA( LPCSTR lpSrc, @@ -2563,6 +2587,7 @@ def ExpandEnvironmentStrings(self, emu, argv, ctx={}): DWORD nSize ); """ + ctx = ctx or {} lpSrc, lpDst, nSize = argv rv = 0 @@ -2586,10 +2611,11 @@ def ExpandEnvironmentStrings(self, emu, argv, ctx={}): return rv @apihook("GetEnvironmentStrings", argc=0) - def GetEnvironmentStrings(self, emu, argv, ctx={}): + def GetEnvironmentStrings(self, emu, argv, ctx: api.ApiContext = None): """ LPCH GetEnvironmentStrings(); """ + ctx = ctx or {} out = "" fn = ctx["func_name"] @@ -2611,7 +2637,7 @@ def GetEnvironmentStrings(self, emu, argv, ctx={}): return env_ptr @apihook("FreeEnvironmentStrings", argc=1) - def FreeEnvironmentStrings(self, emu, argv, ctx={}): + def FreeEnvironmentStrings(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FreeEnvironmentStrings( LPCH penv @@ -2625,7 +2651,7 @@ def FreeEnvironmentStrings(self, emu, argv, ctx={}): return True @apihook("GetFullPathName", argc=4) - def GetFullPathName(self, emu, argv, ctx={}): + def GetFullPathName(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetFullPathNameA( LPCSTR lpFileName, @@ -2634,6 +2660,7 @@ def GetFullPathName(self, emu, argv, ctx={}): LPSTR *lpFilePart ); """ + ctx = ctx or {} lpFileName, nBufferLength, lpBuffer, lpFilePart = argv cw = self.get_char_width(ctx) @@ -2656,12 +2683,13 @@ def GetFullPathName(self, emu, argv, ctx={}): return rv @apihook("GetStartupInfo", argc=1) - def GetStartupInfo(self, emu, argv, ctx={}): + def GetStartupInfo(self, emu, argv, ctx: api.ApiContext = None): """ void GetStartupInfo( LPSTARTUPINFO lpStartupInfo ); """ + ctx = ctx or {} (lpStartupInfo,) = argv @@ -2727,7 +2755,7 @@ def GetStartupInfo(self, emu, argv, ctx={}): return None @apihook("GetStdHandle", argc=1) - def GetStdHandle(self, emu, argv, ctx={}): + def GetStdHandle(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE WINAPI GetStdHandle( _In_ DWORD nStdHandle @@ -2742,7 +2770,7 @@ def GetStdHandle(self, emu, argv, ctx={}): return hnd @apihook("GetFileType", argc=1) - def GetFileType(self, emu, argv, ctx={}): + def GetFileType(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetFileType( HANDLE hFile @@ -2755,7 +2783,7 @@ def GetFileType(self, emu, argv, ctx={}): return FILE_TYPE_DISK @apihook("SetHandleCount", argc=1) - def SetHandleCount(self, emu, argv, ctx={}): + def SetHandleCount(self, emu, argv, ctx: api.ApiContext = None): """ UINT SetHandleCount( UINT uNumber @@ -2768,7 +2796,7 @@ def SetHandleCount(self, emu, argv, ctx={}): return uNumber @apihook("GetACP", argc=0) - def GetACP(self, emu, argv, ctx={}): + def GetACP(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetACP(); """ @@ -2778,7 +2806,7 @@ def GetACP(self, emu, argv, ctx={}): return windows_1252 @apihook("IsValidCodePage", argc=1) - def IsValidCodePage(self, emu, argv, ctx={}): + def IsValidCodePage(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsValidCodePage( UINT CodePage @@ -2790,7 +2818,7 @@ def IsValidCodePage(self, emu, argv, ctx={}): return True @apihook("GetCPInfo", argc=2) - def GetCPInfo(self, emu, argv, ctx={}): + def GetCPInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetCPInfo( UINT CodePage, @@ -2807,7 +2835,7 @@ def GetCPInfo(self, emu, argv, ctx={}): return True @apihook("WideCharToMultiByte", argc=8) - def WideCharToMultiByte(self, emu, argv, ctx={}): + def WideCharToMultiByte(self, emu, argv, ctx: api.ApiContext = None): """ int WideCharToMultiByte( UINT CodePage, @@ -2870,7 +2898,7 @@ def WideCharToMultiByte(self, emu, argv, ctx={}): return rv @apihook("MultiByteToWideChar", argc=6) - def MultiByteToWideChar(self, emu, argv, ctx={}): + def MultiByteToWideChar(self, emu, argv, ctx: api.ApiContext = None): """ int MultiByteToWideChar( UINT CodePage, @@ -2925,7 +2953,7 @@ def MultiByteToWideChar(self, emu, argv, ctx={}): return rv @apihook("GetStringTypeA", argc=5) - def GetStringTypeA(self, emu, argv, ctx={}): + def GetStringTypeA(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetStringTypeA( LCID Locale, @@ -2935,11 +2963,12 @@ def GetStringTypeA(self, emu, argv, ctx={}): LPWORD lpCharType ); """ + ctx = ctx or {} args = argv[1:] return self.GetStringTypeW(emu, args, ctx) @apihook("GetStringTypeW", argc=4) - def GetStringTypeW(self, emu, argv, ctx={}): + def GetStringTypeW(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetStringTypeW( DWORD dwInfoType, @@ -2948,6 +2977,7 @@ def GetStringTypeW(self, emu, argv, ctx={}): LPWORD lpCharType ); """ + ctx = ctx or {} dwInfoType, lpSrcStr, cchSrc, lpCharType = argv rv = 0 @@ -3006,7 +3036,7 @@ def GetStringTypeW(self, emu, argv, ctx={}): return rv @apihook("LCMapString", argc=6) - def LCMapString(self, emu, argv, ctx={}): + def LCMapString(self, emu, argv, ctx: api.ApiContext = None): """ int LCMapString( LCID Locale, @@ -3017,6 +3047,7 @@ def LCMapString(self, emu, argv, ctx={}): int cchDest ); """ + ctx = ctx or {} (Locale, dwMapFlags, lpSrcStr, cchSrc, lpDestStr, cchDest) = argv @@ -3036,7 +3067,7 @@ def LCMapString(self, emu, argv, ctx={}): return rv @apihook("LCMapStringEx", argc=9) - def LCMapStringEx(self, emu, argv, ctx={}): + def LCMapStringEx(self, emu, argv, ctx: api.ApiContext = None): """ int LCMapStringEx( LPCWSTR lpLocaleName, @@ -3068,7 +3099,7 @@ def LCMapStringEx(self, emu, argv, ctx={}): return rv @apihook("GetModuleFileName", argc=3) - def GetModuleFileName(self, emu, argv, ctx={}): + def GetModuleFileName(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetModuleFileName( HMODULE hModule, @@ -3076,6 +3107,7 @@ def GetModuleFileName(self, emu, argv, ctx={}): DWORD nSize ); """ + ctx = ctx or {} hModule, lpFilename, nSize = argv size = 0 cw = self.get_char_width(ctx) @@ -3112,7 +3144,7 @@ def GetModuleFileName(self, emu, argv, ctx={}): return size @apihook("HeapFree", argc=3) - def HeapFree(self, emu, argv, ctx={}): + def HeapFree(self, emu, argv, ctx: api.ApiContext = None): """ BOOL HeapFree( HANDLE hHeap, @@ -3128,7 +3160,7 @@ def HeapFree(self, emu, argv, ctx={}): return rv @apihook("LocalFree", argc=1) - def LocalFree(self, emu, argv, ctx={}): + def LocalFree(self, emu, argv, ctx: api.ApiContext = None): """ HLOCAL LocalFree( _Frees_ptr_opt_ HLOCAL hMem @@ -3145,7 +3177,7 @@ def LocalFree(self, emu, argv, ctx={}): return rv @apihook("GlobalHandle", argc=1) - def GlobalHandle(self, emu, argv, ctx={}): + def GlobalHandle(self, emu, argv, ctx: api.ApiContext = None): """ HGLOBAL GlobalHandle( LPCVOID pMem @@ -3155,7 +3187,7 @@ def GlobalHandle(self, emu, argv, ctx={}): return pMem @apihook("GlobalUnlock", argc=1) - def GlobalUnlock(self, emu, argv, ctx={}): + def GlobalUnlock(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GlobalUnlock( HGLOBAL hMem @@ -3164,7 +3196,7 @@ def GlobalUnlock(self, emu, argv, ctx={}): return 0 @apihook("GlobalFree", argc=1) - def GlobalFree(self, emu, argv, ctx={}): + def GlobalFree(self, emu, argv, ctx: api.ApiContext = None): """ HGLOBAL GlobalFree( _Frees_ptr_opt_ HGLOBAL hMem @@ -3173,13 +3205,14 @@ def GlobalFree(self, emu, argv, ctx={}): return 0 @apihook("GetSystemDirectory", argc=2) - def GetSystemDirectory(self, emu, argv, ctx={}): + def GetSystemDirectory(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetSystemDirectory( LPSTR lpBuffer, UINT uSize ); """ + ctx = ctx or {} rv = 0 lpBuffer, uSize = argv @@ -3207,7 +3240,7 @@ def GetSystemDirectory(self, emu, argv, ctx={}): return rv @apihook("IsDBCSLeadByte", argc=1) - def IsDBCSLeadByte(self, emu, argv, ctx={}): + def IsDBCSLeadByte(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsDBCSLeadByte( BYTE TestChar @@ -3216,13 +3249,14 @@ def IsDBCSLeadByte(self, emu, argv, ctx={}): return True @apihook("SetEnvironmentVariable", argc=2) - def SetEnvironmentVariable(self, emu, argv, ctx={}): + def SetEnvironmentVariable(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetEnvironmentVariable( LPCTSTR lpName, LPCTSTR lpValue ); """ + ctx = ctx or {} lpName, lpValue = argv cw = self.get_char_width(ctx) if lpName and lpValue: @@ -3234,12 +3268,13 @@ def SetEnvironmentVariable(self, emu, argv, ctx={}): return True @apihook("SetDllDirectory", argc=1) - def SetDllDirectory(self, emu, argv, ctx={}): + def SetDllDirectory(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetDllDirectory( LPCSTR lpPathName ); """ + ctx = ctx or {} (path,) = argv cw = self.get_char_width(ctx) @@ -3249,17 +3284,18 @@ def SetDllDirectory(self, emu, argv, ctx={}): return True @apihook("GetWindowsDirectory", argc=2) - def GetWindowsDirectory(self, emu, argv, ctx={}): + def GetWindowsDirectory(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetWindowsDirectory( LPSTR lpBuffer, UINT uSize ); """ + ctx = ctx or {} return self.GetSystemDirectory(emu, argv, ctx) @apihook("CreateFileMapping", argc=6) - def CreateFileMapping(self, emu, argv, ctx={}): + def CreateFileMapping(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateFileMapping( HANDLE hFile, @@ -3270,6 +3306,7 @@ def CreateFileMapping(self, emu, argv, ctx={}): LPTSTR lpName ); """ + ctx = ctx or {} hfile, map_attrs, prot, max_size_high, max_size_low, map_name = argv cw = self.get_char_width(ctx) @@ -3287,7 +3324,7 @@ def CreateFileMapping(self, emu, argv, ctx={}): return hmap @apihook("MapViewOfFile", argc=5) - def MapViewOfFile(self, emu, argv, ctx={}): + def MapViewOfFile(self, emu, argv, ctx: api.ApiContext = None): """ LPVOID MapViewOfFile( HANDLE hFileMappingObject, @@ -3362,7 +3399,7 @@ def MapViewOfFile(self, emu, argv, ctx={}): return buf @apihook("UnmapViewOfFile", argc=1) - def UnmapViewOfFile(self, emu, argv, ctx={}): + def UnmapViewOfFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL UnmapViewOfFile( LPCVOID lpBaseAddress @@ -3382,7 +3419,7 @@ def UnmapViewOfFile(self, emu, argv, ctx={}): return rv @apihook("GetSystemInfo", argc=1) - def GetSystemInfo(self, emu, argv, ctx={}): + def GetSystemInfo(self, emu, argv, ctx: api.ApiContext = None): """ void GetSystemInfo( LPSYSTEM_INFO lpSystemInfo @@ -3402,12 +3439,13 @@ def GetSystemInfo(self, emu, argv, ctx={}): return @apihook("GetFileAttributes", argc=1) - def GetFileAttributes(self, emu, argv, ctx={}): + def GetFileAttributes(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetFileAttributes( LPCSTR lpFileName ); """ + ctx = ctx or {} (fn,) = argv cw = self.get_char_width(ctx) rv = windefs.INVALID_FILE_ATTRIBUTES @@ -3418,7 +3456,7 @@ def GetFileAttributes(self, emu, argv, ctx={}): return rv @apihook("GetFileAttributesEx", argc=3) - def GetFileAttributesEx(self, emu, argv, ctx={}): + def GetFileAttributesEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetFileAttributesEx( LPCSTR lpFileName, @@ -3426,6 +3464,7 @@ def GetFileAttributesEx(self, emu, argv, ctx={}): LPVOID lpFileInformation ); """ + ctx = ctx or {} lpFileName, fInfoLevelId, lpFileInformation = argv cw = self.get_char_width(ctx) @@ -3473,7 +3512,7 @@ def GetFileAttributesEx(self, emu, argv, ctx={}): return True @apihook("GetFileTime", argc=4) - def GetFileTime(self, emu, argv, ctx={}): + def GetFileTime(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetFileTime( HANDLE hFile, @@ -3501,7 +3540,7 @@ def GetFileTime(self, emu, argv, ctx={}): return True @apihook("SetFileTime", argc=4) - def SetFileTime(self, emu, argv, ctx={}): + def SetFileTime(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetFileTime( HANDLE hFile, @@ -3514,13 +3553,14 @@ def SetFileTime(self, emu, argv, ctx={}): return True @apihook("CreateDirectory", argc=2) - def CreateDirectory(self, emu, argv, ctx={}): + def CreateDirectory(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CreateDirectory( LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ); """ + ctx = ctx or {} pn, sec = argv cw = self.get_char_width(ctx) @@ -3530,12 +3570,13 @@ def CreateDirectory(self, emu, argv, ctx={}): return True @apihook("RemoveDirectory", argc=1) - def RemoveDirectory(self, emu, argv, ctx={}): + def RemoveDirectory(self, emu, argv, ctx: api.ApiContext = None): """ BOOL RemoveDirectoryA( [in] LPCSTR lpPathName ); """ + ctx = ctx or {} (pn,) = argv cw = self.get_char_width(ctx) @@ -3546,7 +3587,7 @@ def RemoveDirectory(self, emu, argv, ctx={}): return True @apihook("CopyFile", argc=3) - def CopyFile(self, emu, argv, ctx={}): + def CopyFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CopyFile( LPCTSTR lpExistingFileName, @@ -3554,6 +3595,7 @@ def CopyFile(self, emu, argv, ctx={}): BOOL bFailIfExists ); """ + ctx = ctx or {} src, dst, fail = argv cw = self.get_char_width(ctx) @@ -3599,13 +3641,14 @@ def CopyFile(self, emu, argv, ctx={}): return True @apihook("MoveFile", argc=2) - def MoveFile(self, emu, argv, ctx={}): + def MoveFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL MoveFile( LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName ); """ + ctx = ctx or {} src, dst = argv cw = self.get_char_width(ctx) @@ -3655,7 +3698,7 @@ def MoveFile(self, emu, argv, ctx={}): return 1 @apihook("CreateFile", argc=7) - def CreateFile(self, emu, argv, ctx={}): + def CreateFile(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateFile( LPTSTR lpFileName, @@ -3667,6 +3710,7 @@ def CreateFile(self, emu, argv, ctx={}): HANDLE hTemplateFile ); """ + ctx = ctx or {} fname, access, share, sec_attr, disp, flags, template = argv hnd = windefs.INVALID_HANDLE_VALUE @@ -3734,12 +3778,13 @@ def CreateFile(self, emu, argv, ctx={}): return hnd @apihook("DeleteFile", argc=1) - def DeleteFile(self, emu, argv, ctx={}): + def DeleteFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DeleteFileW( LPCWSTR lpFileName ); """ + ctx = ctx or {} lpFileName = argv[0] cw = self.get_char_width(ctx) if not lpFileName: @@ -3758,7 +3803,7 @@ def DeleteFile(self, emu, argv, ctx={}): return 0 @apihook("ReadFile", argc=5) - def ReadFile(self, emu, argv, ctx={}): + def ReadFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ReadFile( HANDLE hFile, @@ -3806,7 +3851,7 @@ def _write_output(emu, data, pBuffer, pBytesRead): return rv @apihook("WriteFile", argc=5) - def WriteFile(self, emu, argv, ctx={}): + def WriteFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WriteFile( HANDLE hFile, @@ -3873,7 +3918,7 @@ def WriteFile(self, emu, argv, ctx={}): return rv @apihook("SetFilePointer", argc=4) - def SetFilePointer(self, emu, argv, ctx={}): + def SetFilePointer(self, emu, argv, ctx: api.ApiContext = None): """ DWORD SetFilePointer( HANDLE hFile, @@ -3895,7 +3940,7 @@ def SetFilePointer(self, emu, argv, ctx={}): return rv @apihook("SetFilePointerEx", argc=4) - def SetFilePointerEx(self, emu, argv, ctx={}): + def SetFilePointerEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetFilePointerEx( [in] HANDLE hFile, @@ -3915,7 +3960,7 @@ def SetFilePointerEx(self, emu, argv, ctx={}): return False @apihook("GetFileSize", argc=2) - def GetFileSize(self, emu, argv, ctx={}): + def GetFileSize(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetFileSize( HANDLE hFile, @@ -3943,7 +3988,7 @@ def GetFileSize(self, emu, argv, ctx={}): return low @apihook("GetFileSizeEx", argc=2) - def GetFileSizeEx(self, emu, argv, ctx={}): + def GetFileSizeEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetFileSizeEx( HANDLE hFile, @@ -3964,7 +4009,7 @@ def GetFileSizeEx(self, emu, argv, ctx={}): return 0 @apihook("CloseHandle", argc=1) - def CloseHandle(self, emu, argv, ctx={}): + def CloseHandle(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CloseHandle( HANDLE hObject @@ -3987,7 +4032,7 @@ def CloseHandle(self, emu, argv, ctx={}): return 0 @apihook("SetEndOfFile", argc=1) - def SetEndOfFile(self, emu, argv, ctx={}): + def SetEndOfFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetEndOfFile( HANDLE hFile @@ -3996,7 +4041,7 @@ def SetEndOfFile(self, emu, argv, ctx={}): return True @apihook("IsDebuggerPresent", argc=0) - def IsDebuggerPresent(self, emu, argv, ctx={}): + def IsDebuggerPresent(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsDebuggerPresent(); """ @@ -4004,7 +4049,7 @@ def IsDebuggerPresent(self, emu, argv, ctx={}): return False @apihook("GetVolumeInformation", argc=8) - def GetVolumeInformation(self, emu, argv, ctx={}): + def GetVolumeInformation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetVolumeInformation( LPCSTR lpRootPathName, @@ -4017,6 +4062,7 @@ def GetVolumeInformation(self, emu, argv, ctx={}): DWORD nFileSystemNameSize ); """ + ctx = ctx or {} root, vol_buf, vol_size, serial, comp_len, fs_flags, fs_name, fs_name_len = argv cw = self.get_char_width(ctx) @@ -4027,7 +4073,7 @@ def GetVolumeInformation(self, emu, argv, ctx={}): return True @apihook("CreateEvent", argc=4) - def CreateEvent(self, emu, argv, ctx={}): + def CreateEvent(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateEvent( LPSECURITY_ATTRIBUTES lpEventAttributes, @@ -4036,6 +4082,7 @@ def CreateEvent(self, emu, argv, ctx={}): LPCSTR lpName ); """ + ctx = ctx or {} attrs, reset, state, name = argv cw = self.get_char_width(ctx) @@ -4055,7 +4102,7 @@ def CreateEvent(self, emu, argv, ctx={}): return hnd @apihook("CreateWaitableTimer", argc=3) - def CreateWaitableTimer(self, emu, argv, ctx={}): + def CreateWaitableTimer(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateWaitableTimer( LPSECURITY_ATTRIBUTES lpTimerAttributes, @@ -4063,6 +4110,7 @@ def CreateWaitableTimer(self, emu, argv, ctx={}): LPCSTR lpTimerName ); """ + ctx = ctx or {} _attrs, _manual_reset, name = argv cw = self.get_char_width(ctx) @@ -4083,7 +4131,7 @@ def CreateWaitableTimer(self, emu, argv, ctx={}): return hnd @apihook("CreateWaitableTimerEx", argc=4) - def CreateWaitableTimerEx(self, emu, argv, ctx={}): + def CreateWaitableTimerEx(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateWaitableTimerEx( LPSECURITY_ATTRIBUTES lpTimerAttributes, @@ -4092,6 +4140,7 @@ def CreateWaitableTimerEx(self, emu, argv, ctx={}): DWORD dwDesiredAccess ); """ + ctx = ctx or {} _attrs, name, _flags, _access = argv cw = self.get_char_width(ctx) @@ -4112,7 +4161,7 @@ def CreateWaitableTimerEx(self, emu, argv, ctx={}): return hnd @apihook("OpenWaitableTimer", argc=3) - def OpenWaitableTimer(self, emu, argv, ctx={}): + def OpenWaitableTimer(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE OpenWaitableTimer( DWORD dwDesiredAccess, @@ -4120,6 +4169,7 @@ def OpenWaitableTimer(self, emu, argv, ctx={}): LPCSTR lpTimerName ); """ + ctx = ctx or {} _access, _inherit, name = argv cw = self.get_char_width(ctx) @@ -4140,7 +4190,7 @@ def OpenWaitableTimer(self, emu, argv, ctx={}): return hnd @apihook("SetWaitableTimer", argc=6) - def SetWaitableTimer(self, emu, argv, ctx={}): + def SetWaitableTimer(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetWaitableTimer( HANDLE hTimer, @@ -4162,7 +4212,7 @@ def SetWaitableTimer(self, emu, argv, ctx={}): return True @apihook("CancelWaitableTimer", argc=1) - def CancelWaitableTimer(self, emu, argv, ctx={}): + def CancelWaitableTimer(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CancelWaitableTimer( HANDLE hTimer @@ -4179,7 +4229,7 @@ def CancelWaitableTimer(self, emu, argv, ctx={}): return True @apihook("OpenEvent", argc=3) - def OpenEvent(self, emu, argv, ctx={}): + def OpenEvent(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE OpenEvent( DWORD dwDesiredAccess, @@ -4187,6 +4237,7 @@ def OpenEvent(self, emu, argv, ctx={}): LPCSTR lpName ); """ + ctx = ctx or {} access, inherit, name = argv cw = self.get_char_width(ctx) @@ -4207,7 +4258,7 @@ def OpenEvent(self, emu, argv, ctx={}): return hnd @apihook("SetEvent", argc=1) - def SetEvent(self, emu, argv, ctx={}): + def SetEvent(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetEvent( HANDLE hEvent @@ -4224,7 +4275,7 @@ def SetEvent(self, emu, argv, ctx={}): return rv @apihook("SetUnhandledExceptionFilter", argc=1) - def SetUnhandledExceptionFilter(self, emu, argv, ctx={}): + def SetUnhandledExceptionFilter(self, emu, argv, ctx: api.ApiContext = None): """ LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter @@ -4237,7 +4288,7 @@ def SetUnhandledExceptionFilter(self, emu, argv, ctx={}): return 0 @apihook("DeleteCriticalSection", argc=1) - def DeleteCriticalSection(self, emu, argv, ctx={}): + def DeleteCriticalSection(self, emu, argv, ctx: api.ApiContext = None): """ void DeleteCriticalSection( LPCRITICAL_SECTION lpCriticalSection @@ -4247,7 +4298,7 @@ def DeleteCriticalSection(self, emu, argv, ctx={}): return None @apihook("FlsFree", argc=1) - def FlsFree(self, emu, argv, ctx={}): + def FlsFree(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FlsFree( DWORD dwFlsIndex @@ -4257,7 +4308,7 @@ def FlsFree(self, emu, argv, ctx={}): return True @apihook("TlsFree", argc=1) - def TlsFree(self, emu, argv, ctx={}): + def TlsFree(self, emu, argv, ctx: api.ApiContext = None): """ BOOL TlsFree( DWORD dwTlsIndex @@ -4267,7 +4318,7 @@ def TlsFree(self, emu, argv, ctx={}): return True @apihook("ProcessIdToSessionId", argc=2) - def ProcessIdToSessionId(self, emu, argv, ctx={}): + def ProcessIdToSessionId(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ProcessIdToSessionId( DWORD dwProcessId, @@ -4290,7 +4341,7 @@ def ProcessIdToSessionId(self, emu, argv, ctx={}): return rv @apihook("InitializeCriticalSectionEx", argc=3) - def InitializeCriticalSectionEx(self, emu, argv, ctx={}): + def InitializeCriticalSectionEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL InitializeCriticalSectionEx( LPCRITICAL_SECTION lpCriticalSection, @@ -4303,7 +4354,7 @@ def InitializeCriticalSectionEx(self, emu, argv, ctx={}): return True @apihook("InitializeCriticalSection", argc=1) - def InitializeCriticalSection(self, emu, argv, ctx={}): + def InitializeCriticalSection(self, emu, argv, ctx: api.ApiContext = None): """ void InitializeCriticalSection( LPCRITICAL_SECTION lpCriticalSection @@ -4314,14 +4365,14 @@ def InitializeCriticalSection(self, emu, argv, ctx={}): return None @apihook("GetOEMCP", argc=0) - def GetOEMCP(self, emu, argv, ctx={}): + def GetOEMCP(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetOEMCP(); """ return 1200 @apihook("GlobalLock", argc=1) - def GlobalLock(self, emu, argv, ctx={}): + def GlobalLock(self, emu, argv, ctx: api.ApiContext = None): """ LPVOID GlobalLock( HGLOBAL hMem @@ -4333,7 +4384,7 @@ def GlobalLock(self, emu, argv, ctx={}): return hMem @apihook("LocalLock", argc=1) - def LocalLock(self, emu, argv, ctx={}): + def LocalLock(self, emu, argv, ctx: api.ApiContext = None): """ LPVOID LocalLock( HGLOBAL hMem @@ -4345,7 +4396,7 @@ def LocalLock(self, emu, argv, ctx={}): return hMem @apihook("HeapDestroy", argc=1) - def HeapDestroy(self, emu, argv, ctx={}): + def HeapDestroy(self, emu, argv, ctx: api.ApiContext = None): """ BOOL HeapDestroy( HANDLE hHeap @@ -4355,7 +4406,7 @@ def HeapDestroy(self, emu, argv, ctx={}): return True @apihook("InitializeSListHead", argc=1) - def InitializeSListHead(self, emu, argv, ctx={}): + def InitializeSListHead(self, emu, argv, ctx: api.ApiContext = None): """ void InitializeSListHead( PSLIST_HEADER ListHead @@ -4368,7 +4419,7 @@ def InitializeSListHead(self, emu, argv, ctx={}): return None @apihook("FreeLibrary", argc=1) - def FreeLibrary(self, emu, argv, ctx={}): + def FreeLibrary(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FreeLibrary( HMODULE hLibModule @@ -4378,7 +4429,7 @@ def FreeLibrary(self, emu, argv, ctx={}): return True @apihook("WaitForSingleObject", argc=2) - def WaitForSingleObject(self, emu, argv, ctx={}): + def WaitForSingleObject(self, emu, argv, ctx: api.ApiContext = None): """ DWORD WaitForSingleObject( HANDLE hHandle, @@ -4396,7 +4447,7 @@ def WaitForSingleObject(self, emu, argv, ctx={}): return rv @apihook("GetConsoleMode", argc=2) - def GetConsoleMode(self, emu, argv, ctx={}): + def GetConsoleMode(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WINAPI GetConsoleMode( _In_ HANDLE hConsoleHandle, @@ -4407,7 +4458,7 @@ def GetConsoleMode(self, emu, argv, ctx={}): return True @apihook("HeapSetInformation", argc=4) - def HeapSetInformation(self, emu, argv, ctx={}): + def HeapSetInformation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL HeapSetInformation( HANDLE HeapHandle, @@ -4420,7 +4471,7 @@ def HeapSetInformation(self, emu, argv, ctx={}): return True @apihook("SetErrorMode", argc=1) - def SetErrorMode(self, emu, argv, ctx={}): + def SetErrorMode(self, emu, argv, ctx: api.ApiContext = None): """ UINT SetErrorMode( UINT uMode @@ -4429,7 +4480,7 @@ def SetErrorMode(self, emu, argv, ctx={}): return 0 @apihook("InterlockedCompareExchange", argc=3) - def InterlockedCompareExchange(self, emu, argv, ctx={}): + def InterlockedCompareExchange(self, emu, argv, ctx: api.ApiContext = None): """ LONG InterlockedCompareExchange( LONG volatile *Destination, @@ -4448,7 +4499,7 @@ def InterlockedCompareExchange(self, emu, argv, ctx={}): return dest @apihook("InterlockedExchange", argc=2) - def InterlockedExchange(self, emu, argv, ctx={}): + def InterlockedExchange(self, emu, argv, ctx: api.ApiContext = None): """ LONG InterlockedExchange( LONG volatile *Target, @@ -4466,7 +4517,7 @@ def InterlockedExchange(self, emu, argv, ctx={}): return tgt @apihook("CreateNamedPipe", argc=8) - def CreateNamedPipe(self, emu, argv, ctx={}): + def CreateNamedPipe(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateNamedPipe( LPCSTR lpName, @@ -4479,6 +4530,7 @@ def CreateNamedPipe(self, emu, argv, ctx={}): LPSECURITY_ATTRIBUTES lpSecurityAttributes ); """ + ctx = ctx or {} ( lpName, dwOpenMode, @@ -4503,7 +4555,7 @@ def CreateNamedPipe(self, emu, argv, ctx={}): return hnd @apihook("CreatePipe", argc=4) - def CreatePipe(self, emu, argv, ctx={}): + def CreatePipe(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CreatePipe( PHANDLE hReadPipe, @@ -4529,7 +4581,7 @@ def CreatePipe(self, emu, argv, ctx={}): return 1 @apihook("PeekNamedPipe", argc=6) - def PeekNamedPipe(self, emu, argv, ctx={}): + def PeekNamedPipe(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PeekNamedPipe( HANDLE hNamedPipe, @@ -4557,7 +4609,7 @@ def PeekNamedPipe(self, emu, argv, ctx={}): return 1 @apihook("ConnectNamedPipe", argc=2) - def ConnectNamedPipe(self, emu, argv, ctx={}): + def ConnectNamedPipe(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ConnectNamedPipe( HANDLE hNamedPipe, @@ -4572,7 +4624,7 @@ def ConnectNamedPipe(self, emu, argv, ctx={}): return rv @apihook("DisconnectNamedPipe", argc=1) - def DisconnectNamedPipe(self, emu, argv, ctx={}): + def DisconnectNamedPipe(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DisconnectNamedPipe( HANDLE hNamedPipe @@ -4586,7 +4638,7 @@ def DisconnectNamedPipe(self, emu, argv, ctx={}): return rv @apihook("GetLocaleInfo", argc=4) - def GetLocaleInfo(self, emu, argv, ctx={}): + def GetLocaleInfo(self, emu, argv, ctx: api.ApiContext = None): """ int GetLocaleInfo( LCID Locale, @@ -4595,6 +4647,7 @@ def GetLocaleInfo(self, emu, argv, ctx={}): int cchData ); """ + ctx = ctx or {} Locale, LCType, lpLCData, cchData = argv rv = 0 @@ -4620,7 +4673,7 @@ def GetLocaleInfo(self, emu, argv, ctx={}): return rv @apihook("IsWow64Process", argc=2) - def IsWow64Process(self, emu, argv, ctx={}): + def IsWow64Process(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsWow64Process( HANDLE hProcess, @@ -4637,7 +4690,7 @@ def IsWow64Process(self, emu, argv, ctx={}): return rv @apihook("CheckRemoteDebuggerPresent", argc=2) - def CheckRemoteDebuggerPresent(self, emu, argv, ctx={}): + def CheckRemoteDebuggerPresent(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CheckRemoteDebuggerPresent( HANDLE hProcess, @@ -4654,13 +4707,14 @@ def CheckRemoteDebuggerPresent(self, emu, argv, ctx={}): return rv @apihook("GetComputerName", argc=2) - def GetComputerName(self, emu, argv, ctx={}): + def GetComputerName(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetComputerName( LPSTR lpBuffer, LPDWORD nSize ); """ + ctx = ctx or {} lpBuffer, nSize = argv rv = False @@ -4683,7 +4737,7 @@ def GetComputerName(self, emu, argv, ctx={}): return rv @apihook("GetVersionEx", argc=1) - def GetVersionEx(self, emu, argv, ctx={}): + def GetVersionEx(self, emu, argv, ctx: api.ApiContext = None): """ NOT_BUILD_WINDOWS_DEPRECATE BOOL GetVersionEx( LPOSVERSIONINFO lpVersionInformation @@ -4710,7 +4764,7 @@ def GetVersionEx(self, emu, argv, ctx={}): return rv @apihook("GetEnvironmentVariable", argc=3) - def GetEnvironmentVariable(self, emu, argv, ctx={}): + def GetEnvironmentVariable(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetEnvironmentVariable( LPCTSTR lpName, @@ -4718,6 +4772,7 @@ def GetEnvironmentVariable(self, emu, argv, ctx={}): DWORD nSize ); """ + ctx = ctx or {} lpName, lpBuffer, nSize = argv rv = 0 @@ -4741,7 +4796,7 @@ def GetEnvironmentVariable(self, emu, argv, ctx={}): return rv @apihook("GetCurrentPackageId", argc=2) - def GetCurrentPackageId(self, emu, argv, ctx={}): + def GetCurrentPackageId(self, emu, argv, ctx: api.ApiContext = None): """ LONG GetCurrentPackageId( UINT32 *bufferLength, @@ -4751,14 +4806,14 @@ def GetCurrentPackageId(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("AreFileApisANSI", argc=0) - def AreFileApisANSI(self, emu, argv, ctx={}): + def AreFileApisANSI(self, emu, argv, ctx: api.ApiContext = None): """ BOOL AreFileApisANSI(); """ return True @apihook("FindFirstFileEx", argc=6) - def FindFirstFileEx(self, emu, argv, ctx={}): + def FindFirstFileEx(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE FindFirstFileExA( LPCSTR lpFileName, @@ -4769,6 +4824,7 @@ def FindFirstFileEx(self, emu, argv, ctx={}): DWORD dwAdditionalFlags ); """ + ctx = ctx or {} ( lpFileName, fInfoLevelId, @@ -4785,13 +4841,14 @@ def FindFirstFileEx(self, emu, argv, ctx={}): return rv @apihook("FindFirstFile", argc=2) - def FindFirstFile(self, emu, argv, ctx={}): + def FindFirstFile(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE FindFirstFileA( LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData ); """ + ctx = ctx or {} lpFileName, lpFindFileData = argv @@ -4828,13 +4885,14 @@ def FindFirstFile(self, emu, argv, ctx={}): return hnd @apihook("FindNextFile", argc=2) - def FindNextFile(self, emu, argv, ctx={}): + def FindNextFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FindNextFile( HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData ); """ + ctx = ctx or {} hFindFile, lpFindFileData = argv rv = 1 @@ -4870,7 +4928,7 @@ def FindNextFile(self, emu, argv, ctx={}): return rv @apihook("FindClose", argc=1) - def FindClose(self, emu, argv, ctx={}): + def FindClose(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FindClose( HANDLE hFindFile @@ -4887,7 +4945,7 @@ def FindClose(self, emu, argv, ctx={}): return True @apihook("GetSystemTimes", argc=3) - def GetSystemTimes(self, emu, argv, ctx={}): + def GetSystemTimes(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetSystemTimes( PFILETIME lpIdleTime, @@ -4911,7 +4969,7 @@ def GetSystemTimes(self, emu, argv, ctx={}): return True @apihook("GetThreadContext", argc=2) - def GetThreadContext(self, emu, argv, ctx={}): + def GetThreadContext(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetThreadContext( HANDLE hThread, @@ -4932,7 +4990,7 @@ def GetThreadContext(self, emu, argv, ctx={}): return True @apihook("SetThreadContext", argc=2) - def SetThreadContext(self, emu, argv, ctx={}): + def SetThreadContext(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetThreadContext( HANDLE hThread, @@ -4957,7 +5015,7 @@ def SetThreadContext(self, emu, argv, ctx={}): return True @apihook("CompareFileTime", argc=2) - def CompareFileTime(self, emu, argv, ctx={}): + def CompareFileTime(self, emu, argv, ctx: api.ApiContext = None): """ LONG CompareFileTime( const FILETIME *lpFileTime1, @@ -4986,7 +5044,7 @@ def CompareFileTime(self, emu, argv, ctx={}): return rv @apihook("FindResource", argc=3) - def FindResource(self, emu, argv, ctx={}): + def FindResource(self, emu, argv, ctx: api.ApiContext = None): """ HRSRC FindResourceA( HMODULE hModule, @@ -4994,6 +5052,7 @@ def FindResource(self, emu, argv, ctx={}): LPCSTR lpType ); """ + ctx = ctx or {} cw = self.get_char_width(ctx) hModule, lpName, lpType = argv @@ -5020,7 +5079,7 @@ def FindResource(self, emu, argv, ctx={}): return pe.base + res.entry_rva @apihook("FindResourceEx", argc=4) - def FindResourceEx(self, emu, argv, ctx={}): + def FindResourceEx(self, emu, argv, ctx: api.ApiContext = None): """ HRSRC FindResourceExW( [in, optional] HMODULE hModule, @@ -5029,6 +5088,7 @@ def FindResourceEx(self, emu, argv, ctx={}): [in] WORD wLanguage ); """ + ctx = ctx or {} # repeats code from FindResource() cw = self.get_char_width(ctx) @@ -5054,7 +5114,7 @@ def FindResourceEx(self, emu, argv, ctx={}): return pe.base + res.entry_rva @apihook("LoadResource", argc=2) - def LoadResource(self, emu, argv, ctx={}): + def LoadResource(self, emu, argv, ctx: api.ApiContext = None): """ HGLOBAL LoadResource( HMODULE hModule, @@ -5081,7 +5141,7 @@ def LoadResource(self, emu, argv, ctx={}): return 0 @apihook("LockResource", argc=1) - def LockResource(self, emu, argv, ctx={}): + def LockResource(self, emu, argv, ctx: api.ApiContext = None): """ LPVOID LockResource( HGLOBAL hResData @@ -5093,7 +5153,7 @@ def LockResource(self, emu, argv, ctx={}): return hResData @apihook("SizeofResource", argc=2) - def SizeofResource(self, emu, argv, ctx={}): + def SizeofResource(self, emu, argv, ctx: api.ApiContext = None): """ DWORD SizeofResource( HMODULE hModule, @@ -5114,7 +5174,7 @@ def SizeofResource(self, emu, argv, ctx={}): return 0 @apihook("FreeResource", argc=1) - def FreeResource(self, emu, argv, ctx={}): + def FreeResource(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FreeResource( [in] HGLOBAL hResData @@ -5124,13 +5184,14 @@ def FreeResource(self, emu, argv, ctx={}): return 0 @apihook("GetCurrentDirectory", argc=2) - def GetCurrentDirectory(self, emu, argv, ctx={}): + def GetCurrentDirectory(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetCurrentDirectory( DWORD nBufferLength, LPTSTR lpBuffer ); """ + ctx = ctx or {} nBufferLength, lpBuffer = argv cw = self.get_char_width(ctx) @@ -5145,7 +5206,7 @@ def GetCurrentDirectory(self, emu, argv, ctx={}): return len(cd) @apihook("VirtualAllocExNuma", argc=6) - def VirtualAllocExNuma(self, emu, argv, ctx={}): + def VirtualAllocExNuma(self, emu, argv, ctx: api.ApiContext = None): """ LPVOID VirtualAllocExNuma( HANDLE hProcess, @@ -5156,12 +5217,13 @@ def VirtualAllocExNuma(self, emu, argv, ctx={}): DWORD nndPreferred ); """ + ctx = ctx or {} argv = argv[:-1] return self.VirtualAllocEx(emu, argv, ctx) @apihook("GetNativeSystemInfo", argc=1) - def GetNativeSystemInfo(self, emu, argv, ctx={}): + def GetNativeSystemInfo(self, emu, argv, ctx: api.ApiContext = None): """ void GetNativeSystemInfo( LPSYSTEM_INFO lpSystemInfo @@ -5171,19 +5233,20 @@ def GetNativeSystemInfo(self, emu, argv, ctx={}): return 0 @apihook("GetUserDefaultUILanguage", argc=0) - def GetUserDefaultUILanguage(self, emu, argv, ctx={}): + def GetUserDefaultUILanguage(self, emu, argv, ctx: api.ApiContext = None): """ LANGID GetUserDefaultUILanguage(); """ return 0xFFFF @apihook("SetCurrentDirectory", argc=1) - def SetCurrentDirectory(self, emu, argv, ctx={}): + def SetCurrentDirectory(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetCurrentDirectory( LPCTSTR lpPathName ); """ + ctx = ctx or {} (path,) = argv if path: @@ -5195,7 +5258,7 @@ def SetCurrentDirectory(self, emu, argv, ctx={}): return True @apihook("OpenThread", argc=3) - def OpenThread(self, emu, argv, ctx={}): + def OpenThread(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE OpenThread( DWORD dwDesiredAccess, @@ -5211,7 +5274,7 @@ def OpenThread(self, emu, argv, ctx={}): return hnd @apihook("RaiseException", argc=4) - def RaiseException(self, emu, argv, ctx={}): + def RaiseException(self, emu, argv, ctx: api.ApiContext = None): """ VOID RaiseException( DWORD dwExceptionCode, @@ -5226,7 +5289,7 @@ def RaiseException(self, emu, argv, ctx={}): return @apihook("VerSetConditionMask", argc=3, conv=e_arch.CALL_CONV_CDECL) - def VerSetConditionMask(self, emu, argv, ctx={}): + def VerSetConditionMask(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI ULONGLONG VerSetConditionMask( ULONGLONG ConditionMask, @@ -5240,7 +5303,7 @@ def VerSetConditionMask(self, emu, argv, ctx={}): return 0 @apihook("VerifyVersionInfo", argc=3, conv=e_arch.CALL_CONV_CDECL) - def VerifyVersionInfo(self, emu, argv, ctx={}): + def VerifyVersionInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL VerifyVersionInfo( LPOSVERSIONINFOEX lpVersionInformation, @@ -5254,14 +5317,14 @@ def VerifyVersionInfo(self, emu, argv, ctx={}): return True @apihook("FreeConsole", argc=0) - def FreeConsole(self, emu, argv, ctx={}): + def FreeConsole(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WINAPI FreeConsole(void); """ return True @apihook("IsBadWritePtr", argc=2) - def IsBadWritePtr(self, emu, argv, ctx={}): + def IsBadWritePtr(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsBadWritePtr( LPVOID lp, @@ -5282,13 +5345,14 @@ def IsBadWritePtr(self, emu, argv, ctx={}): return rv @apihook("IsBadStringPtr", argc=2) - def IsBadStringPtr(self, emu, argv, ctx={}): + def IsBadStringPtr(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsBadStringPtrW( LPCWSTR lpsz, UINT_PTR ucchMax ); """ + ctx = ctx or {} lpsz, ucchMax = argv cw = self.get_char_width(ctx) rv = True @@ -5303,7 +5367,7 @@ def IsBadStringPtr(self, emu, argv, ctx={}): return rv @apihook("GetSystemFirmwareTable", argc=4) - def GetSystemFirmwareTable(self, emu, argv, ctx={}): + def GetSystemFirmwareTable(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetSystemFirmwareTable( DWORD FirmwareTableProviderSignature, @@ -5323,13 +5387,14 @@ def GetSystemFirmwareTable(self, emu, argv, ctx={}): return rv @apihook("GetTempPath", argc=2) - def GetTempPath(self, emu, argv, ctx={}): + def GetTempPath(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetTempPathA( DWORD nBufferLength, LPSTR lpBuffer ); """ + ctx = ctx or {} nBufferLength, lpBuffer = argv rv = 0 @@ -5346,7 +5411,7 @@ def GetTempPath(self, emu, argv, ctx={}): return rv @apihook("SetPriorityClass", argc=2) - def SetPriorityClass(self, emu, argv, ctx={}): + def SetPriorityClass(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetPriorityClass( HANDLE hProcess, @@ -5356,7 +5421,7 @@ def SetPriorityClass(self, emu, argv, ctx={}): return 1 @apihook("SetProcessPriorityBoost", argc=2) - def SetProcessPriorityBoost(self, emu, argv, ctx={}): + def SetProcessPriorityBoost(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetProcessPriorityBoost( HANDLE hProcess, @@ -5367,12 +5432,13 @@ def SetProcessPriorityBoost(self, emu, argv, ctx={}): return 1 @apihook("GetDriveType", argc=1) - def GetDriveType(self, emu, argv, ctx={}): + def GetDriveType(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetDriveType( LPCSTR lpRootPathName ); """ + ctx = ctx or {} (lpRootPathName,) = argv cw = self.get_char_width(ctx) @@ -5390,7 +5456,7 @@ def GetDriveType(self, emu, argv, ctx={}): return dm.get_drive_type(name) @apihook("GetExitCodeProcess", argc=2) - def GetExitCodeProcess(self, emu, argv, ctx={}): + def GetExitCodeProcess(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetExitCodeProcess( HANDLE hProcess, @@ -5403,7 +5469,7 @@ def GetExitCodeProcess(self, emu, argv, ctx={}): return 1 @apihook("SetThreadPriority", argc=2) - def SetThreadPriority(self, emu, argv, ctx={}): + def SetThreadPriority(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetThreadPriority( HANDLE hThread, @@ -5413,7 +5479,7 @@ def SetThreadPriority(self, emu, argv, ctx={}): return 1 @apihook("ReleaseMutex", argc=1) - def ReleaseMutex(self, emu, argv, ctx={}): + def ReleaseMutex(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ReleaseMutex( HANDLE hMutex @@ -5422,7 +5488,7 @@ def ReleaseMutex(self, emu, argv, ctx={}): return 1 @apihook("GetShortPathName", argc=3) - def GetShortPathName(self, emu, argv, ctx={}): + def GetShortPathName(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetShortPathNameW( LPCWSTR lpszLongPath, @@ -5431,6 +5497,7 @@ def GetShortPathName(self, emu, argv, ctx={}): ); https://en.wikipedia.org/wiki/8.3_filename#VFAT_and_Computer-generated_8.3_filenames """ + ctx = ctx or {} lpszLongPath, lpszShortPath, cchBuffer = argv cw = self.get_char_width(ctx) s = self.read_mem_string(lpszLongPath, cw) @@ -5471,7 +5538,7 @@ def GetShortPathName(self, emu, argv, ctx={}): return len(out) + 1 @apihook("GetLongPathName", argc=3) - def GetLongPathName(self, emu, argv, ctx={}): + def GetLongPathName(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetLongPathNameA( LPCSTR lpszShortPath, @@ -5479,6 +5546,7 @@ def GetLongPathName(self, emu, argv, ctx={}): DWORD cchBuffer ); """ + ctx = ctx or {} lpszShortPath, lpszLongPath, cchBuffer = argv # Not an accurate implementation, just a placeholder for now @@ -5492,7 +5560,7 @@ def GetLongPathName(self, emu, argv, ctx={}): return len(s) * cw + 1 @apihook("QueueUserAPC", argc=3) - def QueueUserAPC(self, emu, argv, ctx={}): + def QueueUserAPC(self, emu, argv, ctx: api.ApiContext = None): """ DWORD QueueUserAPC( PAPCFUNC pfnAPC, @@ -5505,7 +5573,7 @@ def QueueUserAPC(self, emu, argv, ctx={}): self.create_thread(pfnAPC, dwData, 0, thread_type=run_type) @apihook("DuplicateHandle", argc=7) - def DuplicateHandle(self, emu, argv, ctx={}): + def DuplicateHandle(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DuplicateHandle( HANDLE hSourceProcessHandle, @@ -5520,7 +5588,7 @@ def DuplicateHandle(self, emu, argv, ctx={}): return 1 @apihook("GetBinaryType", argc=2) - def GetBinaryType(self, emu, argv, ctx={}): + def GetBinaryType(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetBinaryTypeA( LPCSTR lpApplicationName, @@ -5530,14 +5598,14 @@ def GetBinaryType(self, emu, argv, ctx={}): return 0 @apihook("GetThreadUILanguage", argc=0) - def GetThreadUILanguage(self, emu, argv, ctx={}): + def GetThreadUILanguage(self, emu, argv, ctx: api.ApiContext = None): """ LANGID GetThreadUILanguage(); """ return 0xFFFF @apihook("SetConsoleHistoryInfo", argc=1) - def SetConsoleHistoryInfo(self, emu, argv, ctx={}): + def SetConsoleHistoryInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WINAPI SetConsoleHistoryInfo( _In_ PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo @@ -5546,7 +5614,7 @@ def SetConsoleHistoryInfo(self, emu, argv, ctx={}): return 1 @apihook("GetFileInformationByHandle", argc=2) - def GetFileInformationByHandle(self, emu, argv, ctx={}): + def GetFileInformationByHandle(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetFileInformationByHandle( HANDLE hFile, @@ -5556,7 +5624,7 @@ def GetFileInformationByHandle(self, emu, argv, ctx={}): return 0 @apihook("GetCommProperties", argc=2) - def GetCommProperties(self, emu, argv, ctx={}): + def GetCommProperties(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetCommProperties( HANDLE hFile, @@ -5566,7 +5634,7 @@ def GetCommProperties(self, emu, argv, ctx={}): return 0 @apihook("GetCommTimeouts", argc=2) - def GetCommTimeouts(self, emu, argv, ctx={}): + def GetCommTimeouts(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetCommTimeouts( HANDLE hFile, @@ -5576,12 +5644,13 @@ def GetCommTimeouts(self, emu, argv, ctx={}): return 0 @apihook("AddAtom", argc=1) - def AddAtom(self, emu, argv, ctx={}): + def AddAtom(self, emu, argv, ctx: api.ApiContext = None): """ ATOM AddAtomW( LPCWSTR lpString ); """ + ctx = ctx or {} ATOM_RESERVED = 0xC000 (lpString,) = argv cw = self.get_char_width(ctx) @@ -5597,12 +5666,13 @@ def AddAtom(self, emu, argv, ctx={}): return self.add_local_atom(s) @apihook("FindAtom", argc=1) - def FindAtom(self, emu, argv, ctx={}): + def FindAtom(self, emu, argv, ctx: api.ApiContext = None): """ ATOM FindAtomA( LPCSTR lpString ); """ + ctx = ctx or {} ATOM_RESERVED = 0xC000 (lpString,) = argv cw = self.get_char_width(ctx) @@ -5623,7 +5693,7 @@ def FindAtom(self, emu, argv, ctx={}): return atom @apihook("GetAtomName", argc=3) - def GetAtomName(self, emu, argv, ctx={}): + def GetAtomName(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetAtomNameA( ATOM nAtom, @@ -5631,6 +5701,7 @@ def GetAtomName(self, emu, argv, ctx={}): int nSize ); """ + ctx = ctx or {} ATOM_RESERVED = 0xC000 nAtom, lpBuffer, nSize = argv cw = self.get_char_width(ctx) @@ -5651,7 +5722,7 @@ def GetAtomName(self, emu, argv, ctx={}): return len(s) - 1 @apihook("DeleteAtom", argc=1) - def DeleteAtom(self, emu, argv, ctx={}): + def DeleteAtom(self, emu, argv, ctx: api.ApiContext = None): """ ATOM DeleteAtom( ATOM nAtom @@ -5670,7 +5741,7 @@ def DeleteAtom(self, emu, argv, ctx={}): return nAtom @apihook("GetProcessHandleCount", argc=1) - def GetProcessHandleCount(self, emu, argv, ctx={}): + def GetProcessHandleCount(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetProcessHandleCount( HANDLE hProcess, @@ -5680,7 +5751,7 @@ def GetProcessHandleCount(self, emu, argv, ctx={}): return 0 @apihook("GetMailslotInfo", argc=5) - def GetMailslotInfo(self, emu, argv, ctx={}): + def GetMailslotInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetMailslotInfo( HANDLE hMailslot, @@ -5693,7 +5764,7 @@ def GetMailslotInfo(self, emu, argv, ctx={}): return 0 @apihook("RtlZeroMemory", argc=2) - def RtlZeroMemory(self, emu, argv, ctx={}): + def RtlZeroMemory(self, emu, argv, ctx: api.ApiContext = None): """ void RtlZeroMemory( void* Destination, @@ -5705,7 +5776,7 @@ def RtlZeroMemory(self, emu, argv, ctx={}): self.mem_write(dest, buf) @apihook("RtlMoveMemory", argc=3) - def RtlMoveMemory(self, emu, argv, ctx={}): + def RtlMoveMemory(self, emu, argv, ctx: api.ApiContext = None): """ void RtlMoveMemory(void* pvDest, const void *pSrc, size_t Length); """ @@ -5714,7 +5785,7 @@ def RtlMoveMemory(self, emu, argv, ctx={}): self.mem_write(dest, buf) @apihook("QueryPerformanceFrequency", argc=1) - def QueryPerformanceFrequency(self, emu, argv, ctx={}): + def QueryPerformanceFrequency(self, emu, argv, ctx: api.ApiContext = None): """ BOOL QueryPerformanceFrequency( LARGE_INTEGER *lpFrequency @@ -5725,13 +5796,14 @@ def QueryPerformanceFrequency(self, emu, argv, ctx={}): return 1 @apihook("FindFirstVolume", argc=2) - def FindFirstVolume(self, emu, argv, ctx={}): + def FindFirstVolume(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE FindFirstVolumeW( LPWSTR lpszVolumeName, DWORD cchBufferLength ); """ + ctx = ctx or {} lpszVolumeName, _ = argv cw = self.get_char_width(ctx) @@ -5752,7 +5824,7 @@ def FindFirstVolume(self, emu, argv, ctx={}): return hnd @apihook("FindNextVolume", argc=3) - def FindNextVolume(self, emu, argv, ctx={}): + def FindNextVolume(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FindNextVolumeW( HANDLE hFindVolume, @@ -5760,6 +5832,7 @@ def FindNextVolume(self, emu, argv, ctx={}): DWORD cchBufferLength ); """ + ctx = ctx or {} hFindVolume, lpszVolumeName, cchBufferLength = argv cw = self.get_char_width(ctx) @@ -5783,7 +5856,7 @@ def FindNextVolume(self, emu, argv, ctx={}): return 1 @apihook("FindVolumeClose", argc=1) - def FindVolumeClose(self, emu, argv, ctx={}): + def FindVolumeClose(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FindVolumeClose( HANDLE hFindVolume @@ -5799,7 +5872,7 @@ def FindVolumeClose(self, emu, argv, ctx={}): return 1 @apihook("CreateIoCompletionPort", argc=4) - def CreateIoCompletionPort(self, emu, argv, ctx={}): + def CreateIoCompletionPort(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE WINAPI CreateIoCompletionPort( _In_ HANDLE FileHandle, @@ -5816,7 +5889,7 @@ def CreateIoCompletionPort(self, emu, argv, ctx={}): return hnd @apihook("GetVolumePathNamesForVolumeName", argc=4) - def GetVolumePathNamesForVolumeName(self, emu, argv, ctx={}): + def GetVolumePathNamesForVolumeName(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetVolumePathNamesForVolumeNameW( LPCWSTR lpszVolumeName, @@ -5825,6 +5898,7 @@ def GetVolumePathNamesForVolumeName(self, emu, argv, ctx={}): PDWORD lpcchReturnLength ); """ + ctx = ctx or {} lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength = argv cw = self.get_char_width(ctx) @@ -5856,7 +5930,7 @@ def GetVolumePathNamesForVolumeName(self, emu, argv, ctx={}): return rv @apihook("GetLogicalDrives", argc=0) - def GetLogicalDrives(self, emu, argv, ctx={}): + def GetLogicalDrives(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetLogicalDrives(); """ @@ -5869,7 +5943,7 @@ def GetLogicalDrives(self, emu, argv, ctx={}): return rv @apihook("GlobalMemoryStatus", argc=1) - def GlobalMemoryStatus(self, emu, argv, ctx={}): + def GlobalMemoryStatus(self, emu, argv, ctx: api.ApiContext = None): """ void GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer @@ -5878,7 +5952,7 @@ def GlobalMemoryStatus(self, emu, argv, ctx={}): return @apihook("GlobalMemoryStatusEx", argc=1) - def GlobalMemoryStatusEx(self, emu, argv, ctx={}): + def GlobalMemoryStatusEx(self, emu, argv, ctx: api.ApiContext = None): """ void GlobalMemoryStatusEx( LPMEMORYSTATUSEX lpBuffer @@ -5914,7 +5988,7 @@ def GlobalMemoryStatusEx(self, emu, argv, ctx={}): return @apihook("GetDiskFreeSpaceEx", argc=4) - def GetDiskFreeSpaceEx(self, emu, argv, ctx={}): + def GetDiskFreeSpaceEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetDiskFreeSpaceEx( LPCSTR lpDirectoryName, @@ -5926,14 +6000,14 @@ def GetDiskFreeSpaceEx(self, emu, argv, ctx={}): return True @apihook("GetSystemDefaultLangID", argc=0) - def GetSystemDefaultLangID(self, emu, argv, ctx={}): + def GetSystemDefaultLangID(self, emu, argv, ctx: api.ApiContext = None): """ LANGID GetSystemDefaultLangID(); """ return True @apihook("ResetEvent", argc=1) - def ResetEvent(self, emu, argv, ctx={}): + def ResetEvent(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ResetEvent( HANDLE hEvent @@ -5942,7 +6016,7 @@ def ResetEvent(self, emu, argv, ctx={}): return True @apihook("WaitForMultipleObjects", argc=4) - def WaitForMultipleObjects(self, emu, argv, ctx={}): + def WaitForMultipleObjects(self, emu, argv, ctx: api.ApiContext = None): """ DWORD WaitForMultipleObjects( DWORD nCount, @@ -5954,7 +6028,7 @@ def WaitForMultipleObjects(self, emu, argv, ctx={}): return 0 @apihook("GetComputerNameEx", argc=3) - def GetComputerNameEx(self, emu, argv, ctx={}): + def GetComputerNameEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetComputerNameExA( COMPUTER_NAME_FORMAT NameType, @@ -5962,6 +6036,7 @@ def GetComputerNameEx(self, emu, argv, ctx={}): LPDWORD nSize ); """ + ctx = ctx or {} NameType, lpBuffer, nSize = argv cw = self.get_char_width(ctx) @@ -5982,7 +6057,7 @@ def GetComputerNameEx(self, emu, argv, ctx={}): return 1 @apihook("GetDateFormat", argc=6) - def GetDateFormat(self, emu, argv, ctx={}): + def GetDateFormat(self, emu, argv, ctx: api.ApiContext = None): """ int GetDateFormatA( LCID Locale, @@ -5993,6 +6068,7 @@ def GetDateFormat(self, emu, argv, ctx={}): int cchDate ); """ + ctx = ctx or {} Locale, dwFlags, lpDate, lpFormat, lpDateStr, cchDate = argv cw = self.get_char_width(ctx) @@ -6032,7 +6108,7 @@ def GetDateFormat(self, emu, argv, ctx={}): return 1 @apihook("DeviceIoControl", argc=8) - def DeviceIoControl(self, emu, argv, ctx={}): + def DeviceIoControl(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DeviceIoControl( HANDLE hDevice, @@ -6086,7 +6162,7 @@ def DeviceIoControl(self, emu, argv, ctx={}): return 0 @apihook("GetTimeFormat", argc=6) - def GetTimeFormat(self, emu, argv, ctx={}): + def GetTimeFormat(self, emu, argv, ctx: api.ApiContext = None): """ int GetTimeFormatA( LCID Locale, @@ -6097,6 +6173,7 @@ def GetTimeFormat(self, emu, argv, ctx={}): int cchTime ); """ + ctx = ctx or {} Locale, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime = argv cw = self.get_char_width(ctx) @@ -6140,7 +6217,7 @@ def GetTimeFormat(self, emu, argv, ctx={}): return 1 @apihook("FlushFileBuffers", argc=1) - def FlushFileBuffers(self, emu, argv, ctx={}): + def FlushFileBuffers(self, emu, argv, ctx: api.ApiContext = None): """BOOL FlushFileBuffers( HANDLE hFile );""" @@ -6152,7 +6229,7 @@ def FlushFileBuffers(self, emu, argv, ctx={}): return rv @apihook("GetExitCodeThread", argc=2) - def GetExitCodeThread(self, emu, argv, ctx={}): + def GetExitCodeThread(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetExitCodeThread( HANDLE hThread, @@ -6166,7 +6243,7 @@ def GetExitCodeThread(self, emu, argv, ctx={}): return True @apihook("InitializeConditionVariable", argc=1) - def InitializeConditionVariable(self, emu, argv, ctx={}): + def InitializeConditionVariable(self, emu, argv, ctx: api.ApiContext = None): """ void InitializeConditionVariable( PCONDITION_VARIABLE ConditionVariable @@ -6178,7 +6255,7 @@ def InitializeConditionVariable(self, emu, argv, ctx={}): return rv @apihook("WakeAllConditionVariable", argc=1) - def WakeAllConditionVariable(self, emu, argv, ctx={}): + def WakeAllConditionVariable(self, emu, argv, ctx: api.ApiContext = None): """ void WakeAllConditionVariable( PCONDITION_VARIABLE ConditionVariable @@ -6187,7 +6264,7 @@ def WakeAllConditionVariable(self, emu, argv, ctx={}): return @apihook("Wow64DisableWow64FsRedirection", argc=1) - def Wow64DisableWow64FsRedirection(self, emu, argv, ctx={}): + def Wow64DisableWow64FsRedirection(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Wow64DisableWow64FsRedirection( PVOID *OldValue @@ -6199,7 +6276,7 @@ def Wow64DisableWow64FsRedirection(self, emu, argv, ctx={}): return rv @apihook("Wow64RevertWow64FsRedirection", argc=1) - def Wow64RevertWow64FsRedirection(self, emu, argv, ctx={}): + def Wow64RevertWow64FsRedirection(self, emu, argv, ctx: api.ApiContext = None): """ BOOL Wow64RevertWow64FsRedirection( PVOID OlValue @@ -6211,7 +6288,7 @@ def Wow64RevertWow64FsRedirection(self, emu, argv, ctx={}): return rv @apihook("EnumProcesses", argc=3) - def EnumProcesses(self, emu, argv, ctx={}): + def EnumProcesses(self, emu, argv, ctx: api.ApiContext = None): """ BOOL EnumProcesses( DWORD *lpidProcess, @@ -6236,7 +6313,7 @@ def EnumProcesses(self, emu, argv, ctx={}): return 1 @apihook("GetModuleFileNameExA", argc=4) - def GetModuleFileNameExA(self, emu, argv, ctx={}): + def GetModuleFileNameExA(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetModuleFileNameExA( HANDLE hProcess, @@ -6245,6 +6322,7 @@ def GetModuleFileNameExA(self, emu, argv, ctx={}): DWORD nSize ); """ + ctx = ctx or {} hProcess, hModule, lpFilename, nSize = argv if hModule: @@ -6278,14 +6356,14 @@ def GetModuleFileNameExA(self, emu, argv, ctx={}): return size @apihook("GetThreadPriority", argc=1) - def GetThreadPriority(self, emu, argv, ctx={}): + def GetThreadPriority(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE hThread; """ return k32types.THREAD_PRIORITY_NORMAL @apihook("RtlUnwind", argc=4) - def RtlUnwind(self, emu, argv, ctx={}): + def RtlUnwind(self, emu, argv, ctx: api.ApiContext = None): """ VOID RtlUnwind( PVOID TargetFrame, @@ -6297,14 +6375,14 @@ def RtlUnwind(self, emu, argv, ctx={}): return @apihook("UnhandledExceptionFilter", argc=1) - def UnhandledExceptionFilter(self, emu, argv, ctx={}): + def UnhandledExceptionFilter(self, emu, argv, ctx: api.ApiContext = None): """ _EXCEPTION_POINTERS *ExceptionInfo; """ return k32types.EXCEPTION_EXECUTE_HANDLER @apihook("GetSystemTimePreciseAsFileTime", argc=1) - def GetSystemTimePreciseAsFileTime(self, emu, argv, ctx={}): + def GetSystemTimePreciseAsFileTime(self, emu, argv, ctx: api.ApiContext = None): """void GetSystemTimePreciseAsFileTime( LPFILETIME lpSystemTimeAsFileTime );""" @@ -6321,7 +6399,7 @@ def GetSystemTimePreciseAsFileTime(self, emu, argv, ctx={}): return @apihook("AddVectoredExceptionHandler", argc=2) - def AddVectoredExceptionHandler(self, emu, argv, ctx={}): + def AddVectoredExceptionHandler(self, emu, argv, ctx: api.ApiContext = None): """ PVOID AddVectoredExceptionHandler( ULONG First, @@ -6335,7 +6413,7 @@ def AddVectoredExceptionHandler(self, emu, argv, ctx={}): return Handler @apihook("RemoveVectoredExceptionHandler", argc=1) - def RemoveVectoredExceptionHandler(self, emu, argv, ctx={}): + def RemoveVectoredExceptionHandler(self, emu, argv, ctx: api.ApiContext = None): """ ULONG RemoveVectoredExceptionHandler( PVOID Handle); @@ -6345,21 +6423,21 @@ def RemoveVectoredExceptionHandler(self, emu, argv, ctx={}): return 1 @apihook("GetSystemDefaultUILanguage", argc=0) - def GetSystemDefaultUILanguage(self, emu, argv, ctx={}): + def GetSystemDefaultUILanguage(self, emu, argv, ctx: api.ApiContext = None): """ LANGID GetSystemDefaultUILanguage(); """ return LANG_EN_US @apihook("GetUserDefaultLangID", argc=0) - def GetUserDefaultLangID(self, emu, argv, ctx={}): + def GetUserDefaultLangID(self, emu, argv, ctx: api.ApiContext = None): """ LANGID GetUserDefaultLangID(); """ return LANG_EN_US @apihook("GetUserDefaultLCID", argc=0) - def GetUserDefaultLCID(self, emu, argv, ctx={}): + def GetUserDefaultLCID(self, emu, argv, ctx: api.ApiContext = None): """ LCID GetUserDefaultLCID(); """ @@ -6367,7 +6445,7 @@ def GetUserDefaultLCID(self, emu, argv, ctx={}): return LOCALE_USER_DEFAULT @apihook("GetSystemDefaultLCID", argc=0) - def GetSystemDefaultLCID(self, emu, argv, ctx={}): + def GetSystemDefaultLCID(self, emu, argv, ctx: api.ApiContext = None): """ LCID GetUserDefaultLCID(); """ @@ -6375,7 +6453,7 @@ def GetSystemDefaultLCID(self, emu, argv, ctx={}): return LOCALE_SYSTEM_DEFAULT @apihook("GetTempFileName", argc=4) - def GetTempFileName(self, emu, argv, ctx={}): + def GetTempFileName(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetTempFileName( [in] LPCSTR lpPathName, @@ -6384,6 +6462,7 @@ def GetTempFileName(self, emu, argv, ctx={}): [out] LPSTR lpTempFileName ); """ + ctx = ctx or {} lpPathName, lpPrefixString, uUnique, lpTempFileName = argv cw = self.get_char_width(ctx) @@ -6402,7 +6481,7 @@ def GetTempFileName(self, emu, argv, ctx={}): return len(out) + 1 @apihook("_llseek", argc=3) - def _llseek(self, emu, argv, ctx={}): + def _llseek(self, emu, argv, ctx: api.ApiContext = None): """ LONG _llseek( HFILE hFile, @@ -6424,13 +6503,14 @@ def _llseek(self, emu, argv, ctx={}): return rv @apihook("_lopen", argc=2) - def _lopen(self, emu, argv, ctx={}): + def _lopen(self, emu, argv, ctx: api.ApiContext = None): """ HFILE _lopen( LPCSTR lpPathName, int iReadWrite ); """ + ctx = ctx or {} lpFileName, iRedWrite = argv cw = self.get_char_width(ctx) filename = self.read_mem_string(lpFileName, cw) @@ -6438,7 +6518,7 @@ def _lopen(self, emu, argv, ctx={}): return fHandle @apihook("_lclose", argc=1) - def _lclose(self, emu, argv, ctx={}): + def _lclose(self, emu, argv, ctx: api.ApiContext = None): """ HFILE _lclose( HFILE hFile @@ -6452,13 +6532,14 @@ def _lclose(self, emu, argv, ctx={}): return False @apihook("GetConsoleTitle", argc=2) - def GetConsoleTitle(self, emu, argv, ctx={}): + def GetConsoleTitle(self, emu, argv, ctx: api.ApiContext = None): """ DWORD WINAPI GetConsoleTitle( _Out_ LPTSTR lpConsoleTitle, _In_ DWORD nSize ); """ + ctx = ctx or {} lpConsoleTitle, nSize = argv cw = self.get_char_width(ctx) rv = False @@ -6483,7 +6564,7 @@ def GetConsoleTitle(self, emu, argv, ctx={}): return rv @apihook("InitializeSRWLock", argc=1) - def InitializeSRWLock(self, emu, argv, ctx={}): + def InitializeSRWLock(self, emu, argv, ctx: api.ApiContext = None): """ void InitializeSRWLock( [out] PSRWLOCK SRWLock @@ -6493,7 +6574,7 @@ def InitializeSRWLock(self, emu, argv, ctx={}): return @apihook("AcquireSRWLockShared", argc=1) - def AcquireSRWLockShared(self, emu, argv, ctx={}): + def AcquireSRWLockShared(self, emu, argv, ctx: api.ApiContext = None): """ void AcquireSRWLockShared( [in, out] PSRWLOCK SRWLock @@ -6503,7 +6584,7 @@ def AcquireSRWLockShared(self, emu, argv, ctx={}): return @apihook("ReleaseSRWLockShared", argc=1) - def ReleaseSRWLockShared(self, emu, argv, ctx={}): + def ReleaseSRWLockShared(self, emu, argv, ctx: api.ApiContext = None): """ void ReleaseSRWLockShared( [in, out] PSRWLOCK SRWLock @@ -6513,7 +6594,7 @@ def ReleaseSRWLockShared(self, emu, argv, ctx={}): return @apihook("AcquireSRWLockExclusive", argc=1) - def AcquireSRWLockExclusive(self, emu, argv, ctx={}): + def AcquireSRWLockExclusive(self, emu, argv, ctx: api.ApiContext = None): """ void AcquireSRWLockExclusive( [in, out] PSRWLOCK SRWLock @@ -6523,7 +6604,7 @@ def AcquireSRWLockExclusive(self, emu, argv, ctx={}): return @apihook("ReleaseSRWLockExclusive", argc=1) - def ReleaseSRWLockExclusive(self, emu, argv, ctx={}): + def ReleaseSRWLockExclusive(self, emu, argv, ctx: api.ApiContext = None): """ void ReleaseSRWLockExclusive( [in, out] PSRWLOCK SRWLock @@ -6533,7 +6614,7 @@ def ReleaseSRWLockExclusive(self, emu, argv, ctx={}): return @apihook("GetPhysicallyInstalledSystemMemory", argc=1) - def GetPhysicallyInstalledSystemMemory(self, emu, argv, ctx={}): + def GetPhysicallyInstalledSystemMemory(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetPhysicallyInstalledSystemMemory( [out] PULONGLONG TotalMemoryInKilobytes @@ -6547,20 +6628,20 @@ def GetPhysicallyInstalledSystemMemory(self, emu, argv, ctx={}): return 1 @apihook("WTSGetActiveConsoleSessionId", argc=0) - def WTSGetActiveConsoleSessionId(self, emu, argv, ctx={}): + def WTSGetActiveConsoleSessionId(self, emu, argv, ctx: api.ApiContext = None): return emu.get_current_process().session @apihook("WaitForSingleObjectEx", argc=3) - def WaitForSingleObjectEx(self, emu, argv, ctx={}): + def WaitForSingleObjectEx(self, emu, argv, ctx: api.ApiContext = None): return 0 # = WAIT_OBJECT_0 @apihook("GetProfileInt", argc=3) - def GetProfileInt(self, emu, argv, ctx={}): + def GetProfileInt(self, emu, argv, ctx: api.ApiContext = None): _, _, nDefault = argv return nDefault @apihook("CreateSemaphoreW", argc=4) - def CreateSemaphoreW(self, emu, argv, ctx={}): + def CreateSemaphoreW(self, emu, argv, ctx: api.ApiContext = None): """ HANDLE CreateSemaphoreW( [in, optional] LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, @@ -6572,7 +6653,7 @@ def CreateSemaphoreW(self, emu, argv, ctx={}): return 0 @apihook("SetThreadStackGuarantee", argc=1) - def SetThreadStackGuarantee(self, emu, argv, ctx={}): + def SetThreadStackGuarantee(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetThreadStackGuarantee( [in, out] PULONG StackSizeInBytes @@ -6581,7 +6662,7 @@ def SetThreadStackGuarantee(self, emu, argv, ctx={}): return 1 @apihook("SetThreadDescription", argc=2) - def SetThreadDescription(self, emu, argv, ctx={}): + def SetThreadDescription(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT SetThreadDescription( [in] HANDLE hThread, @@ -6591,7 +6672,7 @@ def SetThreadDescription(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("InitOnceBeginInitialize", argc=4) - def InitOnceBeginInitialize(self, emu, argv, ctx={}): + def InitOnceBeginInitialize(self, emu, argv, ctx: api.ApiContext = None): """ BOOL InitOnceBeginInitialize( [in, out] LPINIT_ONCE lpInitOnce, @@ -6603,7 +6684,7 @@ def InitOnceBeginInitialize(self, emu, argv, ctx={}): return 1 @apihook("FlsGetValue2", argc=1) - def FlsGetValue2(self, emu, argv, ctx={}): + def FlsGetValue2(self, emu, argv, ctx: api.ApiContext = None): fls_index = argv[0] try: val = emu.get_fls_value(fls_index) @@ -6612,7 +6693,7 @@ def FlsGetValue2(self, emu, argv, ctx={}): return 0x1000 @apihook("RtlCaptureContext", argc=1) - def RtlCaptureContext(self, emu, argv, ctx={}): + def RtlCaptureContext(self, emu, argv, ctx: api.ApiContext = None): ptr = self.emu.reg_read("rcx") if ptr: try: @@ -6628,11 +6709,11 @@ def RtlCaptureContext(self, emu, argv, ctx={}): return True @apihook("RtlLookupFunctionEntry", argc=3) - def RtlLookupFunctionEntry(self, emu, argv, ctx={}): + def RtlLookupFunctionEntry(self, emu, argv, ctx: api.ApiContext = None): return 0 @apihook("MulDiv", argc=3) - def MulDiv(self, emu, argv, ctx={}): + def MulDiv(self, emu, argv, ctx: api.ApiContext = None): """ int MulDiv( int nNumber, @@ -6649,7 +6730,7 @@ def MulDiv(self, emu, argv, ctx={}): return 0 @apihook("GlobalAddAtomA", argc=1) - def GlobalAddAtomA(self, emu, argv, ctx={}): + def GlobalAddAtomA(self, emu, argv, ctx: api.ApiContext = None): """ ATOM GlobalAddAtomA( LPCSTR lpString diff --git a/speakeasy/winenv/api/usermode/lz32.py b/speakeasy/winenv/api/usermode/lz32.py index 1af25cfb..0ad6d450 100644 --- a/speakeasy/winenv/api/usermode/lz32.py +++ b/speakeasy/winenv/api/usermode/lz32.py @@ -16,7 +16,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("LZSeek", argc=3, conv=_arch.CALL_CONV_STDCALL) - def LZSeek(self, emu, argv, ctx={}): + def LZSeek(self, emu, argv, ctx: api.ApiContext = None): """ LONG LZSeek( INT hFile, diff --git a/speakeasy/winenv/api/usermode/mpr.py b/speakeasy/winenv/api/usermode/mpr.py index 81d4d168..bc35c9e3 100644 --- a/speakeasy/winenv/api/usermode/mpr.py +++ b/speakeasy/winenv/api/usermode/mpr.py @@ -17,7 +17,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("WNetOpenEnum", argc=5, conv=_arch.CALL_CONV_STDCALL) - def WNetOpenEnum(self, emu, argv, ctx={}): + def WNetOpenEnum(self, emu, argv, ctx: api.ApiContext = None): """ DWORD WNetOpenEnum( DWORD dwScope, @@ -44,7 +44,7 @@ def WNetOpenEnum(self, emu, argv, ctx={}): return mpr.ERROR_NO_NETWORK @apihook("WNetEnumResource", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WNetEnumResource(self, emu, argv, ctx={}): + def WNetEnumResource(self, emu, argv, ctx: api.ApiContext = None): """ DWORD WNetEnumResourceA( HANDLE hEnum, @@ -56,7 +56,7 @@ def WNetEnumResource(self, emu, argv, ctx={}): return mpr.ERROR_NO_NETWORK @apihook("WNetAddConnection2", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WNetAddConnection2(self, emu, argv, ctx={}): + def WNetAddConnection2(self, emu, argv, ctx: api.ApiContext = None): """ DWORD WNetAddConnection2W( LPNETRESOURCEW lpNetResource, @@ -68,7 +68,7 @@ def WNetAddConnection2(self, emu, argv, ctx={}): return mpr.ERROR_NO_NETWORK @apihook("WNetGetConnection", argc=3, conv=_arch.CALL_CONV_STDCALL) - def WNetGetConnection(self, emu, argv, ctx={}): + def WNetGetConnection(self, emu, argv, ctx: api.ApiContext = None): """ DWORD WNetGetConnectionA( LPCSTR lpLocalName, @@ -76,6 +76,7 @@ def WNetGetConnection(self, emu, argv, ctx={}): LPDWORD lpnLength ); """ + ctx = ctx or {} lpLocalName, lpRemoteName, lpnLength = argv cw = self.get_char_width(ctx) diff --git a/speakeasy/winenv/api/usermode/mscoree.py b/speakeasy/winenv/api/usermode/mscoree.py index e0e4fa1c..db560039 100644 --- a/speakeasy/winenv/api/usermode/mscoree.py +++ b/speakeasy/winenv/api/usermode/mscoree.py @@ -22,7 +22,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("CorExitProcess", argc=1) - def CorExitProcess(self, emu, argv, ctx={}): + def CorExitProcess(self, emu, argv, ctx: api.ApiContext = None): """ void STDMETHODCALLTYPE CorExitProcess ( int exitCode diff --git a/speakeasy/winenv/api/usermode/msi32.py b/speakeasy/winenv/api/usermode/msi32.py index 94af0a9c..1113eee7 100644 --- a/speakeasy/winenv/api/usermode/msi32.py +++ b/speakeasy/winenv/api/usermode/msi32.py @@ -16,7 +16,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("MsiDatabaseMergeA", argc=3, conv=_arch.CALL_CONV_STDCALL, ordinal=29) - def MsiDatabaseMergeA(self, emu, argv, ctx={}): + def MsiDatabaseMergeA(self, emu, argv, ctx: api.ApiContext = None): """ UINT MsiDatabaseMergeA( MSIHANDLE hDatabase, diff --git a/speakeasy/winenv/api/usermode/msimg32.py b/speakeasy/winenv/api/usermode/msimg32.py index 4b6c8aaf..3dfbaf9a 100644 --- a/speakeasy/winenv/api/usermode/msimg32.py +++ b/speakeasy/winenv/api/usermode/msimg32.py @@ -19,7 +19,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("TransparentBlt", argc=11) - def TransparentBlt(self, emu, argv, ctx={}): + def TransparentBlt(self, emu, argv, ctx: api.ApiContext = None): """ BOOL TransparentBlt( HDC hdcDest, diff --git a/speakeasy/winenv/api/usermode/msvcrt.py b/speakeasy/winenv/api/usermode/msvcrt.py index d944ce29..5402881b 100644 --- a/speakeasy/winenv/api/usermode/msvcrt.py +++ b/speakeasy/winenv/api/usermode/msvcrt.py @@ -90,7 +90,7 @@ def _acmdln(self, ptr=0): return cmdln @apihook("__p__acmdln", argc=0) - def __p__acmdln(self, emu, argv, ctx={}): + def __p__acmdln(self, emu, argv, ctx: api.ApiContext = None): """Command line global CRT variable""" cmdln = self._acmdln() @@ -98,7 +98,7 @@ def __p__acmdln(self, emu, argv, ctx={}): return cmdln @apihook("_onexit", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _onexit(self, emu, argv, ctx={}): + def _onexit(self, emu, argv, ctx: api.ApiContext = None): """ _onexit_t _onexit( _onexit_t function @@ -109,7 +109,7 @@ def _onexit(self, emu, argv, ctx={}): return func @apihook("mbstowcs_s", argc=5, conv=e_arch.CALL_CONV_CDECL) - def mbstowcs_s(self, emu, argv, ctx={}): + def mbstowcs_s(self, emu, argv, ctx: api.ApiContext = None): """ errno_t mbstowcs_s( size_t *pReturnValue, @@ -156,7 +156,7 @@ def mbstowcs_s(self, emu, argv, ctx={}): return rv @apihook("_wcsnicmp", argc=3, conv=e_arch.CALL_CONV_CDECL) - def _wcsnicmp(self, emu, argv, ctx={}): + def _wcsnicmp(self, emu, argv, ctx: api.ApiContext = None): """ int _wcsnicmp( const wchar_t *string1, @@ -181,7 +181,7 @@ def _wcsnicmp(self, emu, argv, ctx={}): # Reference: https://wiki.osdev.org/Visual_C%2B%2B_Runtime @apihook("_initterm_e", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _initterm_e(self, emu, argv, ctx={}): + def _initterm_e(self, emu, argv, ctx: api.ApiContext = None): """ static int _initterm_e(_PIFV * pfbegin, _PIFV * pfend) @@ -194,7 +194,7 @@ def _initterm_e(self, emu, argv, ctx={}): return rv @apihook("_initterm", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _initterm(self, emu, argv, ctx={}): + def _initterm(self, emu, argv, ctx: api.ApiContext = None): """static void _initterm (_PVFV * pfbegin, _PVFV * pfend)""" pfbegin, pfend = argv @@ -204,7 +204,7 @@ def _initterm(self, emu, argv, ctx={}): return rv @apihook("__getmainargs", argc=5) - def __getmainargs(self, emu, argv, ctx={}): + def __getmainargs(self, emu, argv, ctx: api.ApiContext = None): """ int __getmainargs( int * _Argc, @@ -270,7 +270,7 @@ def __getmainargs(self, emu, argv, ctx={}): return rv @apihook("__wgetmainargs", argc=5) - def __wgetmainargs(self, emu, argv, ctx={}): + def __wgetmainargs(self, emu, argv, ctx: api.ApiContext = None): """ int __wgetmainargs ( int *_Argc, @@ -286,7 +286,7 @@ def __wgetmainargs(self, emu, argv, ctx={}): return rv @apihook("__p___wargv", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __p___wargv(self, emu, argv, ctx={}): + def __p___wargv(self, emu, argv, ctx: api.ApiContext = None): """WCHAR *** __p___wargv ()""" ptr_size = self.get_ptr_size() @@ -317,7 +317,7 @@ def __p___wargv(self, emu, argv, ctx={}): return rv @apihook("__p___argv", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __p___argv(self, emu, argv, ctx={}): + def __p___argv(self, emu, argv, ctx: api.ApiContext = None): """char *** __p___argv ()""" ptr_size = self.get_ptr_size() @@ -348,7 +348,7 @@ def __p___argv(self, emu, argv, ctx={}): return rv @apihook("__p___argc", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __p___argc(self, emu, argv, ctx={}): + def __p___argc(self, emu, argv, ctx: api.ApiContext = None): """int * __p___argc ()""" _argv = emu.get_argv() @@ -358,14 +358,14 @@ def __p___argc(self, emu, argv, ctx={}): return argc @apihook("__p___initenv", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __p___initenv(self, emu, argv, ctx={}): + def __p___initenv(self, emu, argv, ctx: api.ApiContext = None): """char *** __p___initenv ()""" ptr_size = self.get_ptr_size() ptr = self.mem_alloc(size=ptr_size, tag="api.initenv") return ptr @apihook("_get_initial_narrow_environment", argc=0, conv=e_arch.CALL_CONV_CDECL) - def _get_initial_narrow_environment(self, emu, argv, ctx={}): + def _get_initial_narrow_environment(self, emu, argv, ctx: api.ApiContext = None): """char** _get_initial_narrow_environment ()""" ptr_size = self.get_ptr_size() @@ -395,7 +395,7 @@ def _get_initial_narrow_environment(self, emu, argv, ctx={}): return envp @apihook("_get_initial_wide_environment", argc=0, conv=e_arch.CALL_CONV_CDECL) - def _get_initial_wide_environment(self, emu, argv, ctx={}): + def _get_initial_wide_environment(self, emu, argv, ctx: api.ApiContext = None): """WCHAR** _get_initial_wide_environment ()""" ptr_size = self.get_ptr_size() @@ -425,7 +425,7 @@ def _get_initial_wide_environment(self, emu, argv, ctx={}): return envp @apihook("exit", argc=1, conv=e_arch.CALL_CONV_CDECL) - def exit(self, emu, argv, ctx={}): + def exit(self, emu, argv, ctx: api.ApiContext = None): """ void exit( int const status @@ -435,7 +435,7 @@ def exit(self, emu, argv, ctx={}): self.exit_process() @apihook("_exit", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _exit(self, emu, argv, ctx={}): + def _exit(self, emu, argv, ctx: api.ApiContext = None): """ void _exit( int const status @@ -445,7 +445,7 @@ def _exit(self, emu, argv, ctx={}): self.exit_process() @apihook("_XcptFilter", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _XcptFilter(self, emu, argv, ctx={}): + def _XcptFilter(self, emu, argv, ctx: api.ApiContext = None): """ int _XcptFilter( unsigned long xcptnum, @@ -457,7 +457,7 @@ def _XcptFilter(self, emu, argv, ctx={}): return 0 @apihook("_CxxThrowException", argc=2, conv=e_arch.CALL_CONV_STDCALL) - def _CxxThrowException(self, emu, argv, ctx={}): + def _CxxThrowException(self, emu, argv, ctx: api.ApiContext = None): """ void _CxxThrowException( void *pExceptionObject, @@ -467,7 +467,7 @@ def _CxxThrowException(self, emu, argv, ctx={}): return @apihook("__acrt_iob_func", argc=1, conv=e_arch.CALL_CONV_CDECL) - def __acrt_iob_func(self, emu, argv, ctx={}): + def __acrt_iob_func(self, emu, argv, ctx: api.ApiContext = None): """FILE * __acrt_iob_func (fd)""" (fd,) = argv @@ -475,7 +475,7 @@ def __acrt_iob_func(self, emu, argv, ctx={}): return fd @apihook("pow", argc=2, conv=e_arch.CALL_CONV_FLOAT) - def pow(self, emu, argv, ctx={}): + def pow(self, emu, argv, ctx: api.ApiContext = None): """ double pow( double x, @@ -494,7 +494,7 @@ def pow(self, emu, argv, ctx={}): return z @apihook("floor", argc=1, conv=e_arch.CALL_CONV_FLOAT) - def floor(self, emu, argv, ctx={}): + def floor(self, emu, argv, ctx: api.ApiContext = None): """ double floor( double x @@ -509,7 +509,7 @@ def floor(self, emu, argv, ctx={}): return z @apihook("sin", argc=1, conv=e_arch.CALL_CONV_FLOAT) - def sin(self, emu, argv, ctx={}): + def sin(self, emu, argv, ctx: api.ApiContext = None): """ double sin( double x @@ -524,7 +524,7 @@ def sin(self, emu, argv, ctx={}): return z @apihook("abs", argc=1, conv=e_arch.CALL_CONV_CDECL) - def abs(self, emu, argv, ctx={}): + def abs(self, emu, argv, ctx: api.ApiContext = None): """ int abs( int x @@ -535,7 +535,7 @@ def abs(self, emu, argv, ctx={}): return y @apihook("strstr", argc=2, conv=e_arch.CALL_CONV_CDECL) - def strstr(self, emu, argv, ctx={}): + def strstr(self, emu, argv, ctx: api.ApiContext = None): """ char *strstr( const char *str, @@ -561,7 +561,7 @@ def strstr(self, emu, argv, ctx={}): return ret @apihook("wcsstr", argc=2, conv=e_arch.CALL_CONV_CDECL) - def wcsstr(self, emu, argv, ctx={}): + def wcsstr(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcsstr( const wchar_t *str, @@ -587,7 +587,7 @@ def wcsstr(self, emu, argv, ctx={}): return ret @apihook("strncat_s", argc=4, conv=e_arch.CALL_CONV_CDECL) - def strncat_s(self, emu, argv, ctx={}): + def strncat_s(self, emu, argv, ctx: api.ApiContext = None): """ errno_t strncat_s( char *strDest, @@ -625,7 +625,7 @@ def strncat_s(self, emu, argv, ctx={}): return rv @apihook("__stdio_common_vfprintf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def __stdio_common_vfprintf(self, emu, argv, ctx={}): + def __stdio_common_vfprintf(self, emu, argv, ctx: api.ApiContext = None): arch = emu.get_arch() if arch == e_arch.ARCH_AMD64: @@ -647,7 +647,7 @@ def __stdio_common_vfprintf(self, emu, argv, ctx={}): return rv @apihook("fprintf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def fprintf(self, emu, argv, ctx={}): + def fprintf(self, emu, argv, ctx: api.ApiContext = None): """ int fprintf( FILE *stream, @@ -671,7 +671,7 @@ def fprintf(self, emu, argv, ctx={}): return len(fin) @apihook("printf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def printf(self, emu, argv, ctx={}): + def printf(self, emu, argv, ctx: api.ApiContext = None): """ int printf( const char *format, @@ -694,7 +694,7 @@ def printf(self, emu, argv, ctx={}): return len(fin) @apihook("memset", argc=3, conv=e_arch.CALL_CONV_CDECL) - def memset(self, emu, argv, ctx={}): + def memset(self, emu, argv, ctx: api.ApiContext = None): """ void *memset ( void * ptr, int value, @@ -709,7 +709,7 @@ def memset(self, emu, argv, ctx={}): return ptr @apihook("time", argc=1, conv=e_arch.CALL_CONV_CDECL) - def time(self, emu, argv, ctx={}): + def time(self, emu, argv, ctx: api.ApiContext = None): """ time_t time( time_t *destTime ); """ @@ -723,7 +723,7 @@ def time(self, emu, argv, ctx={}): return out_time @apihook("_strtime", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _strtime(self, emu, argv, ctx={}): + def _strtime(self, emu, argv, ctx: api.ApiContext = None): """ char *_strtime(char *buffer); """ @@ -734,7 +734,7 @@ def _strtime(self, emu, argv, ctx={}): return buffer @apihook("_strdate", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _strdate(self, emu, argv, ctx={}): + def _strdate(self, emu, argv, ctx: api.ApiContext = None): """ char *_strdate(char *buffer); """ @@ -745,7 +745,7 @@ def _strdate(self, emu, argv, ctx={}): return buffer @apihook("clock", argc=0, conv=e_arch.CALL_CONV_CDECL) - def clock(self, emu, argv, ctx={}): + def clock(self, emu, argv, ctx: api.ApiContext = None): """ clock_t clock( void ); """ @@ -755,7 +755,7 @@ def clock(self, emu, argv, ctx={}): return self.tick_counter @apihook("srand", argc=1, conv=e_arch.CALL_CONV_CDECL) - def srand(self, emu, argv, ctx={}): + def srand(self, emu, argv, ctx: api.ApiContext = None): """ void srand (unsigned int seed); """ @@ -765,7 +765,7 @@ def srand(self, emu, argv, ctx={}): return @apihook("sprintf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def sprintf(self, emu, argv, ctx={}): + def sprintf(self, emu, argv, ctx: api.ApiContext = None): """ int sprintf( char *buffer, @@ -789,7 +789,7 @@ def sprintf(self, emu, argv, ctx={}): return len(fin) @apihook("_snprintf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def _snprintf(self, emu, argv, ctx={}): + def _snprintf(self, emu, argv, ctx: api.ApiContext = None): """ int _snprintf( char *buffer, @@ -814,7 +814,7 @@ def _snprintf(self, emu, argv, ctx={}): return len(fin) @apihook("atoi", argc=1, conv=e_arch.CALL_CONV_CDECL) - def atoi(self, emu, argv, ctx={}): + def atoi(self, emu, argv, ctx: api.ApiContext = None): """ int atoi( const char *str @@ -834,7 +834,7 @@ def atoi(self, emu, argv, ctx={}): return rv @apihook("rand", argc=0, conv=e_arch.CALL_CONV_CDECL) - def rand(self, emu, argv, ctx={}): + def rand(self, emu, argv, ctx: api.ApiContext = None): """ int rand( void ); """ @@ -844,7 +844,7 @@ def rand(self, emu, argv, ctx={}): return self.rand_int @apihook("__set_app_type", argc=1, conv=e_arch.CALL_CONV_CDECL) - def __set_app_type(self, emu, argv, ctx={}): + def __set_app_type(self, emu, argv, ctx: api.ApiContext = None): """ void __set_app_type ( int at @@ -853,11 +853,11 @@ def __set_app_type(self, emu, argv, ctx={}): return @apihook("_set_app_type", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _set_app_type(self, emu, argv, ctx={}): + def _set_app_type(self, emu, argv, ctx: api.ApiContext = None): return @apihook("__p__fmode", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __p__fmode(self, emu, argv, ctx={}): + def __p__fmode(self, emu, argv, ctx: api.ApiContext = None): """ int* __p__fmode(); """ @@ -869,7 +869,7 @@ def __p__fmode(self, emu, argv, ctx={}): return ptr @apihook("__p__commode", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __p__commode(self, emu, argv, ctx={}): + def __p__commode(self, emu, argv, ctx: api.ApiContext = None): """ int* __p__commode(); """ @@ -881,7 +881,7 @@ def __p__commode(self, emu, argv, ctx={}): return ptr @apihook("_controlfp", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _controlfp(self, emu, argv, ctx={}): + def _controlfp(self, emu, argv, ctx: api.ApiContext = None): """ unsigned int _controlfp(unsigned int new, unsinged int mask) @@ -889,7 +889,7 @@ def _controlfp(self, emu, argv, ctx={}): return 0 @apihook("strcpy", argc=2, conv=e_arch.CALL_CONV_CDECL) - def strcpy(self, emu, argv, ctx={}): + def strcpy(self, emu, argv, ctx: api.ApiContext = None): """ char *strcpy( char *strDestination, @@ -904,7 +904,7 @@ def strcpy(self, emu, argv, ctx={}): return dest @apihook("wcscpy", argc=2, conv=e_arch.CALL_CONV_CDECL) - def wcscpy(self, emu, argv, ctx={}): + def wcscpy(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcscpy( wchar_t *strDestination, @@ -918,7 +918,7 @@ def wcscpy(self, emu, argv, ctx={}): return dest @apihook("strncpy", argc=3, conv=e_arch.CALL_CONV_CDECL) - def strncpy(self, emu, argv, ctx={}): + def strncpy(self, emu, argv, ctx: api.ApiContext = None): """ char * strncpy( char * destination, @@ -935,7 +935,7 @@ def strncpy(self, emu, argv, ctx={}): return dest @apihook("wcsncpy", argc=3, conv=e_arch.CALL_CONV_CDECL) - def wcsncpy(self, emu, argv, ctx={}): + def wcsncpy(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcsncpy( wchar_t *strDest, @@ -952,7 +952,7 @@ def wcsncpy(self, emu, argv, ctx={}): return dest @apihook("memcpy", argc=3, conv=e_arch.CALL_CONV_CDECL) - def memcpy(self, emu, argv, ctx={}): + def memcpy(self, emu, argv, ctx: api.ApiContext = None): """ void *memcpy( void *dest, @@ -966,7 +966,7 @@ def memcpy(self, emu, argv, ctx={}): return dest @apihook("memmove", argc=3, conv=e_arch.CALL_CONV_CDECL) - def memmove(self, emu, argv, ctx={}): + def memmove(self, emu, argv, ctx: api.ApiContext = None): """ void *memmove( void *dest, @@ -980,7 +980,7 @@ def memmove(self, emu, argv, ctx={}): return dest @apihook("memcmp", argc=3, conv=e_arch.CALL_CONV_CDECL) - def memcmp(self, emu, argv, ctx={}): + def memcmp(self, emu, argv, ctx: api.ApiContext = None): """ int memcmp( const void *buffer1, @@ -1003,7 +1003,7 @@ def memcmp(self, emu, argv, ctx={}): return diff @apihook("_except_handler4_common", argc=6, conv=e_arch.CALL_CONV_CDECL) - def _except_handler4_common(self, emu, argv, ctx={}): + def _except_handler4_common(self, emu, argv, ctx: api.ApiContext = None): """ _CRTIMP __C_specific_handler( _In_ struct _EXCEPTION_RECORD *ExceptionRecord, @@ -1072,7 +1072,7 @@ def _except_handler4_common(self, emu, argv, ctx={}): return rv @apihook("_seh_filter_exe", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _seh_filter_exe(self, emu, argv, ctx={}): + def _seh_filter_exe(self, emu, argv, ctx: api.ApiContext = None): """ int __cdecl _seh_filter_exe( unsigned long _ExceptionNum, @@ -1085,7 +1085,7 @@ def _seh_filter_exe(self, emu, argv, ctx={}): return rv @apihook("_except_handler3", argc=4, conv=e_arch.CALL_CONV_CDECL) - def _except_handler3(self, emu, argv, ctx={}): + def _except_handler3(self, emu, argv, ctx: api.ApiContext = None): """ int _except_handler3( PEXCEPTION_RECORD exception_record, @@ -1098,7 +1098,7 @@ def _except_handler3(self, emu, argv, ctx={}): return rv @apihook("_seh_filter_dll", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _seh_filter_dll(self, emu, argv, ctx={}): + def _seh_filter_dll(self, emu, argv, ctx: api.ApiContext = None): """ int __cdecl _seh_filter_dll( unsigned long _ExceptionNum, @@ -1111,7 +1111,7 @@ def _seh_filter_dll(self, emu, argv, ctx={}): return rv @apihook("puts", argc=1, conv=e_arch.CALL_CONV_CDECL) - def puts(self, emu, argv, ctx={}): + def puts(self, emu, argv, ctx: api.ApiContext = None): """ int puts( const char *str @@ -1126,7 +1126,7 @@ def puts(self, emu, argv, ctx={}): return rv @apihook("_initialize_onexit_table", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _initialize_onexit_table(self, emu, argv, ctx={}): + def _initialize_onexit_table(self, emu, argv, ctx: api.ApiContext = None): """ int _initialize_onexit_table( _onexit_table_t* table @@ -1137,7 +1137,7 @@ def _initialize_onexit_table(self, emu, argv, ctx={}): return rv @apihook("_register_onexit_function", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _register_onexit_function(self, emu, argv, ctx={}): + def _register_onexit_function(self, emu, argv, ctx: api.ApiContext = None): """ int _register_onexit_function( _onexit_table_t* table, @@ -1149,7 +1149,7 @@ def _register_onexit_function(self, emu, argv, ctx={}): return rv @apihook("malloc", argc=1, conv=e_arch.CALL_CONV_CDECL) - def malloc(self, emu, argv, ctx={}): + def malloc(self, emu, argv, ctx: api.ApiContext = None): """ void *malloc( size_t size @@ -1161,7 +1161,7 @@ def malloc(self, emu, argv, ctx={}): return chunk @apihook("calloc", argc=2, conv=e_arch.CALL_CONV_CDECL) - def calloc(self, emu, argv, ctx={}): + def calloc(self, emu, argv, ctx: api.ApiContext = None): """ void *calloc( size_t num, @@ -1181,7 +1181,7 @@ def calloc(self, emu, argv, ctx={}): return chunk @apihook("free", argc=1, conv=e_arch.CALL_CONV_CDECL) - def free(self, emu, argv, ctx={}): + def free(self, emu, argv, ctx: api.ApiContext = None): """ void free( void *memblock @@ -1191,7 +1191,7 @@ def free(self, emu, argv, ctx={}): self.mem_free(mem) @apihook("_beginthreadex", argc=6, conv=e_arch.CALL_CONV_CDECL) - def _beginthreadex(self, emu, argv, ctx={}): + def _beginthreadex(self, emu, argv, ctx: api.ApiContext = None): """ uintptr_t _beginthreadex( void *security, @@ -1212,7 +1212,7 @@ def _beginthreadex(self, emu, argv, ctx={}): return handle @apihook("_beginthread", argc=3, conv=e_arch.CALL_CONV_CDECL) - def _beginthread(self, emu, argv, ctx={}): + def _beginthread(self, emu, argv, ctx: api.ApiContext = None): """ uintptr_t _beginthread void( __cdecl *start_address )( void * ), @@ -1226,7 +1226,7 @@ def _beginthread(self, emu, argv, ctx={}): return handle @apihook("system", argc=1, conv=e_arch.CALL_CONV_CDECL) - def system(self, emu, argv, ctx={}): + def system(self, emu, argv, ctx: api.ApiContext = None): """ int system( const char *command @@ -1241,7 +1241,7 @@ def system(self, emu, argv, ctx={}): return rv @apihook("toupper", argc=1, conv=e_arch.CALL_CONV_CDECL) - def toupper(self, emu, argv, ctx={}): + def toupper(self, emu, argv, ctx: api.ApiContext = None): """ int toupper( int c @@ -1256,7 +1256,7 @@ def toupper(self, emu, argv, ctx={}): return c @apihook("strlen", argc=1, conv=e_arch.CALL_CONV_CDECL) - def strlen(self, emu, argv, ctx={}): + def strlen(self, emu, argv, ctx: api.ApiContext = None): """ size_t strlen( const char *str @@ -1271,7 +1271,7 @@ def strlen(self, emu, argv, ctx={}): return rv @apihook("strcat", argc=2, conv=e_arch.CALL_CONV_CDECL) - def strcat(self, emu, argv, ctx={}): + def strcat(self, emu, argv, ctx: api.ApiContext = None): """ char *strcat( char *strDestination, @@ -1288,7 +1288,7 @@ def strcat(self, emu, argv, ctx={}): return _str1 @apihook("_strlwr", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _strlwr(self, emu, argv, ctx={}): + def _strlwr(self, emu, argv, ctx: api.ApiContext = None): """ char *_strlwr( char *str @@ -1305,7 +1305,7 @@ def _strlwr(self, emu, argv, ctx={}): return string_ptr @apihook("strncat", argc=3, conv=e_arch.CALL_CONV_CDECL) - def strncat(self, emu, argv, ctx={}): + def strncat(self, emu, argv, ctx: api.ApiContext = None): """ char *strncat( char *destination, @@ -1323,7 +1323,7 @@ def strncat(self, emu, argv, ctx={}): return dest @apihook("wcscat", argc=2, conv=e_arch.CALL_CONV_CDECL) - def wcscat(self, emu, argv, ctx={}): + def wcscat(self, emu, argv, ctx: api.ApiContext = None): """ wchar_t *wcscat( wchar_t *strDestination, @@ -1340,7 +1340,7 @@ def wcscat(self, emu, argv, ctx={}): return _str1 @apihook("wcslen", argc=1, conv=e_arch.CALL_CONV_CDECL) - def wcslen(self, emu, argv, ctx={}): + def wcslen(self, emu, argv, ctx: api.ApiContext = None): """ size_t wcslen( const wchar_t* wcs @@ -1354,7 +1354,7 @@ def wcslen(self, emu, argv, ctx={}): return rv @apihook("_lock", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _lock(self, emu, argv, ctx={}): + def _lock(self, emu, argv, ctx: api.ApiContext = None): """ void __cdecl _lock int locknum @@ -1363,7 +1363,7 @@ def _lock(self, emu, argv, ctx={}): return @apihook("_unlock", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _unlock(self, emu, argv, ctx={}): + def _unlock(self, emu, argv, ctx: api.ApiContext = None): """ void __cdecl _unlock int locknum @@ -1372,7 +1372,7 @@ def _unlock(self, emu, argv, ctx={}): return @apihook("_ltoa", argc=3, conv=e_arch.CALL_CONV_CDECL) - def _ltoa(self, emu, argv, ctx={}): + def _ltoa(self, emu, argv, ctx: api.ApiContext = None): """ char *_ltoa( long value, @@ -1391,7 +1391,7 @@ def _ltoa(self, emu, argv, ctx={}): return @apihook("__dllonexit", argc=3, conv=e_arch.CALL_CONV_CDECL) - def __dllonexit(self, emu, argv, ctx={}): + def __dllonexit(self, emu, argv, ctx: api.ApiContext = None): """ onexit_t __dllonexit( _onexit_t func, @@ -1407,7 +1407,7 @@ def __dllonexit(self, emu, argv, ctx={}): return func @apihook("strncmp", argc=3, conv=e_arch.CALL_CONV_CDECL) - def strncmp(self, emu, argv, ctx={}): + def strncmp(self, emu, argv, ctx: api.ApiContext = None): """ int strncmp( const char *string1, @@ -1428,7 +1428,7 @@ def strncmp(self, emu, argv, ctx={}): return rv @apihook("strcmp", argc=2, conv=e_arch.CALL_CONV_CDECL) - def strcmp(self, emu, argv, ctx={}): + def strcmp(self, emu, argv, ctx: api.ApiContext = None): """ int strcmp( const char *string1, @@ -1448,7 +1448,7 @@ def strcmp(self, emu, argv, ctx={}): return rv @apihook("strrchr", argc=2, conv=e_arch.CALL_CONV_CDECL) - def strrchr(self, emu, argv, ctx={}): + def strrchr(self, emu, argv, ctx: api.ApiContext = None): """ char *strrchr( const char *str, @@ -1472,7 +1472,7 @@ def strrchr(self, emu, argv, ctx={}): return rv @apihook("_ftol", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _ftol(self, emu, argv, ctx={}): + def _ftol(self, emu, argv, ctx: api.ApiContext = None): """ int _ftol(int); """ @@ -1480,14 +1480,14 @@ def _ftol(self, emu, argv, ctx={}): return int(f) @apihook("_adjust_fdiv", argc=0, conv=e_arch.CALL_CONV_CDECL) - def _adjust_fdiv(self, emu, argv, ctx={}): + def _adjust_fdiv(self, emu, argv, ctx: api.ApiContext = None): """ void _adjust_fdiv(void) """ return @apihook("tolower", argc=1, conv=e_arch.CALL_CONV_CDECL) - def tolower(self, emu, argv, ctx={}): + def tolower(self, emu, argv, ctx: api.ApiContext = None): """ int tolower ( int c ); """ @@ -1495,7 +1495,7 @@ def tolower(self, emu, argv, ctx={}): return c | 0x20 @apihook("isdigit", argc=1, conv=e_arch.CALL_CONV_CDECL) - def isdigit(self, emu, argv, ctx={}): + def isdigit(self, emu, argv, ctx: api.ApiContext = None): """ int isdigit( int c @@ -1505,14 +1505,14 @@ def isdigit(self, emu, argv, ctx={}): return int(48 <= c <= 57) @apihook("sscanf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def sscanf(self, emu, argv, ctx={}): + def sscanf(self, emu, argv, ctx: api.ApiContext = None): """ int sscanf ( const char * s, const char * format, ...); """ return @apihook("strchr", argc=2, conv=e_arch.CALL_CONV_CDECL) - def strchr(self, emu, argv, ctx={}): + def strchr(self, emu, argv, ctx: api.ApiContext = None): """ char *strchr( const char *str, @@ -1536,7 +1536,7 @@ def strchr(self, emu, argv, ctx={}): return rv @apihook("_set_invalid_parameter_handler", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _set_invalid_parameter_handler(self, emu, argv, ctx={}): + def _set_invalid_parameter_handler(self, emu, argv, ctx: api.ApiContext = None): """ _invalid_parameter_handler _set_invalid_parameter_handler( _invalid_parameter_handler pNew @@ -1547,7 +1547,7 @@ def _set_invalid_parameter_handler(self, emu, argv, ctx={}): return 0 @apihook("__CxxFrameHandler", argc=4, conv=e_arch.CALL_CONV_CDECL) - def __CxxFrameHandler(self, emu, argv, ctx={}): + def __CxxFrameHandler(self, emu, argv, ctx: api.ApiContext = None): """ EXCEPTION_DISPOSITION __CxxFrameHandler( EHExceptionRecord *pExcept, @@ -1565,7 +1565,7 @@ def __CxxFrameHandler(self, emu, argv, ctx={}): return 0 @apihook("_vsnprintf", argc=4, conv=e_arch.CALL_CONV_CDECL) - def _vsnprintf(self, emu, argv, ctx={}): + def _vsnprintf(self, emu, argv, ctx: api.ApiContext = None): """ int _vsnprintf( char *buffer, @@ -1593,7 +1593,7 @@ def _vsnprintf(self, emu, argv, ctx={}): return rv @apihook("__stdio_common_vsprintf", argc=7, conv=e_arch.CALL_CONV_CDECL) - def __stdio_common_vsprintf(self, emu, argv, ctx={}): + def __stdio_common_vsprintf(self, emu, argv, ctx: api.ApiContext = None): """ int __stdio_common_vsprintf( unsigned int64 Options, @@ -1622,7 +1622,7 @@ def __stdio_common_vsprintf(self, emu, argv, ctx={}): return rv @apihook("_strcmpi", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _strcmpi(self, emu, argv, ctx={}): + def _strcmpi(self, emu, argv, ctx: api.ApiContext = None): """ int _strcmpi( const char *string1, @@ -1647,7 +1647,7 @@ def _strcmpi(self, emu, argv, ctx={}): return rv @apihook("_wcsicmp", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _wcsicmp(self, emu, argv, ctx={}): + def _wcsicmp(self, emu, argv, ctx: api.ApiContext = None): """ int _wcsicmp( const wchar_t *string1, @@ -1672,94 +1672,94 @@ def _wcsicmp(self, emu, argv, ctx={}): return rv @apihook("??3@YAXPAX@Z", argc=1, conv=e_arch.CALL_CONV_CDECL) - def __3_YAXPAX_Z(self, emu, argv, ctx={}): + def __3_YAXPAX_Z(self, emu, argv, ctx: api.ApiContext = None): (ptr,) = argv if ptr: self.mem_free(ptr) return @apihook("??2@YAPAXI@Z", argc=1, conv=e_arch.CALL_CONV_CDECL) - def __2_YAPAXI_Z(self, emu, argv, ctx={}): + def __2_YAPAXI_Z(self, emu, argv, ctx: api.ApiContext = None): (size,) = argv if size <= 0: size = self.get_ptr_size() return self.mem_alloc(size, tag="api.msvcrt.operator_new") @apihook("__current_exception_context", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __current_exception_context(self, emu, argv, ctx={}): + def __current_exception_context(self, emu, argv, ctx: api.ApiContext = None): return @apihook("__current_exception", argc=0, conv=e_arch.CALL_CONV_CDECL) - def __current_exception(self, emu, argv, ctx={}): + def __current_exception(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_set_new_mode", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _set_new_mode(self, emu, argv, ctx={}): + def _set_new_mode(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_configthreadlocale", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _configthreadlocale(self, emu, argv, ctx={}): + def _configthreadlocale(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_setusermatherr", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _setusermatherr(self, emu, argv, ctx={}): + def _setusermatherr(self, emu, argv, ctx: api.ApiContext = None): return @apihook("__setusermatherr", argc=1, conv=e_arch.CALL_CONV_CDECL) - def __setusermatherr(self, emu, argv, ctx={}): + def __setusermatherr(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_cexit", argc=0, conv=e_arch.CALL_CONV_CDECL) - def _cexit(self, emu, argv, ctx={}): + def _cexit(self, emu, argv, ctx: api.ApiContext = None): # TODO: handle atexit flavor functions self.exit_process() @apihook("_c_exit", argc=0, conv=e_arch.CALL_CONV_CDECL) - def _c_exit(self, emu, argv, ctx={}): + def _c_exit(self, emu, argv, ctx: api.ApiContext = None): self.exit_process() @apihook("_register_thread_local_exe_atexit_callback", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _register_thread_local_exe_atexit_callback(self, emu, argv, ctx={}): + def _register_thread_local_exe_atexit_callback(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_crt_atexit", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _crt_atexit(self, emu, argv, ctx={}): + def _crt_atexit(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_controlfp_s", argc=3, conv=e_arch.CALL_CONV_CDECL) - def _controlfp_s(self, emu, argv, ctx={}): + def _controlfp_s(self, emu, argv, ctx: api.ApiContext = None): return @apihook("terminate", argc=1, conv=e_arch.CALL_CONV_CDECL) - def terminate(self, emu, argv, ctx={}): + def terminate(self, emu, argv, ctx: api.ApiContext = None): self.exit_process() @apihook("_crt_atexit", argc=1, conv=e_arch.CALL_CONV_CDECL) # type: ignore[no-redef] - def _crt_atexit(self, emu, argv, ctx={}): + def _crt_atexit(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_initialize_narrow_environment", argc=0, conv=e_arch.CALL_CONV_CDECL) - def _initialize_narrow_environment(self, emu, argv, ctx={}): + def _initialize_narrow_environment(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_configure_narrow_argv", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _configure_narrow_argv(self, emu, argv, ctx={}): + def _configure_narrow_argv(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_set_fmode", argc=1, conv=e_arch.CALL_CONV_CDECL) - def _set_fmode(self, emu, argv, ctx={}): + def _set_fmode(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_itoa", argc=3, conv=e_arch.CALL_CONV_CDECL) - def _itoa(self, emu, argv, ctx={}): + def _itoa(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_itow", argc=3, conv=e_arch.CALL_CONV_CDECL) - def _itow(self, emu, argv, ctx={}): + def _itow(self, emu, argv, ctx: api.ApiContext = None): return @apihook("_EH_prolog", argc=0, conv=e_arch.CALL_CONV_CDECL) - def _EH_prolog(self, emu, argv, ctx={}): + def _EH_prolog(self, emu, argv, ctx: api.ApiContext = None): # push -1 emu.push_stack(0xFFFFFFFF) @@ -1788,7 +1788,7 @@ def _EH_prolog(self, emu, argv, ctx={}): return @apihook("wcstombs", argc=3, conv=e_arch.CALL_CONV_CDECL) - def wcstombs(self, emu, argv, ctx={}): + def wcstombs(self, emu, argv, ctx: api.ApiContext = None): """ size_t wcstombs( char *mbstr, @@ -1803,7 +1803,7 @@ def wcstombs(self, emu, argv, ctx={}): return len(s.encode("ascii")) @apihook("_stricmp", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _stricmp(self, emu, argv, ctx={}): + def _stricmp(self, emu, argv, ctx: api.ApiContext = None): """ int _stricmp( const char *string1, @@ -1828,7 +1828,7 @@ def _stricmp(self, emu, argv, ctx={}): return rv @apihook("_strnicmp", argc=3, conv=e_arch.CALL_CONV_CDECL) - def _strnicmp(self, emu, argv, ctx={}): + def _strnicmp(self, emu, argv, ctx: api.ApiContext = None): """ int _strnicmp( const char *string1, @@ -1854,7 +1854,7 @@ def _strnicmp(self, emu, argv, ctx={}): return rv @apihook("_wcsicmp", argc=2, conv=e_arch.CALL_CONV_CDECL) # type: ignore[no-redef] - def _wcsicmp(self, emu, argv, ctx={}): + def _wcsicmp(self, emu, argv, ctx: api.ApiContext = None): """ int wcsicmp( const wchar_t *string1, @@ -1876,7 +1876,7 @@ def _wcsicmp(self, emu, argv, ctx={}): return rv @apihook("wcscmp", argc=2, conv=e_arch.CALL_CONV_CDECL) - def wcscmp(self, emu, argv, ctx={}): + def wcscmp(self, emu, argv, ctx: api.ApiContext = None): """ int wcscmp( const wchar_t *string1, @@ -1896,7 +1896,7 @@ def wcscmp(self, emu, argv, ctx={}): return rv @apihook("_snwprintf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def _snwprintf(self, emu, argv, ctx={}): + def _snwprintf(self, emu, argv, ctx: api.ApiContext = None): """ int _snwprintf( wchar_t *buffer, @@ -1925,7 +1925,7 @@ def _snwprintf(self, emu, argv, ctx={}): return len(fin) @apihook("_errno", argc=0) - def _errno(self, emu, argv, ctx={}): + def _errno(self, emu, argv, ctx: api.ApiContext = None): """ """ _VAL = 0x0C @@ -1936,7 +1936,7 @@ def _errno(self, emu, argv, ctx={}): return self.errno_t @apihook("fopen", argc=2, conv=e_arch.CALL_CONV_CDECL) - def fopen(self, emu, argv, ctx={}): + def fopen(self, emu, argv, ctx: api.ApiContext = None): """ FILE *fopen( const char *filename, @@ -1967,7 +1967,7 @@ def fopen(self, emu, argv, ctx={}): return stream @apihook("_wfopen", argc=2, conv=e_arch.CALL_CONV_CDECL) - def _wfopen(self, emu, argv, ctx={}): + def _wfopen(self, emu, argv, ctx: api.ApiContext = None): """ FILE *_wfopen( const wchar_t *filename, @@ -1998,7 +1998,7 @@ def _wfopen(self, emu, argv, ctx={}): return stream @apihook("fclose", argc=1, conv=e_arch.CALL_CONV_CDECL) - def fclose(self, emu, argv, ctx={}): + def fclose(self, emu, argv, ctx: api.ApiContext = None): """ int fclose( FILE *stream @@ -2014,7 +2014,7 @@ def fclose(self, emu, argv, ctx={}): return 0 @apihook("fseek", argc=3, conv=e_arch.CALL_CONV_CDECL) - def fseek(self, emu, argv, ctx={}): + def fseek(self, emu, argv, ctx: api.ApiContext = None): """ int fseek( FILE *stream, @@ -2038,7 +2038,7 @@ def fseek(self, emu, argv, ctx={}): return 0 @apihook("ftell", argc=1, conv=e_arch.CALL_CONV_CDECL) - def ftell(self, emu, argv, ctx={}): + def ftell(self, emu, argv, ctx: api.ApiContext = None): """ long ftell( FILE *stream @@ -2060,7 +2060,7 @@ def ftell(self, emu, argv, ctx={}): return pos @apihook("fread", argc=4, conv=e_arch.CALL_CONV_CDECL) - def fread(self, emu, argv, ctx={}): + def fread(self, emu, argv, ctx: api.ApiContext = None): """ size_t fread( void *ptr, @@ -2089,7 +2089,7 @@ def fread(self, emu, argv, ctx={}): return len(data) // size @apihook("fputc", argc=2) - def fputc(self, emu, argv, ctx={}): + def fputc(self, emu, argv, ctx: api.ApiContext = None): """ int fputc( int c, @@ -2100,7 +2100,7 @@ def fputc(self, emu, argv, ctx={}): return c @apihook("signal", argc=2) - def signal(self, emu, argv, ctx={}): + def signal(self, emu, argv, ctx: api.ApiContext = None): """ void __cdecl *signal( int sig, diff --git a/speakeasy/winenv/api/usermode/msvfw32.py b/speakeasy/winenv/api/usermode/msvfw32.py index 2182d3c4..0d4433b7 100644 --- a/speakeasy/winenv/api/usermode/msvfw32.py +++ b/speakeasy/winenv/api/usermode/msvfw32.py @@ -21,7 +21,7 @@ def get_handle(self): return handle @apihook("ICOpen", argc=3) - def ICOpen(self, emu, argv, ctx={}): + def ICOpen(self, emu, argv, ctx: api.ApiContext = None): """ HIC ICOpen( DWORD fccType, @@ -33,7 +33,7 @@ def ICOpen(self, emu, argv, ctx={}): return self.get_handle() @apihook("ICSendMessage", argc=4) - def ICSendMessage(self, emu, argv, ctx={}): + def ICSendMessage(self, emu, argv, ctx: api.ApiContext = None): """ LRESULT ICSendMessage( HIC hic, @@ -46,7 +46,7 @@ def ICSendMessage(self, emu, argv, ctx={}): return 1 @apihook("ICClose", argc=1) - def ICClose(self, emu, argv, ctx={}): + def ICClose(self, emu, argv, ctx: api.ApiContext = None): """ LRESULT ICClose( HIC hic diff --git a/speakeasy/winenv/api/usermode/ncrypt.py b/speakeasy/winenv/api/usermode/ncrypt.py index 9d760d4d..1023424c 100644 --- a/speakeasy/winenv/api/usermode/ncrypt.py +++ b/speakeasy/winenv/api/usermode/ncrypt.py @@ -26,7 +26,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("NCryptOpenStorageProvider", argc=3) - def NCryptOpenStorageProvider(self, emu, argv, ctx={}): + def NCryptOpenStorageProvider(self, emu, argv, ctx: api.ApiContext = None): """ SECURITY_STATUS NCryptOpenStorageProvider( NCRYPT_PROV_HANDLE *phProvider, @@ -47,7 +47,7 @@ def NCryptOpenStorageProvider(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("NCryptImportKey", argc=8) - def NCryptImportKey(self, emu, argv, ctx={}): + def NCryptImportKey(self, emu, argv, ctx: api.ApiContext = None): """ SECURITY_STATUS NCryptImportKey( NCRYPT_PROV_HANDLE hProvider, @@ -60,6 +60,7 @@ def NCryptImportKey(self, emu, argv, ctx={}): DWORD dwFlags ); """ + ctx = ctx or {} hProvider, hImportKey, pszBlobType, pParameterList, phKey, pbData, cbData, dwFlags = argv blob_type = self.read_wide_string(pszBlobType) argv[2] = blob_type @@ -84,13 +85,14 @@ def NCryptImportKey(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("NCryptDeleteKey", argc=2) - def NCryptDeleteKey(self, emu, argv, ctx={}): + def NCryptDeleteKey(self, emu, argv, ctx: api.ApiContext = None): """ SECURITY_STATUS NCryptDeleteKey( NCRYPT_KEY_HANDLE hKey, DWORD dwFlags ); """ + ctx = ctx or {} hKey, dwFlags = argv cm = emu.get_crypt_manager() for hnd, ctx in cm.ctx_handles.items(): @@ -102,12 +104,13 @@ def NCryptDeleteKey(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("NCryptFreeObject", argc=1) - def NCryptFreeObject(self, emu, argv, ctx={}): + def NCryptFreeObject(self, emu, argv, ctx: api.ApiContext = None): """ SECURITY_STATUS NCryptFreeObject( NCRYPT_HANDLE hObject ); """ + ctx = ctx or {} hObject = argv[0] cm = emu.get_crypt_manager() diff --git a/speakeasy/winenv/api/usermode/netapi32.py b/speakeasy/winenv/api/usermode/netapi32.py index f58196df..329e4fd5 100644 --- a/speakeasy/winenv/api/usermode/netapi32.py +++ b/speakeasy/winenv/api/usermode/netapi32.py @@ -20,7 +20,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("NetGetJoinInformation", argc=3) - def NetGetJoinInformation(self, emu, argv, ctx={}): + def NetGetJoinInformation(self, emu, argv, ctx: api.ApiContext = None): """ NET_API_STATUS NET_API_FUNCTION NetGetJoinInformation( LPCWSTR lpServer, @@ -47,7 +47,7 @@ def NetGetJoinInformation(self, emu, argv, ctx={}): return netapi32defs.NERR_Success @apihook("NetWkstaGetInfo", argc=3) - def NetWkstaGetInfo(self, emu, argv, ctx={}): + def NetWkstaGetInfo(self, emu, argv, ctx: api.ApiContext = None): """ NET_API_STATUS NET_API_FUNCTION NetWkstaGetInfo( LMSTR servername, @@ -125,7 +125,7 @@ def NetUserAdd(self, emu, argv, ctx={}): return netapi32defs.NERR_Success @apihook("NetApiBufferFree", argc=1) - def NetApiBufferFree(self, emu, argv, ctx={}): + def NetApiBufferFree(self, emu, argv, ctx: api.ApiContext = None): """ NET_API_STATUS NET_API_FUNCTION NetApiBufferFree( _Frees_ptr_opt_ LPVOID Buffer diff --git a/speakeasy/winenv/api/usermode/netutils.py b/speakeasy/winenv/api/usermode/netutils.py index 1bd15748..792c48bb 100644 --- a/speakeasy/winenv/api/usermode/netutils.py +++ b/speakeasy/winenv/api/usermode/netutils.py @@ -16,7 +16,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("NetApiBufferFree", argc=1) - def NetApiBufferFree(self, emu, argv, ctx={}): + def NetApiBufferFree(self, emu, argv, ctx: api.ApiContext = None): """ NET_API_STATUS NET_API_FUNCTION NetApiBufferFree( _Frees_ptr_opt_ LPVOID Buffer diff --git a/speakeasy/winenv/api/usermode/ntdll.py b/speakeasy/winenv/api/usermode/ntdll.py index 6db37813..e0b5f024 100644 --- a/speakeasy/winenv/api/usermode/ntdll.py +++ b/speakeasy/winenv/api/usermode/ntdll.py @@ -31,23 +31,23 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("RtlGetLastWin32Error", argc=0) - def RtlGetLastWin32Error(self, emu, argv, ctx={}): + def RtlGetLastWin32Error(self, emu, argv, ctx: api.ApiContext = None): """DWORD RtlGetLastWin32Error();""" return emu.get_last_error() @apihook("RtlNtStatusToDosError", argc=1) - def RtlNtStatusToDosError(self, emu, argv, ctx={}): + def RtlNtStatusToDosError(self, emu, argv, ctx: api.ApiContext = None): """ULONG RtlNtStatusToDosError(NTSTATUS Status);""" return 0 @apihook("RtlFlushSecureMemoryCache", argc=2) - def RtlFlushSecureMemoryCache(self, emu, argv, ctx={}): + def RtlFlushSecureMemoryCache(self, emu, argv, ctx: api.ApiContext = None): """DWORD RtlFlushSecureMemoryCache(PVOID arg0, PVOID arg1);""" return True @apihook("RtlAddVectoredExceptionHandler", argc=2) - def RtlAddVectoredExceptionHandler(self, emu, argv, ctx={}): + def RtlAddVectoredExceptionHandler(self, emu, argv, ctx: api.ApiContext = None): """ PVOID AddVectoredExceptionHandler( ULONG First, @@ -61,14 +61,14 @@ def RtlAddVectoredExceptionHandler(self, emu, argv, ctx={}): return Handler @apihook("NtYieldExecution", argc=0) - def NtYieldExecution(self, emu, argv, ctx={}): + def NtYieldExecution(self, emu, argv, ctx: api.ApiContext = None): """ NtYieldExecution(); """ return 0 @apihook("RtlRemoveVectoredExceptionHandler", argc=1) - def RtlRemoveVectoredExceptionHandler(self, emu, argv, ctx={}): + def RtlRemoveVectoredExceptionHandler(self, emu, argv, ctx: api.ApiContext = None): """ ULONG RemoveVectoredExceptionHandler( PVOID Handle @@ -81,7 +81,7 @@ def RtlRemoveVectoredExceptionHandler(self, emu, argv, ctx={}): return Handler @apihook("LdrLoadDll", argc=4) - def LdrLoadDll(self, emu, argv, ctx={}): + def LdrLoadDll(self, emu, argv, ctx: api.ApiContext = None): """NTSTATUS NTAPI LdrLoadDll( @@ -132,7 +132,7 @@ def LdrLoadDll(self, emu, argv, ctx={}): return 0 @apihook("LdrGetProcedureAddress", argc=4) - def LdrGetProcedureAddress(self, emu, argv, ctx={}): + def LdrGetProcedureAddress(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS LdrGetProcedureAddress( HMODULE ModuleHandle, @@ -167,7 +167,7 @@ def LdrGetProcedureAddress(self, emu, argv, ctx={}): return rv @apihook("RtlZeroMemory", argc=2) - def RtlZeroMemory(self, emu, argv, ctx={}): + def RtlZeroMemory(self, emu, argv, ctx: api.ApiContext = None): """ void RtlZeroMemory( void* Destination, @@ -179,7 +179,7 @@ def RtlZeroMemory(self, emu, argv, ctx={}): self.mem_write(dest, buf) @apihook("RtlMoveMemory", argc=3) - def RtlMoveMemory(self, emu, argv, ctx={}): + def RtlMoveMemory(self, emu, argv, ctx: api.ApiContext = None): """ void RtlMoveMemory(void* pvDest, const void *pSrc, size_t Length); """ @@ -188,7 +188,7 @@ def RtlMoveMemory(self, emu, argv, ctx={}): self.mem_write(dest, buf) @apihook("NtSetInformationProcess", argc=4) - def NtSetInformationProcess(self, emu, argv, ctx={}): + def NtSetInformationProcess(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS NTAPI @@ -202,7 +202,7 @@ def NtSetInformationProcess(self, emu, argv, ctx={}): return 0 @apihook("RtlEncodePointer", argc=1) - def RtlEncodePointer(self, emu, argv, ctx={}): + def RtlEncodePointer(self, emu, argv, ctx: api.ApiContext = None): """ PVOID NTAPI @@ -215,7 +215,7 @@ def RtlEncodePointer(self, emu, argv, ctx={}): return rv @apihook("RtlDecodePointer", argc=1) - def RtlDecodePointer(self, emu, argv, ctx={}): + def RtlDecodePointer(self, emu, argv, ctx: api.ApiContext = None): """ PVOID NTAPI @@ -228,7 +228,7 @@ def RtlDecodePointer(self, emu, argv, ctx={}): return rv @apihook("NtWaitForSingleObject", argc=3) - def NtWaitForSingleObject(self, emu, argv, ctx={}): + def NtWaitForSingleObject(self, emu, argv, ctx: api.ApiContext = None): """ NTSYSAPI NTSTATUS @@ -251,7 +251,7 @@ def NtWaitForSingleObject(self, emu, argv, ctx={}): return rv @apihook("RtlComputeCrc32", argc=3) - def RtlComputeCrc32(self, emu, argv, ctx={}): + def RtlComputeCrc32(self, emu, argv, ctx: api.ApiContext = None): """ DWORD RtlComputeCrc32( DWORD dwInitial, @@ -267,7 +267,7 @@ def RtlComputeCrc32(self, emu, argv, ctx={}): return dwInitial @apihook("LdrFindResource_U", argc=4) - def LdrFindResource_U(self, emu, argv, ctx={}): + def LdrFindResource_U(self, emu, argv, ctx: api.ApiContext = None): """ pub unsafe extern "system" fn LdrFindResource_U( DllHandle: PVOID, @@ -328,7 +328,7 @@ def LdrFindResource_U(self, emu, argv, ctx={}): return ddk.STATUS_SUCCESS @apihook("NtUnmapViewOfSection", argc=2) - def NtUnmapViewOfSection(self, emu, argv, ctx={}): + def NtUnmapViewOfSection(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS NtUnmapViewOfSection( HANDLE ProcessHandle, @@ -338,7 +338,7 @@ def NtUnmapViewOfSection(self, emu, argv, ctx={}): return ddk.STATUS_SUCCESS @apihook("LdrAccessResource", argc=4) - def LdrAccessResource(self, emu, argv, ctx={}): + def LdrAccessResource(self, emu, argv, ctx: api.ApiContext = None): """ NTSTATUS NTAPI LdrAccessResource ( _In_ PVOID BaseAddress, _In_ PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry, diff --git a/speakeasy/winenv/api/usermode/ole32.py b/speakeasy/winenv/api/usermode/ole32.py index 5d930887..e6d492fb 100644 --- a/speakeasy/winenv/api/usermode/ole32.py +++ b/speakeasy/winenv/api/usermode/ole32.py @@ -25,7 +25,7 @@ def __init__(self, emu): self.names = {} @apihook("OleInitialize", argc=1) - def OleInitialize(self, emu, argv, ctx={}): + def OleInitialize(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT OleInitialize( IN LPVOID pvReserved @@ -37,7 +37,7 @@ def OleInitialize(self, emu, argv, ctx={}): return rv @apihook("CoInitialize", argc=1) - def CoInitialize(self, emu, argv, ctx={}): + def CoInitialize(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT CoInitialize( LPVOID pvReserved @@ -49,7 +49,7 @@ def CoInitialize(self, emu, argv, ctx={}): return rv @apihook("CoInitializeEx", argc=2) - def CoInitializeEx(self, emu, argv, ctx={}): + def CoInitializeEx(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT CoInitializeEx( LPVOID pvReserved, @@ -62,13 +62,13 @@ def CoInitializeEx(self, emu, argv, ctx={}): return rv @apihook("CoUninitialize", argc=0) - def CoUninitialize(self, emu, argv, ctx={}): + def CoUninitialize(self, emu, argv, ctx: api.ApiContext = None): """ void CoUninitialize(); """ @apihook("CoInitializeSecurity", argc=9) - def CoInitializeSecurity(self, emu, argv, ctx={}): + def CoInitializeSecurity(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT CoInitializeSecurity( PSECURITY_DESCRIPTOR pSecDesc, @@ -96,7 +96,7 @@ def CoInitializeSecurity(self, emu, argv, ctx={}): return rv @apihook("CoCreateInstance", argc=5) - def CoCreateInstance(self, emu, argv, ctx={}): + def CoCreateInstance(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT CoCreateInstance( REFCLSID rclsid, @@ -132,7 +132,7 @@ def CoCreateInstance(self, emu, argv, ctx={}): return rv @apihook("CoSetProxyBlanket", argc=8) - def CoSetProxyBlanket(self, emu, argv, ctx={}): + def CoSetProxyBlanket(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT CoSetProxyBlanket( IUnknown *pProxy, @@ -148,7 +148,7 @@ def CoSetProxyBlanket(self, emu, argv, ctx={}): return 1 @apihook("StringFromCLSID", argc=2) - def StringFromCLSID(self, emu, argv, ctx={}): + def StringFromCLSID(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT StringFromCLSID( REFCLSID rclsid, @@ -172,7 +172,7 @@ def StringFromCLSID(self, emu, argv, ctx={}): return rv @apihook("CoCreateGuid", argc=1) - def CoCreateGuid(self, emu, argv, ctx={}): + def CoCreateGuid(self, emu, argv, ctx: api.ApiContext = None): pguid = argv[0] guid_bytes = b"\xde\xad\xc0\xde\xbe\xef\xca\xfe\xba\xbe\x01\x23\x45\x67\x89\xab" if pguid: diff --git a/speakeasy/winenv/api/usermode/oleaut32.py b/speakeasy/winenv/api/usermode/oleaut32.py index 6596b9da..95b3e5b5 100644 --- a/speakeasy/winenv/api/usermode/oleaut32.py +++ b/speakeasy/winenv/api/usermode/oleaut32.py @@ -16,7 +16,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("SysAllocString", argc=1, ordinal=2) - def SysAllocString(self, emu, argv, ctx={}): + def SysAllocString(self, emu, argv, ctx: api.ApiContext = None): """ BSTR SysAllocString( const OLECHAR *psz @@ -42,7 +42,7 @@ def SysAllocString(self, emu, argv, ctx={}): return 0 @apihook("SysAllocStringLen", argc=2, ordinal=4) - def SysAllocStringLen(self, emu, argv, ctx={}): + def SysAllocStringLen(self, emu, argv, ctx: api.ApiContext = None): """ BSTR SysAllocStringLen( [in] const OLECHAR *strIn, @@ -72,7 +72,7 @@ def SysAllocStringLen(self, emu, argv, ctx={}): return bstr + 4 @apihook("SysFreeString", argc=1, ordinal=6) - def SysFreeString(self, emu, argv, ctx={}): + def SysFreeString(self, emu, argv, ctx: api.ApiContext = None): """ void SysFreeString( BSTR bstrString @@ -82,7 +82,7 @@ def SysFreeString(self, emu, argv, ctx={}): return @apihook("VariantInit", argc=1, ordinal=8) - def VariantInit(self, emu, argv, ctx={}): + def VariantInit(self, emu, argv, ctx: api.ApiContext = None): """ void VariantInit( VARIANTARG *pvarg diff --git a/speakeasy/winenv/api/usermode/psapi.py b/speakeasy/winenv/api/usermode/psapi.py index 25ae90c4..76099164 100644 --- a/speakeasy/winenv/api/usermode/psapi.py +++ b/speakeasy/winenv/api/usermode/psapi.py @@ -53,7 +53,7 @@ def _get_module_file_name(self, proc, hModule): return proc.path or "" @apihook("EnumProcesses", argc=3) - def EnumProcesses(self, emu, argv, ctx={}): + def EnumProcesses(self, emu, argv, ctx: api.ApiContext = None): lpidProcess, cb, lpcbNeeded = argv processes = emu.get_processes() @@ -73,7 +73,7 @@ def EnumProcesses(self, emu, argv, ctx={}): return 1 @apihook("EnumProcessModules", argc=4) - def EnumProcessModules(self, emu, argv, ctx={}): + def EnumProcessModules(self, emu, argv, ctx: api.ApiContext = None): hProcess, lphModule, cb, lpcbNeeded = argv proc = self.get_object_from_handle(hProcess) if not proc: @@ -99,7 +99,8 @@ def EnumProcessModules(self, emu, argv, ctx={}): @apihook("GetModuleBaseName", argc=4) @apihook("GetModuleBaseNameA", argc=4) @apihook("GetModuleBaseNameW", argc=4) - def GetModuleBaseName(self, emu, argv, ctx={}): + def GetModuleBaseName(self, emu, argv, ctx: api.ApiContext = None): + ctx = ctx or {} hProcess, hModule, lpBaseName, nSize = argv if not lpBaseName or nSize == 0: return 0 @@ -129,7 +130,8 @@ def GetModuleBaseName(self, emu, argv, ctx={}): @apihook("GetModuleFileNameEx", argc=4) @apihook("GetModuleFileNameExA", argc=4) @apihook("GetModuleFileNameExW", argc=4) - def GetModuleFileNameEx(self, emu, argv, ctx={}): + def GetModuleFileNameEx(self, emu, argv, ctx: api.ApiContext = None): + ctx = ctx or {} hProcess, hModule, lpFilename, nSize = argv if not lpFilename or nSize == 0: return 0 diff --git a/speakeasy/winenv/api/usermode/rpcrt4.py b/speakeasy/winenv/api/usermode/rpcrt4.py index 3aff5c9e..6e4ae81a 100644 --- a/speakeasy/winenv/api/usermode/rpcrt4.py +++ b/speakeasy/winenv/api/usermode/rpcrt4.py @@ -21,7 +21,7 @@ def __init__(self, emu): super().__init__(emu) @apihook("UuidCreate", argc=1) - def UuidCreate(self, emu, argv, ctx={}): + def UuidCreate(self, emu, argv, ctx: api.ApiContext = None): """ RPC_STATUS UuidCreate( UUID *Uuid @@ -43,7 +43,7 @@ def UuidCreate(self, emu, argv, ctx={}): return 0 @apihook("UuidToStringA", argc=2) - def UuidToStringA(self, emu, argv, ctx={}): + def UuidToStringA(self, emu, argv, ctx: api.ApiContext = None): """ RPC_STATUS UuidToStringA( const UUID *Uuid, diff --git a/speakeasy/winenv/api/usermode/secur32.py b/speakeasy/winenv/api/usermode/secur32.py index cab8397b..a7808b4c 100644 --- a/speakeasy/winenv/api/usermode/secur32.py +++ b/speakeasy/winenv/api/usermode/secur32.py @@ -17,7 +17,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("GetUserNameEx", argc=3, conv=_arch.CALL_CONV_STDCALL) - def GetUserNameEx(self, emu, argv, ctx={}): + def GetUserNameEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOLEAN SEC_ENTRY GetUserNameExA( EXTENDED_NAME_FORMAT NameFormat, @@ -25,6 +25,7 @@ def GetUserNameEx(self, emu, argv, ctx={}): PULONG nSize ); """ + ctx = ctx or {} NameFormat, lpNameBuffer, nSize = argv cw = self.get_char_width(ctx) @@ -45,7 +46,7 @@ def GetUserNameEx(self, emu, argv, ctx={}): return 1 @apihook("EncryptMessage", argc=4) - def EncryptMessage(self, emu, argv, ctx={}): + def EncryptMessage(self, emu, argv, ctx: api.ApiContext = None): """ SECURITY_STATUS SEC_ENTRY EncryptMessage( PCtxtHandle phContext, diff --git a/speakeasy/winenv/api/usermode/sfc.py b/speakeasy/winenv/api/usermode/sfc.py index 8f2476e0..0e7851c2 100644 --- a/speakeasy/winenv/api/usermode/sfc.py +++ b/speakeasy/winenv/api/usermode/sfc.py @@ -15,9 +15,9 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("SfcIsFileProtected", argc=2) - def SfcIsFileProtected(self, emu, argv, ctx={}): + def SfcIsFileProtected(self, emu, argv, ctx: api.ApiContext = None): return False @apihook("SfcTerminateWatcherThread", argc=0, ordinal=2) - def SfcTerminateWatcherThread(self, emu, argv, ctx={}): + def SfcTerminateWatcherThread(self, emu, argv, ctx: api.ApiContext = None): return 0 diff --git a/speakeasy/winenv/api/usermode/shell32.py b/speakeasy/winenv/api/usermode/shell32.py index 219820b7..c234f8d9 100644 --- a/speakeasy/winenv/api/usermode/shell32.py +++ b/speakeasy/winenv/api/usermode/shell32.py @@ -36,7 +36,7 @@ def get_handle(self): return self.curr_handle @apihook("SHCreateDirectoryEx", argc=3) - def SHCreateDirectoryEx(self, emu, argv, ctx={}): + def SHCreateDirectoryEx(self, emu, argv, ctx: api.ApiContext = None): """ int SHCreateDirectoryExA( HWND hwnd, @@ -44,6 +44,7 @@ def SHCreateDirectoryEx(self, emu, argv, ctx={}): const SECURITY_ATTRIBUTES *psa ); """ + ctx = ctx or {} hwnd, pszPath, psa = argv @@ -58,7 +59,7 @@ def SHCreateDirectoryEx(self, emu, argv, ctx={}): return 0 @apihook("ShellExecute", argc=6) - def ShellExecute(self, emu, argv, ctx={}): + def ShellExecute(self, emu, argv, ctx: api.ApiContext = None): """ HINSTANCE ShellExecuteA( HWND hwnd, @@ -69,6 +70,7 @@ def ShellExecute(self, emu, argv, ctx={}): INT nShowCmd ); """ + ctx = ctx or {} hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd = argv @@ -99,12 +101,13 @@ def ShellExecute(self, emu, argv, ctx={}): return 33 @apihook("ShellExecuteEx", argc=1) - def ShellExecuteEx(self, emu, argv, ctx={}): + def ShellExecuteEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ShellExecuteExA( [in, out] SHELLEXECUTEINFOA *pExecInfo ); """ + ctx = ctx or {} (lpShellExecuteInfo,) = argv sei = shell32_defs.SHELLEXECUTEINFOA(emu.get_ptr_size()) @@ -117,7 +120,7 @@ def ShellExecuteEx(self, emu, argv, ctx={}): return True @apihook("SHChangeNotify", argc=4) - def SHChangeNotify(self, emu, argv, ctx={}): + def SHChangeNotify(self, emu, argv, ctx: api.ApiContext = None): """ void SHChangeNotify( LONG wEventId, @@ -129,14 +132,14 @@ def SHChangeNotify(self, emu, argv, ctx={}): return @apihook("IsUserAnAdmin", argc=0, ordinal=680) - def IsUserAnAdmin(self, emu, argv, ctx={}): + def IsUserAnAdmin(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsUserAnAdmin(); """ return emu.config.user.is_admin @apihook("SHGetMalloc", argc=1) - def SHGetMalloc(self, emu, argv, ctx={}): + def SHGetMalloc(self, emu, argv, ctx: api.ApiContext = None): """ SHSTDAPI SHGetMalloc( IMalloc **ppMalloc @@ -151,13 +154,14 @@ def SHGetMalloc(self, emu, argv, ctx={}): return rv @apihook("CommandLineToArgv", argc=2) - def CommandLineToArgv(self, emu, argv, ctx={}): + def CommandLineToArgv(self, emu, argv, ctx: api.ApiContext = None): """ LPWSTR * CommandLineToArgv( LPCWSTR lpCmdLine, int *pNumArgs ); """ + ctx = ctx or {} cmdline, argc = argv cw = self.get_char_width(ctx) @@ -194,7 +198,7 @@ def CommandLineToArgv(self, emu, argv, ctx={}): return buf @apihook("ExtractIcon", argc=3) - def ExtractIcon(self, emu, argv, ctx={}): + def ExtractIcon(self, emu, argv, ctx: api.ApiContext = None): """ HICON ExtractIconA( HINSTANCE hInst, @@ -206,7 +210,7 @@ def ExtractIcon(self, emu, argv, ctx={}): return self.get_handle() @apihook("SHGetFolderPath", argc=5) - def SHGetFolderPath(self, emu, argv, ctx={}): + def SHGetFolderPath(self, emu, argv, ctx: api.ApiContext = None): """ HWND hwnd, int csidl, @@ -214,6 +218,7 @@ def SHGetFolderPath(self, emu, argv, ctx={}): DWORD dwFlags, LPWSTR pszPath """ + ctx = ctx or {} hwnd, csidl, hToken, dwFlags, pszPath = argv if csidl in shell32_defs.CSIDL: argv[1] = shell32_defs.CSIDL[csidl] diff --git a/speakeasy/winenv/api/usermode/shlwapi.py b/speakeasy/winenv/api/usermode/shlwapi.py index d3c71d28..8fadfafb 100644 --- a/speakeasy/winenv/api/usermode/shlwapi.py +++ b/speakeasy/winenv/api/usermode/shlwapi.py @@ -37,12 +37,13 @@ def join_windows_path(self, *args, **kwargs): return os.path.join(*args, **kwargs).replace("/", "\\") @apihook("PathIsRelative", argc=1) - def PathIsRelative(self, emu, argv, ctx={}): + def PathIsRelative(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PathIsRelativeA( LPCSTR pszPath ); """ + ctx = ctx or {} (pszPath,) = argv @@ -59,13 +60,14 @@ def PathIsRelative(self, emu, argv, ctx={}): return rv @apihook("StrStr", argc=2) - def StrStr(self, emu, argv, ctx={}): + def StrStr(self, emu, argv, ctx: api.ApiContext = None): """ PCSTR StrStr( PCSTR pszFirst, PCSTR pszSrch ); """ + ctx = ctx or {} hay, needle = argv @@ -88,13 +90,14 @@ def StrStr(self, emu, argv, ctx={}): return ret @apihook("StrStrI", argc=2) - def StrStrI(self, emu, argv, ctx={}): + def StrStrI(self, emu, argv, ctx: api.ApiContext = None): """ PCSTR StrStrI( PCSTR pszFirst, PCSTR pszSrch ); """ + ctx = ctx or {} hay, needle = argv @@ -119,11 +122,12 @@ def StrStrI(self, emu, argv, ctx={}): return ret @apihook("PathFindExtension", argc=1) - def PathFindExtension(self, emu, argv, ctx={}): + def PathFindExtension(self, emu, argv, ctx: api.ApiContext = None): """LPCSTR PathFindExtensionA( LPCSTR pszPath ); """ + ctx = ctx or {} (pszPath,) = argv cw = self.get_char_width(ctx) s = self.read_mem_string(pszPath, cw) @@ -138,13 +142,14 @@ def PathFindExtension(self, emu, argv, ctx={}): return pszPath + idx1 + 1 + idx2 @apihook("StrCmpI", argc=2) - def StrCmpI(self, emu, argv, ctx={}): + def StrCmpI(self, emu, argv, ctx: api.ApiContext = None): """ int StrCmpI( PCWSTR psz1, PCWSTR psz2 ); """ + ctx = ctx or {} psz1, psz2 = argv cw = self.get_char_width(ctx) @@ -161,12 +166,13 @@ def StrCmpI(self, emu, argv, ctx={}): return rv @apihook("PathFindFileName", argc=1) - def PathFindFileName(self, emu, argv, ctx={}): + def PathFindFileName(self, emu, argv, ctx: api.ApiContext = None): """ LPCSTR PathFindFileNameA( LPCSTR pszPath ); """ + ctx = ctx or {} (pszPath,) = argv cw = self.get_char_width(ctx) s = self.read_mem_string(pszPath, cw) @@ -179,12 +185,13 @@ def PathFindFileName(self, emu, argv, ctx={}): return pszPath + idx + 1 @apihook("PathRemoveExtension", argc=1) - def PathRemoveExtension(self, emu, argv, ctx={}): + def PathRemoveExtension(self, emu, argv, ctx: api.ApiContext = None): """ void PathRemoveExtensionA( LPSTR pszPath ); """ + ctx = ctx or {} (pszPath,) = argv cw = self.get_char_width(ctx) s = self.read_mem_string(pszPath, cw) @@ -201,12 +208,13 @@ def PathRemoveExtension(self, emu, argv, ctx={}): return pszPath @apihook("PathStripPath", argc=1) - def PathStripPath(self, emu, argv, ctx={}): + def PathStripPath(self, emu, argv, ctx: api.ApiContext = None): """ void PathStripPath( LPSTR pszPath ); """ + ctx = ctx or {} (pszPath,) = argv cw = self.get_char_width(ctx) s = self.read_mem_string(pszPath, cw) @@ -218,7 +226,7 @@ def PathStripPath(self, emu, argv, ctx={}): self.mem_write(pszPath, mod_name) @apihook("wvnsprintfA", argc=4) - def wvnsprintfA(self, emu, argv, ctx={}): + def wvnsprintfA(self, emu, argv, ctx: api.ApiContext = None): """ int wvnsprintfA( PSTR pszDest, @@ -246,7 +254,7 @@ def wvnsprintfA(self, emu, argv, ctx={}): return rv @apihook("wnsprintf", argc=e_arch.VAR_ARGS, conv=e_arch.CALL_CONV_CDECL) - def wnsprintf(self, emu, argv, ctx={}): + def wnsprintf(self, emu, argv, ctx: api.ApiContext = None): """ int wnsprintfA( PSTR pszDest, @@ -255,6 +263,7 @@ def wnsprintf(self, emu, argv, ctx={}): ... ); """ + ctx = ctx or {} argv = emu.get_func_argv(e_arch.CALL_CONV_CDECL, 3) buf, max_buf_size, fmt = argv @@ -279,13 +288,14 @@ def wnsprintf(self, emu, argv, ctx={}): return -1 @apihook("PathAppend", argc=2) - def PathAppend(self, emu, argv, ctx={}): + def PathAppend(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PathAppendA( LPSTR pszPath, LPCSTR pszMore ); """ + ctx = ctx or {} pszPath, pszMore = argv cw = self.get_char_width(ctx) path = self.read_mem_string(pszPath, cw) @@ -298,7 +308,7 @@ def PathAppend(self, emu, argv, ctx={}): return 1 @apihook("PathCanonicalize", argc=2) - def PathCanonicalize(self, emu, argv, ctx={}): + def PathCanonicalize(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PathCanonicalizeW( [out] LPWSTR pszBuf, @@ -311,10 +321,11 @@ def PathCanonicalize(self, emu, argv, ctx={}): return 1 @apihook("PathRemoveFileSpec", argc=1) - def PathRemoveFileSpec(self, emu, argv, ctx={}): + def PathRemoveFileSpec(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PathRemoveFileSpec(LPTSTR pszPath); """ + ctx = ctx or {} (pszPath,) = argv cw = self.get_char_width(ctx) s = self.read_mem_string(pszPath, cw) @@ -327,10 +338,11 @@ def PathRemoveFileSpec(self, emu, argv, ctx={}): return 1 @apihook("PathAddBackslash", argc=1) - def PathAddBackslash(self, emu, argv, ctx={}): + def PathAddBackslash(self, emu, argv, ctx: api.ApiContext = None): """ LPTSTR PathAddBackslash(LPTSTR pszPath); """ + ctx = ctx or {} (pszPath,) = argv cw = self.get_char_width(ctx) s = self.read_mem_string(pszPath, cw) @@ -343,13 +355,14 @@ def PathAddBackslash(self, emu, argv, ctx={}): return pszPath @apihook("PathRenameExtension", argc=2) - def PathRenameExtension(self, emu, argv, ctx={}): + def PathRenameExtension(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PathRenameExtension( [in, out] LPSTR pszPath, [in] LPCSTR pszExt ); """ + ctx = ctx or {} pszPath, pszExt = argv cw = self.get_char_width(ctx) diff --git a/speakeasy/winenv/api/usermode/urlmon.py b/speakeasy/winenv/api/usermode/urlmon.py index 28a0dd61..17cfc06d 100644 --- a/speakeasy/winenv/api/usermode/urlmon.py +++ b/speakeasy/winenv/api/usermode/urlmon.py @@ -23,7 +23,7 @@ def __init__(self, emu): self.names = {} @apihook("URLDownloadToFile", argc=5) - def URLDownloadToFile(self, emu, argv, ctx={}): + def URLDownloadToFile(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT URLDownloadToFile( LPUNKNOWN pCaller, @@ -33,6 +33,7 @@ def URLDownloadToFile(self, emu, argv, ctx={}): LPBINDSTATUSCALLBACK lpfnCB ); """ + ctx = ctx or {} pCaller, szURL, szFileName, dwReserved, lpfnCB = argv rv = windefs.ERROR_SUCCESS @@ -55,7 +56,7 @@ def URLDownloadToFile(self, emu, argv, ctx={}): return rv @apihook("URLDownloadToCacheFile", argc=6) - def URLDownloadToCacheFile(self, emu, argv, ctx={}): + def URLDownloadToCacheFile(self, emu, argv, ctx: api.ApiContext = None): """ HRESULT URLDownloadToCacheFileA( LPUNKNOWN pCaller, @@ -66,6 +67,7 @@ def URLDownloadToCacheFile(self, emu, argv, ctx={}): LPBINDSTATUSCALLBACK lpfnCB ); """ + ctx = ctx or {} pCaller, szURL, szFileName, cchFileName, dwReserved, lpfnCB = argv rv = windefs.ERROR_SUCCESS cw = self.get_char_width(ctx) diff --git a/speakeasy/winenv/api/usermode/user32.py b/speakeasy/winenv/api/usermode/user32.py index 8936a136..50a467bf 100644 --- a/speakeasy/winenv/api/usermode/user32.py +++ b/speakeasy/winenv/api/usermode/user32.py @@ -111,7 +111,7 @@ def find_string_resource_by_id(self, pe, uID): return pe_metadata.string_table.get(uID) @apihook("GetDesktopWindow", argc=0) - def GetDesktopWindow(self, emu, argv, ctx={}): + def GetDesktopWindow(self, emu, argv, ctx: api.ApiContext = None): """HWND GetDesktopWindow();""" hnd = 0 @@ -123,7 +123,7 @@ def GetDesktopWindow(self, emu, argv, ctx={}): return hnd @apihook("ShowWindow", argc=2) - def ShowWindow(self, emu, argv, ctx={}): + def ShowWindow(self, emu, argv, ctx: api.ApiContext = None): """BOOL ShowWindow( HWND hWnd, int nCmdShow @@ -134,7 +134,7 @@ def ShowWindow(self, emu, argv, ctx={}): return rv @apihook("CreateWindowStation", argc=4) - def CreateWindowStation(self, emu, argv, ctx={}): + def CreateWindowStation(self, emu, argv, ctx: api.ApiContext = None): """ HWINSTA CreateWindowStation( LPCSTR lpwinsta, @@ -148,7 +148,7 @@ def CreateWindowStation(self, emu, argv, ctx={}): return self.get_handle() @apihook("SetProcessWindowStation", argc=1) - def SetProcessWindowStation(self, emu, argv, ctx={}): + def SetProcessWindowStation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetProcessWindowStation( HWINSTA hWinSta @@ -163,7 +163,7 @@ def SetProcessWindowStation(self, emu, argv, ctx={}): return rv @apihook("GetDC", argc=1) - def GetDC(self, emu, argv, ctx={}): + def GetDC(self, emu, argv, ctx: api.ApiContext = None): """ HDC GetDC( HWND hWnd @@ -175,12 +175,13 @@ def GetDC(self, emu, argv, ctx={}): return rv @apihook("RegisterClassEx", argc=1) - def RegisterClassEx(self, emu, argv, ctx={}): + def RegisterClassEx(self, emu, argv, ctx: api.ApiContext = None): """ ATOM RegisterClassEx( const WNDCLASSEXA *Arg1 ); """ + ctx = ctx or {} (Arg1,) = argv wclass = windefs.WNDCLASSEX(emu.get_ptr_size()) wclass = self.mem_cast(wclass, Arg1) @@ -195,7 +196,7 @@ def RegisterClassEx(self, emu, argv, ctx={}): return atom @apihook("UnregisterClass", argc=2) - def UnregisterClass(self, emu, argv, ctx={}): + def UnregisterClass(self, emu, argv, ctx: api.ApiContext = None): """ BOOL UnregisterClass( LPCSTR lpClassName, @@ -206,7 +207,7 @@ def UnregisterClass(self, emu, argv, ctx={}): return 1 @apihook("SetCursorPos", argc=2) - def SetCursorPos(self, emu, argv, ctx={}): + def SetCursorPos(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetCursorPos( int X, @@ -216,7 +217,7 @@ def SetCursorPos(self, emu, argv, ctx={}): return 1 @apihook("CloseDesktop", argc=1) - def CloseDesktop(self, emu, argv, ctx={}): + def CloseDesktop(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CloseDesktop( HDESK hDesktop @@ -225,7 +226,7 @@ def CloseDesktop(self, emu, argv, ctx={}): return 1 @apihook("CloseWindowStation", argc=1) - def CloseWindowStation(self, emu, argv, ctx={}): + def CloseWindowStation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL CloseWindowStation( HWINSTA hWinSta @@ -234,7 +235,7 @@ def CloseWindowStation(self, emu, argv, ctx={}): return 1 @apihook("GetThreadDesktop", argc=1) - def GetThreadDesktop(self, emu, argv, ctx={}): + def GetThreadDesktop(self, emu, argv, ctx: api.ApiContext = None): """ HDESK GetThreadDesktop( DWORD dwThreadId @@ -243,7 +244,7 @@ def GetThreadDesktop(self, emu, argv, ctx={}): return 1 @apihook("OpenWindowStation", argc=3) - def OpenWindowStation(self, emu, argv, ctx={}): + def OpenWindowStation(self, emu, argv, ctx: api.ApiContext = None): """ HWINSTA OpenWindowStation( LPCSTR lpszWinSta, @@ -254,7 +255,7 @@ def OpenWindowStation(self, emu, argv, ctx={}): return 1 @apihook("ChangeWindowMessageFilter", argc=2) - def ChangeWindowMessageFilter(self, emu, argv, ctx={}): + def ChangeWindowMessageFilter(self, emu, argv, ctx: api.ApiContext = None): """ BOOL ChangeWindowMessageFilter( UINT message, @@ -266,7 +267,7 @@ def ChangeWindowMessageFilter(self, emu, argv, ctx={}): return True @apihook("UpdateWindow", argc=1) - def UpdateWindow(self, emu, argv, ctx={}): + def UpdateWindow(self, emu, argv, ctx: api.ApiContext = None): """ BOOL UpdateWindow( HWND hWnd @@ -285,7 +286,7 @@ def UpdateWindow(self, emu, argv, ctx={}): return True @apihook("PostQuitMessage", argc=1) - def PostQuitMessage(self, emu, argv, ctx={}): + def PostQuitMessage(self, emu, argv, ctx: api.ApiContext = None): """ void PostQuitMessage( int nExitCode @@ -294,7 +295,7 @@ def PostQuitMessage(self, emu, argv, ctx={}): return @apihook("DestroyWindow", argc=1) - def DestroyWindow(self, emu, argv, ctx={}): + def DestroyWindow(self, emu, argv, ctx: api.ApiContext = None): """ BOOL DestroyWindow( HWND hWnd @@ -303,7 +304,7 @@ def DestroyWindow(self, emu, argv, ctx={}): return True @apihook("DefWindowProc", argc=4) - def DefWindowProc(self, emu, argv, ctx={}): + def DefWindowProc(self, emu, argv, ctx: api.ApiContext = None): """ LRESULT LRESULT DefWindowProc( HWND hWnd, @@ -315,7 +316,7 @@ def DefWindowProc(self, emu, argv, ctx={}): return 0 @apihook("CreateWindowEx", argc=12) - def CreateWindowEx(self, emu, argv, ctx={}): + def CreateWindowEx(self, emu, argv, ctx: api.ApiContext = None): """ HWND CreateWindowExA( DWORD dwExStyle, @@ -332,6 +333,7 @@ def CreateWindowEx(self, emu, argv, ctx={}): LPVOID lpParam ); """ + ctx = ctx or {} cw = self.get_char_width(ctx) _, cn, wn, _, x, y, width, height, parent, menu, inst, param = argv if cn: @@ -348,7 +350,7 @@ def CreateWindowEx(self, emu, argv, ctx={}): return hnd @apihook("SetLayeredWindowAttributes", argc=4) - def SetLayeredWindowAttributes(self, emu, argv, ctx={}): + def SetLayeredWindowAttributes(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetLayeredWindowAttributes( [in] HWND hwnd, @@ -361,13 +363,14 @@ def SetLayeredWindowAttributes(self, emu, argv, ctx={}): return 1 @apihook("MessageBox", argc=4) - def MessageBox(self, emu, argv, ctx={}): + def MessageBox(self, emu, argv, ctx: api.ApiContext = None): """int MessageBox( HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType );""" + ctx = ctx or {} hWnd, lpText, lpCaption, uType = argv cw = self.get_char_width(ctx) @@ -383,7 +386,7 @@ def MessageBox(self, emu, argv, ctx={}): return rv @apihook("MessageBoxEx", argc=5) - def MessageBoxEx(self, emu, argv, ctx={}): + def MessageBoxEx(self, emu, argv, ctx: api.ApiContext = None): """ int MessageBoxExA( HWND hWnd, @@ -393,13 +396,14 @@ def MessageBoxEx(self, emu, argv, ctx={}): WORD wLanguageId ); """ + ctx = ctx or {} av = argv[:-1] rv = self.MessageBox(emu, av, ctx) argv[:4] = av return rv @apihook("LoadString", argc=4) - def LoadString(self, emu, argv, ctx={}): + def LoadString(self, emu, argv, ctx: api.ApiContext = None): """ int LoadStringW( HINSTANCE hInstance, @@ -408,6 +412,7 @@ def LoadString(self, emu, argv, ctx={}): int cchBufferMax ); """ + ctx = ctx or {} hInstance, uID, lpBuffer, ccBufferMax = argv cw = self.get_char_width(ctx) @@ -455,7 +460,7 @@ def LoadString(self, emu, argv, ctx={}): return len(encoded) @apihook("GetCursorPos", argc=1) - def GetCursorPos(self, emu, argv, ctx={}): + def GetCursorPos(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetCursorPos( LPPOINT lpPoint @@ -468,7 +473,7 @@ def GetCursorPos(self, emu, argv, ctx={}): return rv @apihook("GetAsyncKeyState", argc=1) - def GetAsyncKeyState(self, emu, argv, ctx={}): + def GetAsyncKeyState(self, emu, argv, ctx: api.ApiContext = None): """ SHORT GetAsyncKeyState( [in] int vKey @@ -479,7 +484,7 @@ def GetAsyncKeyState(self, emu, argv, ctx={}): return self.get_synthetic_async_key_state(vkey) @apihook("GetKeyboardType", argc=1) - def GetKeyboardType(self, emu, argv, ctx={}): + def GetKeyboardType(self, emu, argv, ctx: api.ApiContext = None): """ int GetKeyboardType( int nTypeFlag @@ -495,7 +500,7 @@ def GetKeyboardType(self, emu, argv, ctx={}): return 0 @apihook("GetSystemMetrics", argc=1) - def GetSystemMetrics(self, emu, argv, ctx={}): + def GetSystemMetrics(self, emu, argv, ctx: api.ApiContext = None): """ int GetSystemMetrics( int nIndex @@ -508,7 +513,7 @@ def GetSystemMetrics(self, emu, argv, ctx={}): return rv @apihook("LoadBitmap", argc=2) - def LoadBitmap(self, emu, argv, ctx={}): + def LoadBitmap(self, emu, argv, ctx: api.ApiContext = None): """ HBITMAP LoadBitmap( HINSTANCE hInstance, @@ -520,7 +525,7 @@ def LoadBitmap(self, emu, argv, ctx={}): return rv @apihook("GetClientRect", argc=2) - def GetClientRect(self, emu, argv, ctx={}): + def GetClientRect(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetClientRect( [in] HWND hWnd, @@ -530,12 +535,13 @@ def GetClientRect(self, emu, argv, ctx={}): return 0 @apihook("RegisterWindowMessage", argc=1) - def RegisterWindowMessage(self, emu, argv, ctx={}): + def RegisterWindowMessage(self, emu, argv, ctx: api.ApiContext = None): """ UINT RegisterWindowMessageA( LPCSTR lpString ); """ + ctx = ctx or {} (lpString,) = argv rv = 0xC000 @@ -548,7 +554,7 @@ def RegisterWindowMessage(self, emu, argv, ctx={}): return rv @apihook("wsprintf", argc=_arch.VAR_ARGS, conv=_arch.CALL_CONV_CDECL) - def wsprintf(self, emu, argv, ctx={}): + def wsprintf(self, emu, argv, ctx: api.ApiContext = None): """ int WINAPIV wsprintf( LPSTR , @@ -556,6 +562,7 @@ def wsprintf(self, emu, argv, ctx={}): ... ); """ + ctx = ctx or {} cw = self.get_char_width(ctx) buf, fmt = emu.get_func_argv(_arch.CALL_CONV_CDECL, 2) @@ -576,7 +583,7 @@ def wsprintf(self, emu, argv, ctx={}): return len(fin) @apihook("PeekMessage", argc=5) - def PeekMessage(self, emu, argv, ctx={}): + def PeekMessage(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PeekMessageA( LPMSG lpMsg, @@ -589,7 +596,7 @@ def PeekMessage(self, emu, argv, ctx={}): return False @apihook("PostMessage", argc=4) - def PostMessage(self, emu, argv, ctx={}): + def PostMessage(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PostMessage( HWND hWnd, @@ -601,7 +608,7 @@ def PostMessage(self, emu, argv, ctx={}): return True @apihook("SendMessage", argc=4) - def SendMessage(self, emu, argv, ctx={}): + def SendMessage(self, emu, argv, ctx: api.ApiContext = None): """ LRESULT SendMessage( HWND hWnd, @@ -617,7 +624,7 @@ def SendMessage(self, emu, argv, ctx={}): return False @apihook("CallNextHookEx", argc=4) - def CallNextHookEx(self, emu, argv, ctx={}): + def CallNextHookEx(self, emu, argv, ctx: api.ApiContext = None): """ LRESULT CallNextHookEx( HHOOK hhk, @@ -630,7 +637,7 @@ def CallNextHookEx(self, emu, argv, ctx={}): return 0 @apihook("SetWindowsHookEx", argc=4) - def SetWindowsHookEx(self, emu, argv, ctx={}): + def SetWindowsHookEx(self, emu, argv, ctx: api.ApiContext = None): """ HHOOK SetWindowsHookEx( int idHook, @@ -651,7 +658,7 @@ def SetWindowsHookEx(self, emu, argv, ctx={}): return hnd @apihook("UnhookWindowsHookEx", argc=1) - def UnhookWindowsHookEx(self, emu, argv, ctx={}): + def UnhookWindowsHookEx(self, emu, argv, ctx: api.ApiContext = None): """ BOOL UnhookWindowsHookEx( HHOOK hhk @@ -666,7 +673,7 @@ def UnhookWindowsHookEx(self, emu, argv, ctx={}): return rv @apihook("MsgWaitForMultipleObjects", argc=5) - def MsgWaitForMultipleObjects(self, emu, argv, ctx={}): + def MsgWaitForMultipleObjects(self, emu, argv, ctx: api.ApiContext = None): """ DWORD MsgWaitForMultipleObjects( DWORD nCount, @@ -679,7 +686,7 @@ def MsgWaitForMultipleObjects(self, emu, argv, ctx={}): return 0 @apihook("GetMessage", argc=4) - def GetMessage(self, emu, argv, ctx={}): + def GetMessage(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetMessage( LPMSG lpMsg, @@ -720,7 +727,7 @@ def GetMessage(self, emu, argv, ctx={}): return True @apihook("TranslateMessage", argc=1) - def TranslateMessage(self, emu, argv, ctx={}): + def TranslateMessage(self, emu, argv, ctx: api.ApiContext = None): """ BOOL TranslateMessage( const MSG *lpMsg @@ -729,7 +736,7 @@ def TranslateMessage(self, emu, argv, ctx={}): return True @apihook("DispatchMessage", argc=1) - def DispatchMessage(self, emu, argv, ctx={}): + def DispatchMessage(self, emu, argv, ctx: api.ApiContext = None): """ LRESULT DispatchMessage( const MSG *lpMsg @@ -743,14 +750,14 @@ def DispatchMessage(self, emu, argv, ctx={}): return 0 @apihook("GetForegroundWindow", argc=0) - def GetForegroundWindow(self, emu, argv, ctx={}): + def GetForegroundWindow(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetForegroundWindow(); """ return self.get_handle() @apihook("LoadCursor", argc=2) - def LoadCursor(self, emu, argv, ctx={}): + def LoadCursor(self, emu, argv, ctx: api.ApiContext = None): """ HCURSOR LoadCursor( HINSTANCE hInstance, @@ -760,13 +767,14 @@ def LoadCursor(self, emu, argv, ctx={}): return self.get_handle() @apihook("FindWindow", argc=2) - def FindWindow(self, emu, argv, ctx={}): + def FindWindow(self, emu, argv, ctx: api.ApiContext = None): """ HWND FindWindow( LPCSTR lpClassName, LPCSTR lpWindowName ); """ + ctx = ctx or {} lpClassName, lpWindowName = argv cw = self.get_char_width(ctx) if lpClassName: @@ -778,7 +786,7 @@ def FindWindow(self, emu, argv, ctx={}): return 0 @apihook("GetWindowText", argc=3) - def GetWindowText(self, emu, argv, ctx={}): + def GetWindowText(self, emu, argv, ctx: api.ApiContext = None): """ int GetWindowText( HWND hWnd, @@ -786,6 +794,7 @@ def GetWindowText(self, emu, argv, ctx={}): int nMaxCount ); """ + ctx = ctx or {} hnd, pstr, maxc = argv cw = self.get_char_width(ctx) @@ -800,7 +809,7 @@ def GetWindowText(self, emu, argv, ctx={}): return len(win_text) @apihook("PaintDesktop", argc=1) - def PaintDesktop(self, emu, argv, ctx={}): + def PaintDesktop(self, emu, argv, ctx: api.ApiContext = None): """ BOOL PaintDesktop( HDC hdc @@ -809,7 +818,8 @@ def PaintDesktop(self, emu, argv, ctx={}): return 0 @apihook("wvsprintf", argc=_arch.VAR_ARGS, conv=_arch.CALL_CONV_CDECL) - def wvsprintf(self, emu, argv, ctx={}): + def wvsprintf(self, emu, argv, ctx: api.ApiContext = None): + ctx = ctx or {} buf, fmt, va_list = emu.get_func_argv(_arch.CALL_CONV_CDECL, 3)[:3] cw = self.get_char_width(ctx) fmt_str = self.read_mem_string(fmt, cw) @@ -824,7 +834,7 @@ def wvsprintf(self, emu, argv, ctx={}): return len(fin) @apihook("ReleaseDC", argc=2) - def ReleaseDC(self, emu, argv, ctx={}): + def ReleaseDC(self, emu, argv, ctx: api.ApiContext = None): """ int ReleaseDC( HWND hWnd, @@ -834,12 +844,13 @@ def ReleaseDC(self, emu, argv, ctx={}): return 0 @apihook("CharNext", argc=1) - def CharNext(self, emu, argv, ctx={}): + def CharNext(self, emu, argv, ctx: api.ApiContext = None): """ LPSTR CharNext( LPCSTR lpsz ); """ + ctx = ctx or {} (s,) = argv rv = 0 cw = self.get_char_width(ctx) @@ -848,13 +859,14 @@ def CharNext(self, emu, argv, ctx={}): return rv @apihook("CharPrev", argc=2) - def CharPrev(self, emu, argv, ctx={}): + def CharPrev(self, emu, argv, ctx: api.ApiContext = None): """ LPSTR CharPrev( LPCSTR lpszStart, LPCSTR lpszCurrent ); """ + ctx = ctx or {} """ Got this from wine. https://github.com/wine-mirror/wine/blob/a8c1d5c108fc57e4d78e9db126f395c89083a83d/dlls/kernelbase/string.c @@ -870,7 +882,7 @@ def CharPrev(self, emu, argv, ctx={}): return s @apihook("EnumWindows", argc=2) - def EnumWindows(self, emu, argv, ctx={}): + def EnumWindows(self, emu, argv, ctx: api.ApiContext = None): """ BOOL EnumWindows( WNDENUMPROC lpEnumFunc, @@ -883,7 +895,7 @@ def EnumWindows(self, emu, argv, ctx={}): return rv @apihook("GetSysColor", argc=1) - def GetSysColor(self, emu, argv, ctx={}): + def GetSysColor(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetSysColor( int nIndex @@ -895,7 +907,7 @@ def GetSysColor(self, emu, argv, ctx={}): return rv @apihook("GetParent", argc=1) - def GetParent(self, emu, argv, ctx={}): + def GetParent(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetParent( HWND hWnd @@ -904,7 +916,7 @@ def GetParent(self, emu, argv, ctx={}): return self.get_handle() @apihook("GetSysColorBrush", argc=1) - def GetSysColorBrush(self, emu, argv, ctx={}): + def GetSysColorBrush(self, emu, argv, ctx: api.ApiContext = None): """ HBRUSH GetSysColorBrush( int nIndex @@ -916,7 +928,7 @@ def GetSysColorBrush(self, emu, argv, ctx={}): return rv @apihook("GetWindowLong", argc=2) - def GetWindowLong(self, emu, argv, ctx={}): + def GetWindowLong(self, emu, argv, ctx: api.ApiContext = None): """ LONG GetWindowLongA( HWND hWnd, @@ -932,7 +944,7 @@ def GetWindowLong(self, emu, argv, ctx={}): return rv @apihook("SetWindowLong", argc=3) - def SetWindowLong(self, emu, argv, ctx={}): + def SetWindowLong(self, emu, argv, ctx: api.ApiContext = None): """ LONG SetWindowLongA( HWND hWnd, @@ -949,7 +961,7 @@ def SetWindowLong(self, emu, argv, ctx={}): return 1 @apihook("DialogBoxParam", argc=5) - def DialogBoxParam(self, emu, argv, ctx={}): + def DialogBoxParam(self, emu, argv, ctx: api.ApiContext = None): """ INT_PTR DialogBoxParam( HINSTANCE hInstance, @@ -959,6 +971,7 @@ def DialogBoxParam(self, emu, argv, ctx={}): LPARAM dwInitParam ); """ + ctx = ctx or {} hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam = argv rv = self.get_handle() cw = self.get_char_width(ctx) @@ -969,7 +982,7 @@ def DialogBoxParam(self, emu, argv, ctx={}): return rv @apihook("CreateDialogIndirectParam", argc=5) - def CreateDialogIndirectParam(self, emu, argv, ctx={}): + def CreateDialogIndirectParam(self, emu, argv, ctx: api.ApiContext = None): """ HWND CreateDialogIndirectParam( HINSTANCE hInstance, @@ -993,7 +1006,7 @@ def CreateDialogIndirectParam(self, emu, argv, ctx={}): return self.get_handle() @apihook("GetMenuInfo", argc=2) - def GetMenuInfo(self, emu, argv, ctx={}): + def GetMenuInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetMenuInfo( HMENU, @@ -1003,7 +1016,7 @@ def GetMenuInfo(self, emu, argv, ctx={}): return 1 @apihook("GetProcessWindowStation", argc=0) - def GetProcessWindowStation(self, emu, argv, ctx={}): + def GetProcessWindowStation(self, emu, argv, ctx: api.ApiContext = None): """ HWINSTA GetProcessWindowStation(); """ @@ -1011,7 +1024,7 @@ def GetProcessWindowStation(self, emu, argv, ctx={}): return sta.get_handle() @apihook("LoadAccelerators", argc=2) - def LoadAccelerators(self, emu, argv, ctx={}): + def LoadAccelerators(self, emu, argv, ctx: api.ApiContext = None): """ HACCEL LoadAccelerators( HINSTANCE hInstance, @@ -1021,7 +1034,7 @@ def LoadAccelerators(self, emu, argv, ctx={}): return self.get_handle() @apihook("IsWindowVisible", argc=1) - def IsWindowVisible(self, emu, argv, ctx={}): + def IsWindowVisible(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsWindowVisible( HWND hWnd @@ -1030,7 +1043,7 @@ def IsWindowVisible(self, emu, argv, ctx={}): return True @apihook("BeginPaint", argc=2) - def BeginPaint(self, emu, argv, ctx={}): + def BeginPaint(self, emu, argv, ctx: api.ApiContext = None): """ HDC BeginPaint( HWND hWnd, @@ -1040,7 +1053,7 @@ def BeginPaint(self, emu, argv, ctx={}): return self.get_handle() @apihook("LookupIconIdFromDirectory", argc=2) - def LookupIconIdFromDirectory(self, emu, argv, ctx={}): + def LookupIconIdFromDirectory(self, emu, argv, ctx: api.ApiContext = None): """ int LookupIconIdFromDirectory( PBYTE presbits, @@ -1050,14 +1063,14 @@ def LookupIconIdFromDirectory(self, emu, argv, ctx={}): return 1 @apihook("GetActiveWindow", argc=0) - def GetActiveWindow(self, emu, argv, ctx={}): + def GetActiveWindow(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetActiveWindow(); """ return self.get_handle() @apihook("GetLastActivePopup", argc=1) - def GetLastActivePopup(self, emu, argv, ctx={}): + def GetLastActivePopup(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetLastActivePopup( HWND hWnd @@ -1067,7 +1080,7 @@ def GetLastActivePopup(self, emu, argv, ctx={}): return self.get_handle() @apihook("GetUserObjectInformation", argc=5) - def GetUserObjectInformation(self, emu, argv, ctx={}): + def GetUserObjectInformation(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetUserObjectInformation( HANDLE hObj, @@ -1090,7 +1103,7 @@ def GetUserObjectInformation(self, emu, argv, ctx={}): return True @apihook("LoadIcon", argc=2) - def LoadIcon(self, emu, argv, ctx={}): + def LoadIcon(self, emu, argv, ctx: api.ApiContext = None): """ HICON LoadIcon( HINSTANCE hInstance, @@ -1118,7 +1131,7 @@ def LoadIcon(self, emu, argv, ctx={}): return 1 @apihook("GetRawInputDeviceList", argc=3) - def GetRawInputDeviceList(self, emu, argv, ctx={}): + def GetRawInputDeviceList(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetRawInputDeviceList( PRAWINPUTDEVICELIST pRawInputDeviceList, @@ -1132,7 +1145,7 @@ def GetRawInputDeviceList(self, emu, argv, ctx={}): return num_devices @apihook("GetNextDlgTabItem", argc=3) - def GetNextDlgTabItem(self, emu, argv, ctx={}): + def GetNextDlgTabItem(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetNextDlgTabItem( HWND hDlg, @@ -1143,7 +1156,7 @@ def GetNextDlgTabItem(self, emu, argv, ctx={}): return 0 @apihook("GetCaretPos", argc=1) - def GetCaretPos(self, emu, argv, ctx={}): + def GetCaretPos(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetCaretPos( LPPOINT lpPoint @@ -1157,7 +1170,7 @@ def GetCaretPos(self, emu, argv, ctx={}): return 1 @apihook("GetMonitorInfo", argc=2) - def GetMonitorInfo(self, emu, argv, ctx={}): + def GetMonitorInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetMonitorInfo( HMONITOR hMonitor, @@ -1172,7 +1185,7 @@ def GetMonitorInfo(self, emu, argv, ctx={}): return 1 @apihook("EndPaint", argc=2) - def EndPaint(self, emu, argv, ctx={}): + def EndPaint(self, emu, argv, ctx: api.ApiContext = None): """ BOOL EndPaint( HWND hWnd, @@ -1182,7 +1195,7 @@ def EndPaint(self, emu, argv, ctx={}): return 1 @apihook("GetDlgCtrlID", argc=1) - def GetDlgCtrlID(self, emu, argv, ctx={}): + def GetDlgCtrlID(self, emu, argv, ctx: api.ApiContext = None): """ int GetDlgCtrlID( HWND hWnd @@ -1191,7 +1204,7 @@ def GetDlgCtrlID(self, emu, argv, ctx={}): return 1 @apihook("GetUpdateRect", argc=3) - def GetUpdateRect(self, emu, argv, ctx={}): + def GetUpdateRect(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetUpdateRect( HWND hWnd, @@ -1202,7 +1215,7 @@ def GetUpdateRect(self, emu, argv, ctx={}): return 0 @apihook("GetAltTabInfo", argc=5) - def GetAltTabInfo(self, emu, argv, ctx={}): + def GetAltTabInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOL GetAltTabInfoA( HWND hwnd, @@ -1215,7 +1228,7 @@ def GetAltTabInfo(self, emu, argv, ctx={}): return 0 @apihook("GetUpdateRgn", argc=3) - def GetUpdateRgn(self, emu, argv, ctx={}): + def GetUpdateRgn(self, emu, argv, ctx: api.ApiContext = None): """ int GetUpdateRgn( HWND hWnd, @@ -1226,7 +1239,7 @@ def GetUpdateRgn(self, emu, argv, ctx={}): return 0 @apihook("FlashWindow", argc=2) - def FlashWindow(self, emu, argv, ctx={}): + def FlashWindow(self, emu, argv, ctx: api.ApiContext = None): """ BOOL FlashWindow( HWND hWnd, @@ -1236,7 +1249,7 @@ def FlashWindow(self, emu, argv, ctx={}): return 1 @apihook("IsClipboardFormatAvailable", argc=1) - def IsClipboardFormatAvailable(self, emu, argv, ctx={}): + def IsClipboardFormatAvailable(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsClipboardFormatAvailable( UINT format @@ -1245,7 +1258,7 @@ def IsClipboardFormatAvailable(self, emu, argv, ctx={}): return 0 @apihook("IsWindow", argc=1) - def IsWindow(self, emu, argv, ctx={}): + def IsWindow(self, emu, argv, ctx: api.ApiContext = None): """ BOOL IsWindow( HWND hWnd @@ -1256,7 +1269,7 @@ def IsWindow(self, emu, argv, ctx={}): return True @apihook("EnableWindow", argc=2) - def EnableWindow(self, emu, argv, ctx={}): + def EnableWindow(self, emu, argv, ctx: api.ApiContext = None): """ BOOL EnableWindow( HWND hWnd, @@ -1268,13 +1281,14 @@ def EnableWindow(self, emu, argv, ctx={}): return False @apihook("CharLowerBuff", argc=2) - def CharLowerBuff(self, emu, argv, ctx={}): + def CharLowerBuff(self, emu, argv, ctx: api.ApiContext = None): """ DWORD CharLowerBuffA( LPSTR lpsz, DWORD cchLength ); """ + ctx = ctx or {} _str, cchLength = argv cw = self.get_char_width(ctx) val = self.read_mem_string(_str, cw, max_chars=cchLength) @@ -1284,13 +1298,14 @@ def CharLowerBuff(self, emu, argv, ctx={}): return cchLength @apihook("CharUpperBuff", argc=2) - def CharUpperBuff(self, emu, argv, ctx={}): + def CharUpperBuff(self, emu, argv, ctx: api.ApiContext = None): """ DWORD CharUpperBuffA( LPSTR lpsz, DWORD cchLength ); """ + ctx = ctx or {} _str, cchLength = argv cw = self.get_char_width(ctx) val = self.read_mem_string(_str, cw, max_chars=cchLength) @@ -1300,12 +1315,13 @@ def CharUpperBuff(self, emu, argv, ctx={}): return cchLength @apihook("CharLower", argc=1) - def CharLower(self, emu, argv, ctx={}): + def CharLower(self, emu, argv, ctx: api.ApiContext = None): """ LPSTR CharLowerA( LPSTR lpsz ); """ + ctx = ctx or {} (_str,) = argv cw = self.get_char_width(ctx) bits = _str.bit_length() @@ -1321,12 +1337,13 @@ def CharLower(self, emu, argv, ctx={}): return _str @apihook("CharUpper", argc=1) - def CharUpper(self, emu, argv, ctx={}): + def CharUpper(self, emu, argv, ctx: api.ApiContext = None): """ LPSTR CharUpperA( LPSTR lpsz ); """ + ctx = ctx or {} (_str,) = argv cw = self.get_char_width(ctx) bits = _str.bit_length() @@ -1342,7 +1359,7 @@ def CharUpper(self, emu, argv, ctx={}): return _str @apihook("SetTimer", argc=4) - def SetTimer(self, emu, argv, ctx={}): + def SetTimer(self, emu, argv, ctx: api.ApiContext = None): """ UINT_PTR SetTimer( HWND hWnd, @@ -1356,7 +1373,7 @@ def SetTimer(self, emu, argv, ctx={}): return self.get_handle() @apihook("KillTimer", argc=2) - def KillTimer(self, emu, argv, ctx={}): + def KillTimer(self, emu, argv, ctx: api.ApiContext = None): """ BOOL KillTimer( HWND hWnd, @@ -1368,7 +1385,7 @@ def KillTimer(self, emu, argv, ctx={}): return True @apihook("OpenDesktop", argc=4) - def OpenDesktop(self, emu, argv, ctx={}): + def OpenDesktop(self, emu, argv, ctx: api.ApiContext = None): """ HDESK OpenDesktopA( LPCSTR lpszDesktop, @@ -1377,6 +1394,7 @@ def OpenDesktop(self, emu, argv, ctx={}): ACCESS_MASK dwDesiredAccess ); """ + ctx = ctx or {} lpszDesktop, dwFlags, fInherit, dwDesiredAccess = argv cw = self.get_char_width(ctx) desktop = self.read_mem_string(lpszDesktop, cw) @@ -1384,7 +1402,7 @@ def OpenDesktop(self, emu, argv, ctx={}): return self.get_handle() @apihook("SetThreadDesktop", argc=1) - def SetThreadDesktop(self, emu, argv, ctx={}): + def SetThreadDesktop(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SetThreadDesktop( HDESK hDesktop @@ -1393,7 +1411,7 @@ def SetThreadDesktop(self, emu, argv, ctx={}): return 0 @apihook("GetKeyboardLayoutList", argc=2) - def GetKeyboardLayoutList(self, emu, argv, ctx={}): + def GetKeyboardLayoutList(self, emu, argv, ctx: api.ApiContext = None): """ int GetKeyboardLayoutList( int nBuff, @@ -1411,7 +1429,7 @@ def GetKeyboardLayoutList(self, emu, argv, ctx={}): return 1 @apihook("GetKBCodePage", argc=0) - def GetKBCodePage(self, emu, argv, ctx={}): + def GetKBCodePage(self, emu, argv, ctx: api.ApiContext = None): """ INT GetKBCodePage(); """ @@ -1421,7 +1439,7 @@ def GetKBCodePage(self, emu, argv, ctx={}): return 437 # OEM United States @apihook("GetClipboardViewer", argc=0) - def GetClipboardViewer(self, emu, argv, ctx={}): + def GetClipboardViewer(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetClipboardViewer(); """ @@ -1434,7 +1452,7 @@ def GetClipboardViewer(self, emu, argv, ctx={}): return hnd @apihook("GetClipboardOwner", argc=0) - def GetClipboardOwner(self, emu, argv, ctx={}): + def GetClipboardOwner(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetClipboardOwner(); """ @@ -1447,7 +1465,7 @@ def GetClipboardOwner(self, emu, argv, ctx={}): return hnd @apihook("GetMenuCheckMarkDimensions", argc=0) - def GetMenuCheckMarkDimensions(self, emu, argv, ctx={}): + def GetMenuCheckMarkDimensions(self, emu, argv, ctx: api.ApiContext = None): """ LONG GetMenuCheckMarkDimensions(); """ @@ -1456,7 +1474,7 @@ def GetMenuCheckMarkDimensions(self, emu, argv, ctx={}): return 983055 @apihook("GetOpenClipboardWindow", argc=0) - def GetOpenClipboardWindow(self, emu, argv, ctx={}): + def GetOpenClipboardWindow(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetOpenClipboardWindow(); """ @@ -1469,7 +1487,7 @@ def GetOpenClipboardWindow(self, emu, argv, ctx={}): return hnd @apihook("GetFocus", argc=0) - def GetFocus(self, emu, argv, ctx={}): + def GetFocus(self, emu, argv, ctx: api.ApiContext = None): """ HWND GetFocus(); """ @@ -1482,7 +1500,7 @@ def GetFocus(self, emu, argv, ctx={}): return hnd @apihook("GetCursor", argc=0) - def GetCursor(self, emu, argv, ctx={}): + def GetCursor(self, emu, argv, ctx: api.ApiContext = None): """ HCURSOR GetCursor(); """ @@ -1495,7 +1513,7 @@ def GetCursor(self, emu, argv, ctx={}): return hnd @apihook("GetClipboardSequenceNumber", argc=0) - def GetClipboardSequenceNumber(self, emu, argv, ctx={}): + def GetClipboardSequenceNumber(self, emu, argv, ctx: api.ApiContext = None): """ DWORD GetClipboardSequenceNumber(); """ @@ -1504,7 +1522,7 @@ def GetClipboardSequenceNumber(self, emu, argv, ctx={}): return 295 @apihook("GetCaretBlinkTime", argc=0) - def GetCaretBlinkTime(self, emu, argv, ctx={}): + def GetCaretBlinkTime(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetCaretBlinkTime(); """ @@ -1513,7 +1531,7 @@ def GetCaretBlinkTime(self, emu, argv, ctx={}): return 530 @apihook("GetDoubleClickTime", argc=0) - def GetDoubleClickTime(self, emu, argv, ctx={}): + def GetDoubleClickTime(self, emu, argv, ctx: api.ApiContext = None): """ UINT GetDoubleClickTime(); """ @@ -1522,7 +1540,7 @@ def GetDoubleClickTime(self, emu, argv, ctx={}): return 500 @apihook("RegisterClipboardFormatA", argc=1) - def RegisterClipboardFormatA(self, emu, argv, ctx={}): + def RegisterClipboardFormatA(self, emu, argv, ctx: api.ApiContext = None): """ UINT RegisterClipboardFormatA( LPCSTR lpszFormat @@ -1533,7 +1551,7 @@ def RegisterClipboardFormatA(self, emu, argv, ctx={}): return 0xC000 @apihook("SystemParametersInfoA", argc=4) - def SystemParametersInfoA(self, emu, argv, ctx={}): + def SystemParametersInfoA(self, emu, argv, ctx: api.ApiContext = None): """ BOOL SystemParametersInfoA( UINT uiAction, @@ -1549,7 +1567,7 @@ def SystemParametersInfoA(self, emu, argv, ctx={}): return 1 @apihook("GetKeyboardLayout", argc=1) - def GetKeyboardLayout(self, emu, argv, ctx={}): + def GetKeyboardLayout(self, emu, argv, ctx: api.ApiContext = None): """ HKL GetKeyboardLayout( DWORD idThread @@ -1560,7 +1578,7 @@ def GetKeyboardLayout(self, emu, argv, ctx={}): return 0x04090409 @apihook("EnumDisplayMonitors", argc=4) - def EnumDisplayMonitors(self, emu, argv, ctx={}): + def EnumDisplayMonitors(self, emu, argv, ctx: api.ApiContext = None): """ BOOL EnumDisplayMonitors( HDC hdc, @@ -1576,7 +1594,7 @@ def EnumDisplayMonitors(self, emu, argv, ctx={}): return 1 @apihook("OemToCharA", argc=2) - def OemToCharA(self, emu, argv, ctx={}): + def OemToCharA(self, emu, argv, ctx: api.ApiContext = None): """ BOOL OemToCharA( LPCSTR lpszSrc, @@ -1602,7 +1620,7 @@ def OemToCharA(self, emu, argv, ctx={}): return 1 @apihook("CharPrevW", argc=2) - def CharPrevW(self, emu, argv, ctx={}): + def CharPrevW(self, emu, argv, ctx: api.ApiContext = None): """ LPWSTR CharPrevW( LPCWSTR lpszStart, diff --git a/speakeasy/winenv/api/usermode/winhttp.py b/speakeasy/winenv/api/usermode/winhttp.py index 68f3b8b7..df28ddee 100644 --- a/speakeasy/winenv/api/usermode/winhttp.py +++ b/speakeasy/winenv/api/usermode/winhttp.py @@ -39,7 +39,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("WinHttpOpen", argc=5, conv=_arch.CALL_CONV_STDCALL) - def WinHttpOpen(self, emu, argv, ctx={}): + def WinHttpOpen(self, emu, argv, ctx: api.ApiContext = None): """ WINHTTPAPI HINTERNET WinHttpOpen( LPCWSTR pszAgentW, @@ -67,7 +67,7 @@ def WinHttpOpen(self, emu, argv, ctx={}): return hnd @apihook("WinHttpConnect", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WinHttpConnect(self, emu, argv, ctx={}): + def WinHttpConnect(self, emu, argv, ctx: api.ApiContext = None): """ WINHTTPAPI HINTERNET WinHttpConnect( IN HINTERNET hSession, @@ -92,7 +92,7 @@ def WinHttpConnect(self, emu, argv, ctx={}): return hdl @apihook("WinHttpOpenRequest", argc=7, conv=_arch.CALL_CONV_STDCALL) - def WinHttpOpenRequest(self, emu, argv, ctx={}): + def WinHttpOpenRequest(self, emu, argv, ctx: api.ApiContext = None): """ WINHTTPAPI HINTERNET WinHttpOpenRequest( IN HINTERNET hConnect, @@ -132,7 +132,7 @@ def WinHttpOpenRequest(self, emu, argv, ctx={}): return hdl @apihook("WinHttpGetIEProxyConfigForCurrentUser", argc=1, conv=_arch.CALL_CONV_STDCALL) - def WinHttpGetIEProxyConfigForCurrentUser(self, emu, argv, ctx={}): + def WinHttpGetIEProxyConfigForCurrentUser(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpGetIEProxyConfigForCurrentUser( IN OUT WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *pProxyConfig @@ -147,7 +147,7 @@ def WinHttpGetIEProxyConfigForCurrentUser(self, emu, argv, ctx={}): return True @apihook("WinHttpGetProxyForUrl", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WinHttpGetProxyForUrl(self, emu, argv, ctx={}): + def WinHttpGetProxyForUrl(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpGetProxyForUrl( IN HINTERNET hSession, @@ -166,7 +166,7 @@ def WinHttpGetProxyForUrl(self, emu, argv, ctx={}): return True @apihook("WinHttpSetOption", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WinHttpSetOption(self, emu, argv, ctx={}): + def WinHttpSetOption(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpSendRequest( IN HINTERNET hRequest, @@ -183,7 +183,7 @@ def WinHttpSetOption(self, emu, argv, ctx={}): return True @apihook("WinHttpSendRequest", argc=7, conv=_arch.CALL_CONV_STDCALL) - def WinHttpSendRequest(self, emu, argv, ctx={}): + def WinHttpSendRequest(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpSendRequest( IN HINTERNET hRequest, @@ -220,7 +220,7 @@ def WinHttpSendRequest(self, emu, argv, ctx={}): return rv @apihook("WinHttpReceiveResponse", argc=2, conv=_arch.CALL_CONV_STDCALL) - def WinHttpReceiveResponse(self, emu, argv, ctx={}): + def WinHttpReceiveResponse(self, emu, argv, ctx: api.ApiContext = None): """ WINHTTPAPI BOOL WinHttpReceiveResponse( IN HINTERNET hRequest, @@ -232,7 +232,7 @@ def WinHttpReceiveResponse(self, emu, argv, ctx={}): return True @apihook("WinHttpReadData", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WinHttpReadData(self, emu, argv, ctx={}): + def WinHttpReadData(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpReadData( IN HINTERNET hRequest, @@ -258,7 +258,7 @@ def WinHttpReadData(self, emu, argv, ctx={}): return rv @apihook("WinHttpCrackUrl", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WinHttpCrackUrl(self, emu, argv, ctx={}): + def WinHttpCrackUrl(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpCrackUrl( LPCWSTR pwszUrl, @@ -301,7 +301,7 @@ def WinHttpCrackUrl(self, emu, argv, ctx={}): return rv @apihook("WinHttpAddRequestHeaders", argc=4, conv=_arch.CALL_CONV_STDCALL) - def WinHttpAddRequestHeaders(self, emu, argv, ctx={}): + def WinHttpAddRequestHeaders(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpAddRequestHeaders( HINTERNET hRequest, @@ -321,7 +321,7 @@ def WinHttpAddRequestHeaders(self, emu, argv, ctx={}): return rv @apihook("WinHttpQueryHeaders", argc=6, conv=_arch.CALL_CONV_STDCALL) - def WinHttpQueryHeaders(self, emu, argv, ctx={}): + def WinHttpQueryHeaders(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpQueryHeaders( HINTERNET hRequest, @@ -354,7 +354,7 @@ def WinHttpQueryHeaders(self, emu, argv, ctx={}): return rv @apihook("WinHttpCloseHandle", argc=1, conv=_arch.CALL_CONV_STDCALL) - def WinHttpCloseHandle(self, emu, argv, ctx={}): + def WinHttpCloseHandle(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI WinHttpCloseHandle( HINTERNET hInternet diff --git a/speakeasy/winenv/api/usermode/wininet.py b/speakeasy/winenv/api/usermode/wininet.py index aa93bd22..1e74dd9d 100644 --- a/speakeasy/winenv/api/usermode/wininet.py +++ b/speakeasy/winenv/api/usermode/wininet.py @@ -39,7 +39,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("InternetOpen", argc=5, conv=_arch.CALL_CONV_STDCALL) - def InternetOpen(self, emu, argv, ctx={}): + def InternetOpen(self, emu, argv, ctx: api.ApiContext = None): """ void InternetOpenA( LPTSTR lpszAgent, @@ -49,6 +49,7 @@ def InternetOpen(self, emu, argv, ctx={}): DWORD dwFlags ); """ + ctx = ctx or {} ua, access, proxy, bypass, flags = argv cw = self.get_char_width(ctx) @@ -67,7 +68,7 @@ def InternetOpen(self, emu, argv, ctx={}): return hnd @apihook("InternetConnect", argc=8, conv=_arch.CALL_CONV_STDCALL) - def InternetConnect(self, emu, argv, ctx={}): + def InternetConnect(self, emu, argv, ctx: api.ApiContext = None): """ void InternetConnect( HINTERNET hInternet, @@ -80,6 +81,7 @@ def InternetConnect(self, emu, argv, ctx={}): DWORD_PTR dwContext ); """ + ctx = ctx or {} hnd, server, port, user, password, service, flags, dwctx = argv cw = self.get_char_width(ctx) @@ -103,7 +105,7 @@ def InternetConnect(self, emu, argv, ctx={}): return hdl @apihook("HttpOpenRequest", argc=8, conv=_arch.CALL_CONV_STDCALL) - def HttpOpenRequest(self, emu, argv, ctx={}): + def HttpOpenRequest(self, emu, argv, ctx: api.ApiContext = None): """ void HttpOpenRequest( HINTERNET hConnect, @@ -116,6 +118,7 @@ def HttpOpenRequest(self, emu, argv, ctx={}): DWORD_PTR dwContext ); """ + ctx = ctx or {} hnd, verb, objname, ver, ref, accepts, flags, dwctx = argv cw = self.get_char_width(ctx) @@ -141,7 +144,7 @@ def HttpOpenRequest(self, emu, argv, ctx={}): return hdl @apihook("InternetCrackUrl", argc=4, conv=_arch.CALL_CONV_STDCALL) - def InternetCrackUrl(self, emu, argv, ctx={}): + def InternetCrackUrl(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI InternetCrackUrl( LPCSTR lpszUrl, @@ -150,6 +153,7 @@ def InternetCrackUrl(self, emu, argv, ctx={}): LPURL_COMPONENTSA lpUrlComponents ); """ + ctx = ctx or {} lpszUrl, dwUrlLength, dwFlags, lpUrlComponents = argv rv = False @@ -184,7 +188,7 @@ def InternetCrackUrl(self, emu, argv, ctx={}): return rv @apihook("InternetSetOption", argc=4, conv=_arch.CALL_CONV_STDCALL) - def InternetSetOption(self, emu, argv, ctx={}): + def InternetSetOption(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI InternetSetOption( HINTERNET hInternet, @@ -200,7 +204,7 @@ def InternetSetOption(self, emu, argv, ctx={}): return rv @apihook("InternetGetConnectedState", argc=2, conv=_arch.CALL_CONV_STDCALL) - def InternetGetConnectedState(self, emu, argv, ctx={}): + def InternetGetConnectedState(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI InternetGetConnectedState( LPDWORD lpdwFlags, @@ -219,7 +223,7 @@ def InternetGetConnectedState(self, emu, argv, ctx={}): return rv @apihook("HttpSendRequest", argc=5, conv=_arch.CALL_CONV_STDCALL) - def HttpSendRequest(self, emu, argv, ctx={}): + def HttpSendRequest(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI HttpSendRequest( HINTERNET hRequest, @@ -229,6 +233,7 @@ def HttpSendRequest(self, emu, argv, ctx={}): DWORD dwOptionalLength ); """ + ctx = ctx or {} hnd, headers, hdrlen, lpOptional, dwOptionalLength = argv body = b"" @@ -255,7 +260,7 @@ def HttpSendRequest(self, emu, argv, ctx={}): return rv @apihook("InternetErrorDlg", argc=5, conv=_arch.CALL_CONV_STDCALL) - def InternetErrorDlg(self, emu, argv, ctx={}): + def InternetErrorDlg(self, emu, argv, ctx: api.ApiContext = None): """ void InternetErrorDlg( HWND hWnd, @@ -270,7 +275,7 @@ def InternetErrorDlg(self, emu, argv, ctx={}): return @apihook("InternetQueryOption", argc=4) - def InternetQueryOption(self, emu, argv, ctx={}): + def InternetQueryOption(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI InternetQueryOption( HINTERNET hInternet, @@ -294,7 +299,7 @@ def InternetQueryOption(self, emu, argv, ctx={}): return rv @apihook("InternetReadFile", argc=4, conv=_arch.CALL_CONV_STDCALL) - def InternetReadFile(self, emu, argv, ctx={}): + def InternetReadFile(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI InternetReadFile( HINTERNET hFile, @@ -320,7 +325,7 @@ def InternetReadFile(self, emu, argv, ctx={}): return rv @apihook("HttpQueryInfo", argc=5) - def HttpQueryInfo(self, emu, argv, ctx={}): + def HttpQueryInfo(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI HttpQueryInfo( HINTERNET hRequest, @@ -330,6 +335,7 @@ def HttpQueryInfo(self, emu, argv, ctx={}): LPDWORD lpdwIndex ); """ + ctx = ctx or {} hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex = argv cw = self.get_char_width(ctx) @@ -355,7 +361,7 @@ def HttpQueryInfo(self, emu, argv, ctx={}): return rv @apihook("InternetQueryDataAvailable", argc=4) - def InternetQueryDataAvailable(self, emu, argv, ctx={}): + def InternetQueryDataAvailable(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI InternetQueryDataAvailable( HINTERNET hFile, @@ -377,7 +383,7 @@ def InternetQueryDataAvailable(self, emu, argv, ctx={}): return rv @apihook("InternetCloseHandle", argc=1) - def InternetCloseHandle(self, emu, argv, ctx={}): + def InternetCloseHandle(self, emu, argv, ctx: api.ApiContext = None): """ BOOLAPI InternetCloseHandle( HINTERNET hInternet @@ -391,7 +397,7 @@ def InternetCloseHandle(self, emu, argv, ctx={}): return rv @apihook("InternetOpenUrl", argc=6) - def InternetOpenUrl(self, emu, argv, ctx={}): + def InternetOpenUrl(self, emu, argv, ctx: api.ApiContext = None): """ void InternetOpenUrlA( HINTERNET hInternet, @@ -402,6 +408,7 @@ def InternetOpenUrl(self, emu, argv, ctx={}): DWORD_PTR dwContext ); """ + ctx = ctx or {} hInternet, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext = argv cw = self.get_char_width(ctx) if lpszUrl: diff --git a/speakeasy/winenv/api/usermode/winmm.py b/speakeasy/winenv/api/usermode/winmm.py index ff7a0896..c77bd514 100644 --- a/speakeasy/winenv/api/usermode/winmm.py +++ b/speakeasy/winenv/api/usermode/winmm.py @@ -18,7 +18,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("timeGetTime", argc=0) - def timeGetTime(self, emu, argv, ctx={}): + def timeGetTime(self, emu, argv, ctx: api.ApiContext = None): """ DWORD timeGetTime(); // return the system time, in milliseconds """ diff --git a/speakeasy/winenv/api/usermode/wkscli.py b/speakeasy/winenv/api/usermode/wkscli.py index 627b48ea..9993cff5 100644 --- a/speakeasy/winenv/api/usermode/wkscli.py +++ b/speakeasy/winenv/api/usermode/wkscli.py @@ -19,7 +19,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("NetGetJoinInformation", argc=3) - def NetGetJoinInformation(self, emu, argv, ctx={}): + def NetGetJoinInformation(self, emu, argv, ctx: api.ApiContext = None): """ NET_API_STATUS NET_API_FUNCTION NetGetJoinInformation( LPCWSTR lpServer, diff --git a/speakeasy/winenv/api/usermode/ws2_32.py b/speakeasy/winenv/api/usermode/ws2_32.py index 96221434..a8c7d3ae 100644 --- a/speakeasy/winenv/api/usermode/ws2_32.py +++ b/speakeasy/winenv/api/usermode/ws2_32.py @@ -40,7 +40,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("WSAStartup", argc=2, conv=_arch.CALL_CONV_STDCALL, ordinal=115) - def WSAStartup(self, emu, argv, ctx={}): + def WSAStartup(self, emu, argv, ctx: api.ApiContext = None): """ int WSAStartup( WORD wVersionRequired, @@ -63,7 +63,7 @@ def WSAStartup(self, emu, argv, ctx={}): return rv @apihook("WSACleanup", argc=0, ordinal=116) - def WSACleanup(self, emu, argv, ctx={}): + def WSACleanup(self, emu, argv, ctx: api.ApiContext = None): """ int WSACleanup(); """ @@ -71,7 +71,7 @@ def WSACleanup(self, emu, argv, ctx={}): return 0 @apihook("WSASocket", argc=6) - def WSASocket(self, emu, argv, ctx={}): + def WSASocket(self, emu, argv, ctx: api.ApiContext = None): """ SOCKET WSAAPI WSASocket( int af, @@ -97,7 +97,7 @@ def WSASocket(self, emu, argv, ctx={}): return fd @apihook("WSAIoctl", argc=9, conv=_arch.CALL_CONV_STDCALL) - def WSAIoctl(self, emu, argv, ctx={}): + def WSAIoctl(self, emu, argv, ctx: api.ApiContext = None): """ int WSAAPI WSAIoctl( SOCKET s, @@ -117,7 +117,7 @@ def WSAIoctl(self, emu, argv, ctx={}): return windefs.ERROR_SUCCESS @apihook("WSAConnect", argc=7, conv=_arch.CALL_CONV_STDCALL) - def WSAConnect(self, emu, argv, ctx={}): + def WSAConnect(self, emu, argv, ctx: api.ApiContext = None): """ int WSAAPI WSAConnect( SOCKET s, @@ -129,13 +129,14 @@ def WSAConnect(self, emu, argv, ctx={}): LPQOS lpGQOS ); """ + ctx = ctx or {} # TODO: Add actual function logic. However, for now, just call connect() return self.connect(emu, argv[:3], ctx) @apihook("socket", argc=3, conv=_arch.CALL_CONV_STDCALL, ordinal=23) - def socket(self, emu, argv, ctx={}): + def socket(self, emu, argv, ctx: api.ApiContext = None): """ SOCKET WSAAPI socket( int af, @@ -158,7 +159,7 @@ def socket(self, emu, argv, ctx={}): return fd @apihook("inet_addr", argc=1, ordinal=11) - def inet_addr(self, emu, argv, ctx={}): + def inet_addr(self, emu, argv, ctx: api.ApiContext = None): """ unsigned long inet_addr( _In_ const char *cp @@ -178,7 +179,7 @@ def inet_addr(self, emu, argv, ctx={}): return rv @apihook("htons", argc=1, conv=_arch.CALL_CONV_STDCALL, ordinal=9) - def htons(self, emu, argv, ctx={}): + def htons(self, emu, argv, ctx: api.ApiContext = None): """ u_short htons( u_short hostshort @@ -191,7 +192,7 @@ def htons(self, emu, argv, ctx={}): return netshort @apihook("ntohs", argc=1, ordinal=15) - def ntohs(self, emu, argv, ctx={}): + def ntohs(self, emu, argv, ctx: api.ApiContext = None): """ u_short ntohs( u_short netshort @@ -202,7 +203,7 @@ def ntohs(self, emu, argv, ctx={}): return ntohs(netshort) @apihook("ntohl", argc=1, ordinal=14) - def ntohl(self, emu, argv, ctx={}): + def ntohl(self, emu, argv, ctx: api.ApiContext = None): """ u_long ntohl( u_long netlong @@ -213,7 +214,7 @@ def ntohl(self, emu, argv, ctx={}): return ntohl(netlong) @apihook("setsockopt", argc=5, ordinal=21) - def setsockopt(self, emu, argv, ctx={}): + def setsockopt(self, emu, argv, ctx: api.ApiContext = None): """ int setsockopt( SOCKET s, @@ -241,7 +242,7 @@ def setsockopt(self, emu, argv, ctx={}): return rv @apihook("WSASetLastError", argc=1, ordinal=112) - def WSASetLastError(self, emu, argv, ctx={}): + def WSASetLastError(self, emu, argv, ctx: api.ApiContext = None): """ void WSASetLastError( int iError @@ -253,7 +254,7 @@ def WSASetLastError(self, emu, argv, ctx={}): return @apihook("gethostname", argc=2, ordinal=57) - def gethostname(self, emu, argv, ctx={}): + def gethostname(self, emu, argv, ctx: api.ApiContext = None): """ int gethostname( char *name, @@ -276,7 +277,7 @@ def gethostname(self, emu, argv, ctx={}): return rv @apihook("gethostbyname", argc=1, conv=_arch.CALL_CONV_STDCALL, ordinal=52) - def gethostbyname(self, emu, argv, ctx={}): + def gethostbyname(self, emu, argv, ctx: api.ApiContext = None): """ struct hostent * gethostbyname(const char FAR * name); """ @@ -318,7 +319,7 @@ def gethostbyname(self, emu, argv, ctx={}): return ptr_hostent @apihook("connect", argc=3, conv=_arch.CALL_CONV_STDCALL, ordinal=4) - def connect(self, emu, argv, ctx={}): + def connect(self, emu, argv, ctx: api.ApiContext = None): """ int WSAAPI connect( SOCKET s, @@ -358,7 +359,7 @@ def connect(self, emu, argv, ctx={}): return rv @apihook("bind", argc=3, ordinal=2) - def bind(self, emu, argv, ctx={}): + def bind(self, emu, argv, ctx: api.ApiContext = None): """ int bind( SOCKET s, @@ -392,7 +393,7 @@ def bind(self, emu, argv, ctx={}): return rv @apihook("listen", argc=2, ordinal=13) - def listen(self, emu, argv, ctx={}): + def listen(self, emu, argv, ctx: api.ApiContext = None): """ int WSAAPI listen( SOCKET s, @@ -405,7 +406,7 @@ def listen(self, emu, argv, ctx={}): return rv @apihook("select", argc=5, ordinal=18) - def select(self, emu, argv, ctx={}): + def select(self, emu, argv, ctx: api.ApiContext = None): """ int WSAAPI select( int nfds, @@ -436,7 +437,7 @@ def select(self, emu, argv, ctx={}): return fd_count @apihook("accept", argc=3, ordinal=1) - def accept(self, emu, argv, ctx={}): + def accept(self, emu, argv, ctx: api.ApiContext = None): """ SOCKET WSAAPI accept( SOCKET s, @@ -479,7 +480,7 @@ def accept(self, emu, argv, ctx={}): return new_sock.fd @apihook("inet_ntoa", argc=1, ordinal=12) - def inet_ntoa(self, emu, argv, ctx={}): + def inet_ntoa(self, emu, argv, ctx: api.ApiContext = None): """ char FAR* inet_ntoa(struct in_addr in); """ @@ -494,7 +495,7 @@ def inet_ntoa(self, emu, argv, ctx={}): return buf @apihook("inet_ntop", argc=4, ordinal=180) - def inet_ntop(self, emu, argv, ctx={}): + def inet_ntop(self, emu, argv, ctx: api.ApiContext = None): """ PCSTR WSAAPI inet_ntop( [in] INT Family, @@ -523,7 +524,7 @@ def inet_ntop(self, emu, argv, ctx={}): return 0 @apihook("inet_pton", argc=3, ordinal=181) - def inet_pton(self, emu, argv, ctx={}): + def inet_pton(self, emu, argv, ctx: api.ApiContext = None): """ INT WSAAPI inet_pton( [in] INT Family, @@ -552,7 +553,7 @@ def inet_pton(self, emu, argv, ctx={}): return 0 @apihook("htonl", argc=1, ordinal=8) - def htonl(self, emu, argv, ctx={}): + def htonl(self, emu, argv, ctx: api.ApiContext = None): """ uint32_t htonl(uint32_t hostlong); """ @@ -560,7 +561,7 @@ def htonl(self, emu, argv, ctx={}): return htonl(hostlong) @apihook("__WSAFDIsSet", argc=2, ordinal=151) - def __WSAFDIsSet(self, emu, argv, ctx={}): + def __WSAFDIsSet(self, emu, argv, ctx: api.ApiContext = None): """ int __WSAFDIsSet( SOCKET , @@ -571,7 +572,7 @@ def __WSAFDIsSet(self, emu, argv, ctx={}): return 1 @apihook("shutdown", argc=2, ordinal=22) - def shutdown(self, emu, argv, ctx={}): + def shutdown(self, emu, argv, ctx: api.ApiContext = None): """ int shutdown( SOCKET s, @@ -581,7 +582,7 @@ def shutdown(self, emu, argv, ctx={}): return 0 @apihook("recv", argc=4, ordinal=16) - def recv(self, emu, argv, ctx={}): + def recv(self, emu, argv, ctx: api.ApiContext = None): """ int recv( SOCKET s, @@ -617,7 +618,7 @@ def recv(self, emu, argv, ctx={}): return rv @apihook("send", argc=4, ordinal=19) - def send(self, emu, argv, ctx={}): + def send(self, emu, argv, ctx: api.ApiContext = None): """ int WSAAPI send( SOCKET s, @@ -648,7 +649,7 @@ def send(self, emu, argv, ctx={}): return len(data) @apihook("closesocket", argc=1, ordinal=3) - def closesocket(self, emu, argv, ctx={}): + def closesocket(self, emu, argv, ctx: api.ApiContext = None): """ int closesocket( IN SOCKET s @@ -668,7 +669,7 @@ def closesocket(self, emu, argv, ctx={}): return rv @apihook("ioctlsocket", argc=3, ordinal=10) - def ioctlsocket(self, emu, argv, ctx={}): + def ioctlsocket(self, emu, argv, ctx: api.ApiContext = None): """ int ioctlsocket( SOCKET s, @@ -686,7 +687,7 @@ def ioctlsocket(self, emu, argv, ctx={}): return rv @apihook("getaddrinfo", argc=4, ordinal=178) - def getaddrinfo(self, emu, argv, ctx={}): + def getaddrinfo(self, emu, argv, ctx: api.ApiContext = None): """ INT WSAAPI getaddrinfo( PCSTR pNodeName, @@ -754,7 +755,7 @@ def getaddrinfo(self, emu, argv, ctx={}): return rv @apihook("freeaddrinfo", argc=1, ordinal=177) - def freeaddrinfo(self, emu, argv, ctx={}): + def freeaddrinfo(self, emu, argv, ctx: api.ApiContext = None): """ VOID WSAAPI freeaddrinfo( PADDRINFOA pAddrInfo @@ -765,7 +766,7 @@ def freeaddrinfo(self, emu, argv, ctx={}): return @apihook("getsockopt", argc=5, ordinal=7) - def getsockopt(self, emu, argv, ctx={}): + def getsockopt(self, emu, argv, ctx: api.ApiContext = None): """ int getsockopt( SOCKET s, diff --git a/speakeasy/winenv/api/usermode/wtsapi32.py b/speakeasy/winenv/api/usermode/wtsapi32.py index 3d1e16dd..d99e0934 100644 --- a/speakeasy/winenv/api/usermode/wtsapi32.py +++ b/speakeasy/winenv/api/usermode/wtsapi32.py @@ -29,7 +29,7 @@ def __init__(self, emu): super().__get_hook_attrs__(self) @apihook("WTSEnumerateSessions", argc=5, conv=_arch.CALL_CONV_STDCALL) - def WTSEnumerateSessions(self, emu, argv, ctx={}): + def WTSEnumerateSessions(self, emu, argv, ctx: api.ApiContext = None): """ BOOL WTSEnumerateSessions( IN HANDLE hServer, @@ -39,6 +39,7 @@ def WTSEnumerateSessions(self, emu, argv, ctx={}): DWORD *pCount ); """ + ctx = ctx or {} hServer, res, ver, ppSessionInfo, pCount = argv rv = 0 @@ -78,7 +79,7 @@ def WTSEnumerateSessions(self, emu, argv, ctx={}): return rv @apihook("WTSFreeMemory", argc=1, conv=_arch.CALL_CONV_STDCALL) - def WTSFreeMemory(self, emu, argv, ctx={}): + def WTSFreeMemory(self, emu, argv, ctx: api.ApiContext = None): """ void WTSFreeMemory( IN PVOID pMemory