2593 Commits

Author SHA1 Message Date
Maurice Heumann
d70ab2607e Add support for user callbacks (#691)
This PR is my attempt to add support for user callbacks in the emulator.
User callbacks allow the emulator to call guest callbacks from syscalls,
and when the callback finishes running, control returns to the syscall
through the completion method. I've also added a test and implemented
the NtUserEnumDisplayMonitors syscall.

One thing to note is that this implementation isn't faithful to how the
Windows kernel does it, since the kernel uses the KernelCallbackTable
and the `ntdll!KiUserCallbackDispatch` method, and this implementation
currently just calls the callback directly.
2026-01-10 13:59:24 +01:00
Maurice Heumann
f7eb8a2b2d Fix memory_manager serialization (#699)
This PR fixes `memory_manager` serialization. In particular, it fixes
running `WOW64` programs from snapshots.
2026-01-10 13:58:39 +01:00
ssvine
c49226d7c1 Fix memory_manager serialization 2026-01-10 14:13:09 +03:00
Maurice Heumann
83a6b65add Fix user_handle_table memory handling (#696)
This PR fixes `user_handle_table` for WOW64. Otherwise we get AV during
32-bit `user32.dll` initialization.
2026-01-09 14:45:25 +01:00
ssvine
dd31b6344f Fix user_handle_table memory handling 2026-01-09 10:51:09 +03:00
Igor Pissolati
d33ef2d93f Avoid memory hook being triggered twice for the same callback 2026-01-08 16:59:09 -03:00
Maurice Heumann
9090e29e21 Revert "module manager: safer ldr init block setup" (#695)
The change from fixed size 0xF0 to sizeof(PS_SYSTEM_DLL_INIT_BLOCK)
(which is 0x128 for V3 struct) causes memory corruption when using
Windows 10 system files.

**Before (working):**
```
constexpr uint64_t symtem_dll_init_block_fix_size = 0xF0; // Wine or WIN10
init_block.Size = symtem_dll_init_block_fix_size;
// ...
this->memory_->write_memory(ldr_init_block_addr, &init_block, symtem_dll_init_block_fix_size);
```

**After (broken):**
```
constexpr uint64_t system_dll_init_block_size = sizeof(PS_SYSTEM_DLL_INIT_BLOCK);  // = 0x128
init_block.Size = system_dll_init_block_size;
// ...
this->memory_->write_memory(ldr_init_block_addr, &init_block, write_size);
```

**Symptom:**
```
Executing syscall: NtQueryVirtualMemory (0x23) at 0x18009d442 via 0x1800d4920 (ntdll.dll)
Interrupt 41
Suspicious: Breakpoint at 0x1800ac7d8 (via 0x1800ac7d5)
Executing syscall: NtQueryVirtualMemory (0x23) at 0x18009d442 via 0x180033579 (ntdll.dll)
Executing syscall: NtQueryVirtualMemory (0x23) at 0x18009d442 via 0x180033579 (ntdll.dll)
Executing syscall: NtQueryVirtualMemory (0x23) at 0x18009d442 via 0x180033579 (ntdll.dll)
Executing syscall: NtQueryVirtualMemory (0x23) at 0x18009d442 via 0x180033579 (ntdll.dll)
Bad address for memory image request: 0x5f0000
Executing syscall: NtRaiseException (0x168) at 0x18009fcd2 via 0x1800a0ee3 (ntdll.dll)
!!! NtRaiseException: Code=0x80000003, Flags=0x0, Address=0x1800ac7d7, NumParams=0, HandleException=0
Emulation terminated without status!
```

**Root cause:** PS_SYSTEM_DLL_INIT_BLOCK has different sizes across
Windows versions. It needs to detect the Windows version from ntdll and
use the appropriate size. I will submit a PR to fix this issue soon.
2026-01-08 11:42:34 +01:00
Brian Wynn
7ba5a7b2e4 Revert "module manager: safer ldr init block setup" 2026-01-08 17:37:01 +08:00
Igor Pissolati
d5d73f42c9 Improve clarity in dispatch_user_callback 2026-01-07 15:01:02 -03:00
Maurice Heumann
01851ad571 Update description for Security Research section 2026-01-07 08:02:34 +01:00
Maurice Heumann
e7abe50f00 module manager: safer ldr init block setup (#693) 2026-01-07 07:50:23 +01:00
redthing1
4e5ba450c1 module manager: safer ldr init block setup 2026-01-06 17:57:34 -08:00
momo5502
ff99a1cb56 Log writes to the import table 2026-01-06 14:41:34 +01:00
Igor Pissolati
9fdc2a4ce6 Add support for user callbacks 2026-01-06 10:14:02 -03:00
Maurice Heumann
7c912146fb Cleanup common header includes (#690) 2026-01-06 11:46:07 +01:00
momo5502
45ac1fc32f Cleanup headers 2026-01-06 11:29:39 +01:00
Maurice Heumann
5d81d8bda9 Implement NtQueryMultipleValueKey (#684)
This PR implements `NtQueryMultipleValueKey` that is used in calls like
`RegQueryMultipleValues`.
2026-01-06 10:38:10 +01:00
Maurice Heumann
e46e8dcf7a more object syscalls (#687) 2026-01-06 10:30:47 +01:00
Maurice Heumann
1a613be667 ports: add noop port stub for WER (#689) 2026-01-06 10:22:49 +01:00
Maurice Heumann
d3af3c781c Add support for user_object/user_handle_table (#677)
Fixes #641

This PR is my attempt to add support for user32 objects and the user32
handle table. I also added a test, but as expected, it fails on Windows
2022. I’ll try to fix that another day, but feel free to review the code
😄
2026-01-06 10:21:58 +01:00
redthing1
17d1e23b60 syscalls.cpp: clang format 2026-01-05 23:15:02 -08:00
redthing1
1be74c4cde ports: add noop port stub for WER 2026-01-05 23:12:53 -08:00
redthing1
51034297bf object syscalls: wire up the new syscalls 2026-01-05 23:08:21 -08:00
redthing1
a2a119aec2 object syscalls: implement NtCompareObjects 2026-01-05 23:08:18 -08:00
redthing1
6f8dca6614 object syscalls: implement NtWaitForMultipleObjects32 2026-01-05 23:08:14 -08:00
redthing1
cafa0ebd0b NTSTATUS: add STATUS_NOT_SAME_OBJECT 2026-01-05 23:08:05 -08:00
Igor Pissolati
90b38b3bff Fix user_handle_table initialization 2026-01-05 09:01:05 -03:00
Igor Pissolati
5d59700ec7 Remove parse_number 2026-01-05 09:00:45 -03:00
ssvine
37c2184bfc Implement NtQueryMultipleValueKey 2026-01-05 13:11:35 +03:00
Maurice Heumann
e0c386abbb Fix: update page protection when re-committing already committed memory regions (#683) 2026-01-05 08:18:20 +01:00
brian
565b499350 Fix: update page protection when re-committing already committed memory regions 2026-01-05 14:39:28 +08:00
Igor Pissolati
d51f890197 Use vector instead of large array 2026-01-04 22:51:19 -03:00
Maurice Heumann
dd56acc2b4 Set PEB64/32 HeapSegmentReserve & HeapSegmentCommit from Executable. (#682) 2026-01-04 22:33:35 +01:00
ahm3dgg
3e7813b269 Merge branch 'patch' of github.com:ahm3dgg/sogen into patch 2026-01-04 21:38:11 +02:00
ahm3dgg
cf2dacb304 Fixed Types for Heap Related Fields in PEB64 2026-01-04 21:37:13 +02:00
Igor Pissolati
7112d619b4 Fix clang tidy 2026-01-04 16:28:30 -03:00
ahmed
ce73ef2b6c Merge branch 'momo5502:main' into patch 2026-01-04 21:06:46 +02:00
Igor Pissolati
5302900a9d Fix for older Windows builds 2026-01-04 16:01:13 -03:00
ahm3dgg
e17204552f fix warning 2026-01-04 20:59:02 +02:00
Maurice Heumann
f218ec5d1d Fix virtual memory semantics and refactor region policy (#681) 2026-01-04 19:46:14 +01:00
ahm3dgg
a3d019c759 Set PEB64/32 HeapSegmentReserve & HeapSegmentCommit from Executable. 2026-01-04 20:24:22 +02:00
Brian Wynn
2b0277cf6b Update src/windows-emulator/syscalls/section.cpp
Co-authored-by: Maurice Heumann <MauriceHeumann@gmail.com>
2026-01-04 23:14:35 +08:00
Maurice Heumann
ec0d626a96 Added additional vmp compatibility (#679) 2026-01-04 15:01:35 +01:00
thejanit0r
3b68260921 Fixed build errors 2026-01-04 14:53:53 +01:00
thejanit0r
f524a8cc38 Fixed clang-tidy errors 2026-01-04 14:47:08 +01:00
thejanit0r
497a4e98cb Fixed formatting 2026-01-04 13:35:54 +01:00
Maurice Heumann
e396192fbb Added support for NtCreateDirectoryObject (#678) 2026-01-04 13:12:04 +01:00
thejanit0r
0688a2cb98 Fixed formatting 2026-01-04 13:37:23 +01:00
brian
600d12f983 Fix clang tidy errors 2026-01-04 18:31:15 +08:00
brian
ea1bbb8b82 Add MEM_IMAGE define 2026-01-04 18:21:07 +08:00