Commit Graph

34 Commits

Author SHA1 Message Date
thejanit0r
29b8ec4072 Added additional vmp compatibility 2026-01-04 09:33:54 +01:00
ssvine
254475e308 Don't read null ptr in NtDelayExecution 2026-01-02 17:36:05 +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
1ebe5356c9 Fix dynamic TLS for WOW64 2025-12-30 15:18:33 +03:00
66hh
536f2ce883 Adjust variable order 2025-12-29 00:54:31 +08:00
66hh
3cd461e2ab Add the debugger_hide attribute to emulator_thread 2025-12-29 00:52:59 +08:00
momo5502
66cfe980d7 Ignore ThreadPriorityBoost 2025-12-22 14:39:44 +01:00
brian
65eecf1cfd Comprehensive WOW64 subsystem implementation 2025-10-13 19:55:50 +08:00
momo5502
7d6648ade0 Extend clang-format column limit to 140 2025-08-16 14:55:07 +02:00
momo5502
ac2d34c143 Small cleanup 2025-07-12 15:40:04 +02:00
momo5502
05c5f0a085 Final cleanup 2025-06-07 08:01:02 +02: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
956e73d839 Some fixes 2025-06-04 20:47:51 +02:00
momo5502
1f829463c1 Use more semantic logging 2025-06-04 20:22:28 +02:00
momo5502
84e8e86b94 Extract sus activity logging 2025-06-04 19:28:50 +02:00
Igor Pissolati
c67146ee45 Add new syscalls 2025-06-02 14:32:15 -03:00
momo5502
d08bcbae9c Add window object 2025-05-18 09:13:26 +02:00
Igor Pissolati
08098da538 Skip ThreadAffinityMask in NtSetInformationThread 2025-04-22 01:25:15 -03:00
Igor Pissolati
c702bedaee Add 3 new syscall handlers 2025-04-19 16:33:34 -03:00
Maurice Heumann
0e9cffa5cb More 32 bit fixes 2025-04-14 14:34:06 +02:00
RektInator
6379370a50 fix(syscalls): fix VirtualQuery return size, ignore unimplemented APC flags and log a warning. 2025-04-14 12:43:11 +02:00
RektInator
7bf0b67167 wip 2025-04-14 12:23:08 +02:00
momo5502
7910021124 Fix apc dispatching 2025-04-13 14:28:35 +02:00
momo5502
30e77f5f9a Fix NtQueueApcThreadEx 2025-04-13 14:12:14 +02:00
momo5502
a3f811a466 Support all APC queue syscalls 2025-04-13 13:39:09 +02:00
momo5502
c1e621c2cd Basic hacky working APC dispatching 2025-04-13 13:39:09 +02:00
momo5502
a8926592bc Prepare APC dispatching 2025-04-13 13:39:09 +02:00
momo5502
bb4b159850 Implement NtQueueApcThreadEx2 2025-04-13 13:39:09 +02:00
momo5502
82227e4d41 Prepare NtQueueApcThreadEx2 support 2025-04-13 13:39:08 +02:00
momo5502
c0252a5f71 Add partial NtContinueEx support 2025-04-13 13:39:08 +02:00
momo5502
f58dec38a2 Prepare APC support 2025-04-13 13:39:08 +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