Commit Graph

61 Commits

Author SHA1 Message Date
Maurice Heumann
608a0cf0ec Improve Windows version detection and LdrSystemDllInitBlock initialization (#697)
- Add WINDOWS_VERSION enum and PS_SYSTEM_DLL_INIT_BLOCK sizes for WOW64
support across different Windows builds.
- Read system information (SystemRoot, BuildNumber, UpdateBuildRevision)
from registry instead of hardcoded paths.
- Add build comparison helpers in process_context for precise build
checks.
2026-01-14 07:14:06 +01:00
Igor Pissolati
2c93915ecc Make Atom case-insensitive 2026-01-11 17:12:15 -03:00
Igor Pissolati
f5fe795028 Fix inadvertent stack pointer overwriting in callback hook 2026-01-11 17:11:17 -03:00
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
brian
0a414ca346 Extract Windows version management into separate module 2026-01-09 16:44:48 +08: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
brian
456dc99fb6 Improve Windows version detection and LdrSystemDllInitBlock initialization
- Add WINDOWS_VERSION enum and PS_SYSTEM_DLL_INIT_BLOCK sizes for WOW64 support across different Windows builds.
- Read system information (SystemRoot, BuildNumber, UpdateBuildRevision) from registry instead of hardcoded paths.
- Add build comparison helpers in process_context for precise build checks.
2026-01-09 00:38:03 +08:00
Igor Pissolati
9fdc2a4ce6 Add support for user callbacks 2026-01-06 10:14:02 -03: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
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
Igor Pissolati
7112d619b4 Fix clang tidy 2026-01-04 16:28:30 -03: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
ahm3dgg
a3d019c759 Set PEB64/32 HeapSegmentReserve & HeapSegmentCommit from Executable. 2026-01-04 20:24:22 +02:00
Igor Pissolati
de491ade0e Add support for user_object/user_handle_table 2026-01-02 19:46:04 -03:00
ssvine
7724b0d416 Refactor emulator_object 2026-01-02 19:03:54 +03:00
Maurice Heumann
1f936c024d Fix thread support (#640)
This PR fixes several things related to threads emulation:

1. Support `SameTebFlags.InitialThread`
This flag is needed to support emulation of .net executables (not yet
fully supported) that don't have an entry point set in `PE` header. This
applies to both `PE32` and `PE64` executables. If `InitialThread` is set
the loader substitutes an entry point of the .net executable with
`mscoree.dll!_CorExeMain`.

2. Fix static thread local storage for `WOW64`
This fix resolves `shell32.dll` initialization on `WOW64`. This fix also
uses correct structure and field names that are obtained from the
corresponding `.pdb` files.

3. Fix dynamic thread local storage for `WOW64`

4. Fix setting argument of a `WOW64` thread start proc

5. Fix creating suspended thread and parse create_flags
Currently creating suspended thread doesn't work because
`NtCreateThreadEx` handler uses invalid flag `CREATE_SUSPENDED`. This PR
fixes that, and moreover it carefully parses create_flags of the
`NtCreateThreadEx` call.

6. Fix `FS` and `GS` handling
This PR fixes several problems with `GS` and `FS` segments:

    * Wrong GDT descriptor for selector 0x53
* Update GDT descriptor for selector 0x53 for a `WOW64` process every
context switch like Windows does
* Set `GS` base when `GS` segment register is updated in 64-bit code
(code selector is `0x33`). When `GS` segment register is loaded with
correct selector (`0x2b`) `GS` base is set to 0. So, when the code
accesses something like `gs:[0]`, a page fault occurs. `KiPageFault`
handles this situation and sets correct `GS` base.

Also, take into account that `teb64.ExceptionList` initially contains
`teb32` address for `WOW64` process. This is used to setup `FS` base
when `wrfsbase` instruction is available. We can enable this instruction
using `kusd.ProcessorFeatures.arr[PF_RDWRFSGSBASE_AVAILABLE] = 1;` and
this work perfectly with `unicorn` backend. Unfortunately `icicle`
backend does not support `wrfsbase`, so I don't enable this instruction
by default.
2025-12-30 17:56:30 +01:00
ssvine
57ad277158 Fix creating suspended thread and parse create_flags 2025-12-30 15:18:55 +03:00
ssvine
fea27338bb Support SameTebFlags.InitialThread
This flag is needed to suport emulation of .net executables
that don't have an entry point set in PE header. This applies
to both PE32 and PE64 executables. If InitialThread is set
the loader substitutes an entry point of the .net executable
with mscoree.dll!_CorExeMain.
2025-12-30 13:44:21 +03:00
66hh
ecc00216d6 Support ProcessInstrumentationCallback 2025-12-27 17:17:23 +08:00
ssvine
3686625fb1 Fix PEB32 2025-12-25 13:42:20 +03:00
brian
5171ef63dc Fix deserialization of optional WOW64 emulator_object members (PEB32/params32) 2025-12-05 20:21:25 +08:00
brian
65eecf1cfd Comprehensive WOW64 subsystem implementation 2025-10-13 19:55:50 +08:00
momo5502
5a3d05c64c Fix compilation 2025-08-18 19:16:43 +02:00
momo5502
8e984b8b29 Keep GDTR readable for now 2025-08-18 19:07:12 +02:00
momo5502
2cef0a5511 Make sure GDTR is page aligned 2025-08-18 19:01:09 +02:00
momo5502
584b770def Store previous IP per thread 2025-08-17 07:32:26 +02:00
momo5502
b2eef2bf46 Align processor counts 2025-08-17 07:31:37 +02:00
momo5502
7d6648ade0 Extend clang-format column limit to 140 2025-08-16 14:55:07 +02:00
3fault
e5e5d05d05 Add temp environment variables to fix GetTempPath(2)W 2025-06-10 09:59:34 -04:00
momo5502
da4a4f90c9 Cleanup exception callbacks 2025-06-07 07:54:11 +02:00
momo5502
802e295bcc Adapt more printing 2025-06-07 07:29:30 +02:00
momo5502
da658e5178 Prepare timer support 2025-06-01 13:56:45 +02:00
momo5502
67031b40ea More UI syscalls 2025-05-18 10:35:22 +02:00
momo5502
0fbd563e8c Support window creation 2025-05-18 09:51:28 +02:00
momo5502
bd4e27469f Add more ui syscall stubs 2025-05-17 18:28:53 +02:00
Igor Pissolati
bab8c55ed3 Disable Trap Test on icicle 2025-04-28 19:27:56 -03:00
Igor Pissolati
b67a512ea6 Properly expand REG_EXPAND_SZ keys 2025-04-28 15:24:49 -03:00
Igor Pissolati
9d5338b168 Load environment variables from registry 2025-04-28 12:46:36 -03:00
robert-yates
b2296930d3 prepare 32bit support with name and class inheritance modifications 2025-04-22 12:01:40 +02:00
Igor Pissolati
657bf6121a Apply suggested changes 2025-04-22 03:44:45 -03:00
Igor Pissolati
6deefb932f Add NtUserGetAtomName syscall 2025-04-22 01:19:05 -03:00
Igor Pissolati
3dfad0f789 Add more atom-related syscalls 2025-04-19 13:52:13 -03:00
Maurice Heumann
0e9cffa5cb More 32 bit fixes 2025-04-14 14:34:06 +02:00
momo5502
a8926592bc Prepare APC dispatching 2025-04-13 13:39:09 +02:00
RektInator
8bc49bdd03 refactor(windows-emulator/syscalls): partial refactor of syscalls.cpp, splits syscall implementations over multiple files 2025-04-11 16:42:00 +02:00
Maurice Heumann
67d34b3988 Small fix 2025-04-08 10:17:05 +02:00
momo5502
3c58c1af98 Log debug strings 2025-04-07 21:03:57 +02:00