From d0e79f51bd47bc302d40c7e8472e643d9e3e2938 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 31 Aug 2024 19:43:27 +0200 Subject: [PATCH] Progress with kernelbase initialization --- src/windows_emulator/main.cpp | 3 +- src/windows_emulator/syscalls.cpp | 48 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/windows_emulator/main.cpp b/src/windows_emulator/main.cpp index a262edb..349ebda 100644 --- a/src/windows_emulator/main.cpp +++ b/src/windows_emulator/main.cpp @@ -282,7 +282,7 @@ namespace context.process_params.access([&](RTL_USER_PROCESS_PARAMETERS& proc_params) { proc_params.Length = sizeof(proc_params); - proc_params.Flags = 0x6001; + proc_params.Flags = 0x6001 | 0x80000000; gs.make_unicode_string(proc_params.CurrentDirectory.DosPath, L"C:\\Users\\mauri\\Desktop"); gs.make_unicode_string(proc_params.ImagePathName, L"C:\\Users\\mauri\\Desktop\\ConsoleApplication6.exe"); gs.make_unicode_string(proc_params.CommandLine, L"C:\\Users\\mauri\\Desktop\\ConsoleApplication6.exe"); @@ -575,6 +575,7 @@ namespace (void)entry1; (void)entry2; + syscall_dispatcher dispatcher{context.ntdll.exports}; emu->hook_instruction(x64_hookable_instructions::syscall, [&] diff --git a/src/windows_emulator/syscalls.cpp b/src/windows_emulator/syscalls.cpp index fbed44e..8cc0a18 100644 --- a/src/windows_emulator/syscalls.cpp +++ b/src/windows_emulator/syscalls.cpp @@ -571,6 +571,29 @@ namespace return STATUS_NOT_SUPPORTED; } + if (info_class == SystemTimeOfDayInformation) + { + if (return_length) + { + return_length.write(sizeof(SYSTEM_TIMEOFDAY_INFORMATION)); + } + + if (system_information_length != sizeof(SYSTEM_TIMEOFDAY_INFORMATION)) + { + return STATUS_BUFFER_TOO_SMALL; + } + + const emulator_object info_obj{c.emu, system_information}; + + info_obj.access([&](SYSTEM_TIMEOFDAY_INFORMATION& info) + { + info.BootTime.QuadPart = 0; + // TODO: Fill + }); + + return STATUS_SUCCESS; + } + if (info_class == SystemRangeStartInformation) { if (return_length) @@ -592,6 +615,7 @@ namespace return STATUS_SUCCESS; } + if (info_class == SystemNumaProcessorMap) { if (return_length) @@ -977,6 +1001,28 @@ namespace throw std::runtime_error("Bad free type"); } + + NTSTATUS handle_NtCreateSection(const syscall_context& /*c*/, const emulator_object section_handle, + const ACCESS_MASK /*desired_access*/, + const emulator_object /*object_attributes*/, + const emulator_object maximum_size, + const ULONG /*section_page_protection*/, const ULONG /*allocation_attributes*/, + const uint64_t /*file_handle*/) + { + section_handle.write(SHARED_SECTION); + + maximum_size.access([](LARGE_INTEGER& large_int) + { + large_int.QuadPart = page_align_up(large_int.QuadPart); + }); + + return STATUS_SUCCESS; + } + + NTSTATUS handle_NtConnectPort() + { + return STATUS_SUCCESS; + } } syscall_dispatcher::syscall_dispatcher(const exported_symbols& ntdll_exports) @@ -1022,6 +1068,8 @@ syscall_dispatcher::syscall_dispatcher(const exported_symbols& ntdll_exports) add_handler(NtOpenFile); add_handler(NtQueryVolumeInformationFile); add_handler(NtApphelpCacheControl); + add_handler(NtCreateSection); + add_handler(NtConnectPort); #undef add_handler }