Skip to content

Commit 1cc9bcb

Browse files
fix: use memory-mapped image for API module decoy PEs
The ApiModuleLoader was writing raw PE file bytes into emulated memory, but PE sections have different file offsets vs virtual addresses. Shellcode that walks the PEB InInitializationOrderModuleList to find kernel32 and then parses its export directory would read garbage because the .edata section data was at its file offset rather than its virtual address. Use pefile's get_memory_mapped_image() so sections are placed at their correct virtual addresses, matching how Windows loads DLLs. Also fixes Process.ldr_entries being a shared class-level mutable default instead of a per-instance list, and corrects the test config module order to list ntdll before kernel32 (matching the default config). Closes #45 remove unnecessary test file
1 parent b67754b commit 1cc9bcb

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

speakeasy/windows/objman.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ def __init__(self, emu, pe=None, user_modules=None, name="", path="", cmdline=""
477477
list_entry = self.address + 0x188
478478
self.emu.mem_write(list_entry, list_entry.to_bytes(8, "little"))
479479
self.emu.mem_write(list_entry + 8, list_entry.to_bytes(8, "little"))
480+
self.ldr_entries: list[LdrDataTableEntry] = []
480481
self.name: str = name
481482
self.base: int = base
482483
self.pid: int = self.id

tests/test.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,16 @@
296296
],
297297

298298
"user_modules": [
299-
{
300-
"name": "kernel32",
301-
"base_addr": "0x77000000",
302-
"path": "C:\\Windows\\system32\\kernel32.dll"
303-
},
304299
{
305300
"name": "ntdll",
306301
"base_addr": "0x7C000000",
307302
"path": "C:\\Windows\\system32\\ntdll.dll"
308303
},
304+
{
305+
"name": "kernel32",
306+
"base_addr": "0x77000000",
307+
"path": "C:\\Windows\\system32\\kernel32.dll"
308+
},
309309

310310
{
311311
"name": "ws2_32",

0 commit comments

Comments
 (0)