Commit Graph

1209 Commits

Author SHA1 Message Date
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
CarlTSpeak
96169a01a8 Merge branch 'main' of https://github.com/momo5502/sogen 2025-10-23 19:00:50 +01:00
Igor Pissolati
3c6c2e2dde Apply review suggestion 2025-10-23 11:19:35 -03:00
Igor Pissolati
2c82277b5e Add FileIdInformation file info class 2025-10-23 11:19:17 -03:00
Igor Pissolati
83aa3b663a Optimize module_manager::get_module 2025-10-22 17:21:34 -03:00
Igor Pissolati
46b97fd91c Don't request 'file_size' for directories 2025-10-22 17:21:04 -03:00
Igor Pissolati
c07f541528 Stub NtSetSecurityObject 2025-10-22 17:20:38 -03:00
Igor Pissolati
d20da12052 Add '\??\pipe\' prefix to is_named_pipe_path 2025-10-22 17:19:51 -03:00
Igor Pissolati
1c89c4e3b3 Initialize StaticUnicodeString in TEB 2025-10-22 17:18:41 -03:00
Igor Pissolati
0d06e6822a Add support for SHA256 in KSecDD 2025-10-22 17:17:57 -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
momo5502
11ef37758c Fix casing 2025-10-21 20:43: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