Commit Graph

189 Commits

Author SHA1 Message Date
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
ssvine
04ff582fa9 Fix static TLS for WOW64
This fix resolves shell32.dll TLS problems.
Also it uses correct structure and field names
2025-12-30 15:18:18 +03:00
66hh
d83c602f19 Change data type to fix 32-bit build 2025-12-28 12:40:51 +08:00
66hh
95b17566a0 Add NtRaiseHardError error message logging 2025-12-27 17:17:24 +08:00
66hh
ecc00216d6 Support ProcessInstrumentationCallback 2025-12-27 17:17:23 +08:00
ssvine
8438a1f456 Support extended variant of ProcessBasicInformation 2025-12-24 18:33:49 +03:00
momo5502
db3a89a0da Support KeyCachedInformation 2025-12-23 09:31:10 +01:00
momo5502
2be5f73755 Support ProcessPriorityClass in NtQueryInformationProcess 2025-11-20 18:25:33 +01:00
momo5502
ed7c7085b4 Fix formatting 2025-11-01 10:34:26 +01:00
momo5502
cb4fe6c30f Merge remote-tracking branch 'origin/main' into wow64 2025-10-25 11:06:03 +02:00
Igor Pissolati
2c82277b5e Add FileIdInformation file info class 2025-10-23 11:19:17 -03:00
Igor Pissolati
4fbd65a302 Fix DISPLAY_DEVICEW value 2025-10-22 17:17:02 -03:00
Igor Pissolati
54ebbe27c2 Implement NtUserEnumDisplaySettings syscall 2025-10-22 17:16:10 -03:00
Igor Pissolati
c8a18cf61c Add FileIsRemoteDeviceInformation file info class 2025-10-22 17:14:51 -03:00
Igor Pissolati
c0fd8ebf51 Add FileFsAttributeInformation fs info class 2025-10-22 17:14:19 -03:00
momo5502
effd2f7a02 Merge remote-tracking branch 'origin/main' into wow64 2025-10-21 20:45:29 +02:00
Maurice Heumann
b84ae7475f Implement ALPC port abstraction and implement DNS resolver port (#558)
This PR introduces an abstraction for ALPC ports to make them easier to
manage in the future, and implements the DNS resolver port, at least
enough to get host address queries working.
There's a lot of code in this PR that I'm not very confident about, so
don't hesitate on the feedback 😄

<img width="1377" height="624" alt="image"
src="https://github.com/user-attachments/assets/4d56b84d-4b87-42ed-9bfa-be04dbbf3735"
/>
2025-10-21 20:42:26 +02:00
momo5502
652f8d7f17 Fix formatting 2025-10-21 20:15:20 +02:00
Maurice Heumann
304dbcc661 Comprehensive WOW64 subsystem implementation (#555)
# Major Features Implemented
**Core WOW64 Architecture**
1. Full TEB, PEB, and Windows structure implementations for 32-bit
processes
2. Proper thread context switching with 32-bit stack allocation
3. Configurable memory allocation with 32-bit/64-bit address space
handling
4. Automatic WOW64 process identification and handling
5. Heaven's Gate Implementation for handling exceptions

**Enhanced Emulation Features**
1. Fixed GDT setup and segment management for WOW64
2. Multi-architecture PE loading with proper import resolution
3. Segment-aware disassembly with WOW64 debugging capabilities

**Testing & Validation**
**32-bit Test Sample**: Minimal "hello" executable with full ASM source

# TODO
Needs more testing, currently in very early stages.
2025-10-21 20:13:01 +02:00
Igor Pissolati
248c09d554 Implement ALPC port abstraction and implement DNS resolver port 2025-10-19 23:23:29 -03:00
Igor Pissolati
887b02c240 Support file renaming and support relative path in NtQueryAttributesFile 2025-10-19 17:51:44 -03:00
brian
65eecf1cfd Comprehensive WOW64 subsystem implementation 2025-10-13 19:55:50 +08:00
momo5502
9453123db0 Force new line at EOF 2025-10-12 17:21:51 +02:00
momo5502
c9c6b46ec2 Support object types information query 2025-09-12 20:36:45 +02:00
momo5502
f5de884ddf Fix compilation with latest reflect version 2025-09-08 12:20:46 +02:00
momo5502
2a43b42428 Mark rdtsc(p) as available 2025-09-07 20:43:11 +02:00
momo5502
7d6648ade0 Extend clang-format column limit to 140 2025-08-16 14:55:07 +02:00
momo5502
292fc6ce67 Fix compilation 2025-08-09 17:38:20 +02:00
momo5502
386f5b1cbc Add missing types 2025-08-09 17:20:22 +02:00
CarlTSpeak
ffea72d48a Added basic pipe support to NtRead/WriteFile 2025-08-06 10:30:40 +01:00
momo5502
6eb4ef33ff Handle invalid page protections
This fixes #420
2025-07-20 09:34:25 +02:00
3fault
2ecd3e4440 add STATUS_GUARD_PAGE_VIOLATION constant to platform includes 2025-07-02 14:06:37 -04:00
momo5502
bda89b5d1e Add more syscalls 2025-06-15 19:48:05 +02:00
momo5502
1421550764 Cleanup and fix NtQueryInformationProcess 2025-06-15 09:31:57 +02:00
Red
f14b16d080 Fix anti-debug detections for NtQueryInformationProcess with ProcessDebugObjectHandle 2025-06-14 15:00:53 +02:00
redthing1
5d9dd122d2 minidump support: dump loading and process reconstruction 2025-06-09 23:12:45 -07:00
momo5502
e26ac99551 Fix char16_t tolower conversion 2025-06-07 11:45:43 +02:00
momo5502
956e73d839 Some fixes 2025-06-04 20:47:51 +02:00
Maurice Heumann
368a9dbdd1 Update file_management.hpp 2025-06-03 11:17:50 +02:00
Igor Pissolati
9f32620220 Fix failing checks 2025-06-02 14:32:15 -03:00
Igor Pissolati
ad3046466e Improvements to NtQueryInformationToken 2025-06-02 14:32:15 -03:00
momo5502
9b2653afc4 Override timestamp counter for deterministic clock 2025-06-02 19:28:24 +02:00
momo5502
909b2db20d Support more mountpoint IOCTLs 2025-06-01 12:36:50 +02:00
momo5502
e763fdac54 Support more syscalls 2025-05-31 21:27:32 +02:00
momo5502
b6f4645420 Some more syscalls 2025-05-31 13:21:19 +02:00
momo5502
c50fdd17a4 Fix compilation warnings 2025-05-31 10:37:04 +02:00
momo5502
5c0a1ce5c2 Build and test MinGW in CI 2025-05-31 09:47:55 +02:00
Hacksign
829e3d95a6 UPDATE: modify cmake scripts, adding warning messages. 2025-05-30 12:37:35 +08:00