Commit Graph

1225 Commits

Author SHA1 Message Date
66hh
95b17566a0 Add NtRaiseHardError error message logging 2025-12-27 17:17:24 +08:00
66hh
02298e2303 Fix illegal address write 2025-12-27 17:17:24 +08:00
66hh
55310c57ac Add additional path checks for NtOpenSection 2025-12-27 17:17:24 +08:00
66hh
98393c03d2 Add a check before the conversion path 2025-12-27 17:17:24 +08:00
66hh
ecc00216d6 Support ProcessInstrumentationCallback 2025-12-27 17:17:23 +08:00
Maurice Heumann
d3cb3f4995 Fix PEB32 (#639)
When emulating `WOW64` samples sometimes you can see a garbige like
this:

```
Executing syscall: NtQueryAttributesFile (0x3D) at 0x18009dd42 via 0x100037f1c (wow64.dll)
--> Querying file attributes: \??\C:\SH╠мхЯЦэР╜р░АC:\Windows\SYSTEM32\VCRUNTIME140.dll
```

This is because of incorrect `PEB32` creation that leads to damaging
several `UNICODE_STRING` fields in `ProcessParameters`.
This PR fixes that.
2025-12-25 12:29:07 +01:00
ssvine
3686625fb1 Fix PEB32 2025-12-25 13:42:20 +03:00
ssvine
96851b20ed Fix unicorn hooking 2025-12-25 13:35:12 +03:00
ssvine
8438a1f456 Support extended variant of ProcessBasicInformation 2025-12-24 18:33:49 +03:00
momo5502
f0f223faaa Remove error 2025-12-24 08:58:15 +01:00
momo5502
b4406d9b41 Collect more DLLs 2025-12-23 12:45:44 +01:00
momo5502
6da563d1ca Collect imagehlp.dll 2025-12-23 12:32:57 +01:00
momo5502
5d84f86eaf Fix warnings 2025-12-23 11:31:51 +01:00
momo5502
35b7839ec8 Support section offsets 2025-12-23 10:50:07 +01:00
momo5502
db3a89a0da Support KeyCachedInformation 2025-12-23 09:31:10 +01:00
momo5502
b1f7efb8c1 Ignore partial disconnect in AFD driver 2025-12-22 16:14:12 +01:00
momo5502
5ebf2dfd81 Support skipping syscall logging 2025-12-22 16:13:58 +01:00
momo5502
66cfe980d7 Ignore ThreadPriorityBoost 2025-12-22 14:39:44 +01:00
momo5502
90343077da Fix ordinals 2025-12-22 14:02:15 +01:00
momo5502
169fcaa8a5 Add DLLs 2025-12-22 13:51:18 +01:00
Maurice Heumann
1708212af9 Translate file paths before usage in section.cpp (#634)
Emulated applications are currently able to access files from the host
system, rather than being restricted to the virtualized file system, by
using `Section` related Syscalls. This behavior appears to have been
introduced in:

- 2024-12-13: [Prepare better section support
(syscalls.cpp:582)](719a50444e (diff-96c7de348bdc06e650bdc371a600a91f80594d4201afd7a28ffa160fa755be9dR582))
- 2025-10-13: [Comprehensive WOW64 subsystem implementation
(section.cpp:141)](65eecf1cfd (diff-415eed3b4b314dc10cc9f7926687770be53799766bc9a4edca2a7f4a45477169R141)))

Because the emulator is [advertised for malware
analysis](https://github.com/momo5502/sogen/blob/main/README.md), this
unintended access path could be considered a security concern.

This PR only fixes two current misuses of an API that interacts with the
host system. As a long term solution, APIs that interact with host
resources should consistently use C++ types that enforce translation of
resource identifiers (e.g., file and registry paths) into their emulated
equivalents. This would help prevent future misuse and ensure that
emulated applications remain isolated from the host environment.
2025-12-22 07:51:10 +01:00
momo5502
69ddd7a93b Small fixes 2025-12-22 07:42:34 +01:00
momo5502
cfebd2f35f Fix WinVerifyTrust 2025-12-21 20:37:42 +01:00
Maurice Kayser
db7548d130 Translate paths before usage in section.cpp 2025-12-21 00:00:00 +00:00
momo5502
ca15abd8ef Add missing syscalls 2025-12-07 11:22:37 +01:00
momo5502
568ca68481 Ignore ProcessPriorityClass 2025-12-06 11:12:19 +01:00
Maurice Heumann
28f3fa0aa0 Fix deserialization of optional WOW64 emulator_object members (#633)
Adds default constructor to `emulator_object` for optional member
deserialization.
Restores `memory_interface` pointer for WOW64 structures after
deserialization.
2025-12-06 08:24:38 +01:00
Maurice Heumann
68b0b51bc8 cmake: add SOGEN_STATIC_CRT option for static runtime linking (#606)
## Summary

Adds a CMake option to use static CRT (`/MT`) instead of the default
dynamic CRT (`/MD`).

**Use case:** Projects that require static linking (e.g., IDA Pro
plugins) cannot use the default `/MD` runtime because they must link
with `/MT`.

## Changes

- Add `SOGEN_STATIC_CRT` option (default: `OFF`)
- When `ON`, sets `CMAKE_MSVC_RUNTIME_LIBRARY` to static (`/MT` or
`/MTd`)
- Also respects parent project's `CMAKE_MSVC_RUNTIME_LIBRARY` if already
defined
- Includes documentation warning about heap allocation boundaries

## Backwards Compatibility

- Default behavior unchanged (`/MD`)
- Existing projects unaffected

## Usage

```bash
cmake -B build -DSOGEN_STATIC_CRT=ON
```

Or in parent CMakeLists.txt:
```cmake
set(SOGEN_STATIC_CRT ON CACHE BOOL "")
add_subdirectory(sogen)
```

## Test plan

- [x] Verified default build still uses `/MD`
- [x] Verified `-DSOGEN_STATIC_CRT=ON` produces `/MT` build
- [x] Tested with IDA Pro plugin project (emudbg) - links successfully
2025-12-06 08:22:42 +01:00
brian
5171ef63dc Fix deserialization of optional WOW64 emulator_object members (PEB32/params32) 2025-12-05 20:21:25 +08:00
Elias Bachaalany
7a42bc7ad3 cmake: rename MOMO_BUILD_AS_LIBRARY to SOGEN_BUILD_STATIC
Also adds FATAL_ERROR guard when SOGEN_STATIC_CRT=ON without SOGEN_BUILD_STATIC=ON,
since static CRT with shared libraries causes heap corruption (each DLL gets its own
allocator but sogen passes ownership across boundaries).

These options are designed to be used together for full static linking, useful for
embedding sogen in projects like IDA Pro plugins.
2025-12-02 16:24:27 -08:00
Elias Bachaalany
651c020b87 Use stack-allocated ctx_t array instead of heap allocation
- Initialize ctxs[i] directly with aggregate initialization
- Pass address of stack object to CreateThread
- Use dot notation instead of arrow for member access
- Remove delete calls since no heap allocation

Co-authored-by: Maurice Heumann <momo5502@gmail.com>
2025-12-02 15:53:37 -08:00
Elias Bachaalany
4a905d562a Update src/samples/test-sample/test.cpp
Co-authored-by: Maurice Heumann <MauriceHeumann@gmail.com>
2025-12-02 15:44:21 -08:00
Elias Bachaalany
7cb92a662b test: add Windows API threads test
Add test_threads_winapi() that creates threads using CreateThread
and WaitForMultipleObjects to complement the existing std::thread
based test, verifying Windows threading API emulation works correctly.
2025-11-26 17:30:43 -08:00
momo5502
8c75475f0d Stub more syscalls 2025-11-20 18:43:20 +01:00
momo5502
2be5f73755 Support ProcessPriorityClass in NtQueryInformationProcess 2025-11-20 18:25:33 +01:00
Maurice Heumann
934e11a311 Archive gdiplus.dll 2025-11-20 18:13:38 +01:00
Maurice Kayser
db67ac5a03 Collect SysWOW64 files in create-root.bat 2025-11-18 00:00:00 +00:00
Maurice Kayser
36b151177e Add WOW64 related entries to create-root.bat 2025-11-18 00:00:00 +00:00
Maurice Kayser
889dea066e Sort create-root.bat entries alphabetically 2025-11-18 00:00:00 +00:00
momo5502
ed7c7085b4 Fix formatting 2025-11-01 10:34:26 +01:00
dependabot[bot]
2468a03da0 Build(deps): Bump icicle-vm
Bumps [icicle-vm](https://github.com/icicle-emu/icicle-emu) from `ebb9bd1` to `0ce707e`.
- [Commits](ebb9bd1969...0ce707edd1)

---
updated-dependencies:
- dependency-name: icicle-vm
  dependency-version: 0ce707edd10f7a099426cf02a9fdf8eda3f57768
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-31 20:21:48 +00:00
momo5502
42630afac0 Remove randomness 2025-10-31 18:23:35 +01:00
momo5502
0e5bbdd8cc Fix serialization issues 2025-10-30 20:21:28 +01:00
momo5502
98eb1f92d1 Better formatting 2025-10-26 18:48:51 +01:00
momo5502
3bf037876c Remove logging 2025-10-26 18:48:43 +01:00
momo5502
cb4fe6c30f Merge remote-tracking branch 'origin/main' into wow64 2025-10-25 11:06:03 +02:00
Maurice Heumann
eb0ba686cd Bugfixes - minidump load, memory tail boundary (#568)
Minor change to allow minidump load to work with pages with copy
permission set.

File was probing memory via VirtualQuery incrementally, previously this
ran forever as Sogen doesn't replicate Windows behaviour.

Added exclusive allocation end boundary so that allocation / info check
on last page of user space VA works. Modified
memory_manager::find_free_allocation_base and
memory_manager::get_region_info to use exclusive boundary.
Added check to NtQueryVirtualMemory - now correctly returns
STATUS_INVALID_PARAMETER when run against memory outside of user space
VA. Kernel modules should use ZwQueryVirtualMemory not the user land
API.
2025-10-25 10:55:18 +02:00
CarlTSpeak
22df3e7889 Fix format issue 2025-10-24 11:13:55 +01:00
CarlTSpeak
064df5b6ef Revert earlier rdtsc changes, implement fixes 2025-10-24 10:59:28 +01:00
Igor Pissolati
b6d7a012d7 Fix issue in NtUserEnumDisplayDevices and NtUserEnumDisplaySettings 2025-10-23 16:02:53 -03:00