From 61fa3084fbc01c569e52cef233df41d3e260cb2f Mon Sep 17 00:00:00 2001 From: rjkiv <76180273+rjkiv@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:35:39 -0700 Subject: [PATCH] more more more --- dll/advapi32.cpp | 14 +++++++++++ dll/kernel32.cpp | 61 ++++++++++++++++++++++++++++++++++++------------ dll/msvcrt.cpp | 7 ++++++ 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/dll/advapi32.cpp b/dll/advapi32.cpp index ce627ac..1220670 100644 --- a/dll/advapi32.cpp +++ b/dll/advapi32.cpp @@ -5,10 +5,24 @@ namespace advapi32 { DEBUG_LOG("RegOpenKeyExA(key=%p, subkey=%s, ...)\n", hKey, lpSubKey); return 1; // screw them for now } + + bool WIN_FUNC CryptAcquireContextW(void** phProv, const wchar_t* pszContainer, const wchar_t* pszProvider, unsigned int dwProvType, unsigned int dwFlags){ + DEBUG_LOG("STUB: CryptAcquireContextW(%p)\n", phProv); + + // to quote the guy above me: screw them for now + static int lmao = 42; + if (phProv) { + *phProv = &lmao; + return true; + } + + return false; + } } static void *resolveByName(const char *name) { if (strcmp(name, "RegOpenKeyExA") == 0) return (void *) advapi32::RegOpenKeyExA; + if (strcmp(name, "CryptAcquireContextW") == 0) return (void*) advapi32::CryptAcquireContextW; return nullptr; } diff --git a/dll/kernel32.cpp b/dll/kernel32.cpp index d919150..b6767fe 100644 --- a/dll/kernel32.cpp +++ b/dll/kernel32.cpp @@ -468,7 +468,7 @@ namespace kernel32 { } LPWSTR WIN_FUNC GetCommandLineW() { - DEBUG_LOG("GetCommandLineW -> "); + DEBUG_LOG("GetCommandLineW -> \n"); return wibo::commandLineW.data(); } @@ -1724,23 +1724,54 @@ namespace kernel32 { } void *WIN_FUNC VirtualAlloc(void *lpAddress, unsigned int dwSize, unsigned int flAllocationType, unsigned int flProtect) { - DEBUG_LOG("VirtualAlloc %p %u %u %u\n",lpAddress, dwSize, flAllocationType, flProtect); - if (flAllocationType & 0x2000 || lpAddress == NULL) { // MEM_RESERVE - // do this for now... - assert(lpAddress == NULL); - void *mem = 0; - posix_memalign(&mem, 0x1000, dwSize); - memset(mem, 0, dwSize); + DEBUG_LOG("VirtualAlloc %p %u %u %u\n", lpAddress, dwSize, flAllocationType, flProtect); - // Windows only fences off the lower 2GB of the 32-bit address space for the private use of processes. - assert(mem < (void*)0x80000000); - - DEBUG_LOG("-> %p\n", mem); - return mem; + int prot = PROT_READ | PROT_WRITE; + if (flProtect == 0x04 /* PAGE_READWRITE */) { + prot = PROT_READ | PROT_WRITE; + } else if (flProtect == 0x02 /* PAGE_READONLY */) { + prot = PROT_READ; + } else if (flProtect == 0x40 /* PAGE_EXECUTE_READWRITE */) { + prot = PROT_READ | PROT_WRITE | PROT_EXEC; } else { - assert(lpAddress != NULL); - return lpAddress; + DEBUG_LOG("Unhandled flProtect: %u, defaulting to RW\n", flProtect); } + + int flags = MAP_PRIVATE | MAP_ANONYMOUS; // MAP_ANONYMOUS ensures the memory is zeroed out + if (lpAddress != NULL) { + flags |= MAP_FIXED; + } + + void* result = mmap(lpAddress, dwSize, prot, flags, -1, 0); + // Windows only fences off the lower 2GB of the 32-bit address space for the private use of processes. + assert(result < (void*)0x80000000); + if (result == MAP_FAILED) { + DEBUG_LOG("mmap failed\n"); + return NULL; + } + else { + DEBUG_LOG("-> %p\n", result); + return result; + } + + + // DEBUG_LOG("VirtualAlloc %p %u %u %u\n",lpAddress, dwSize, flAllocationType, flProtect); + // if (flAllocationType & 0x2000 || lpAddress == NULL) { // MEM_RESERVE + // // do this for now... + // assert(lpAddress == NULL); + // void *mem = 0; + // posix_memalign(&mem, 0x1000, dwSize); + // memset(mem, 0, dwSize); + + // // Windows only fences off the lower 2GB of the 32-bit address space for the private use of processes. + // assert(mem < (void*)0x80000000); + + // DEBUG_LOG("-> %p\n", mem); + // return mem; + // } else { + // assert(lpAddress != NULL); + // return lpAddress; + // } } unsigned int WIN_FUNC VirtualFree(void *lpAddress, unsigned int dwSize, int dwFreeType) { diff --git a/dll/msvcrt.cpp b/dll/msvcrt.cpp index 1aee60e..b10469e 100644 --- a/dll/msvcrt.cpp +++ b/dll/msvcrt.cpp @@ -341,6 +341,12 @@ namespace msvcrt { return std::wcsncmp(string1, string2, count); } + int WIN_ENTRY _vswprintf_c_l(wchar_t* buffer, size_t size, const wchar_t* format, va_list args) { + if (!buffer || !format || size == 0) + return -1; + return vswprintf(buffer, size, format, args); + } + } @@ -374,6 +380,7 @@ static void *resolveByName(const char *name) { if (strcmp(name, "_write") == 0) return (void*)msvcrt::_write; if (strcmp(name, "exit") == 0) return (void*)msvcrt::exit; if (strcmp(name, "wcsncmp") == 0) return (void*)msvcrt::wcsncmp; + if (strcmp(name, "_vswprintf_c_l") == 0) return (void*)msvcrt::_vswprintf_c_l; return nullptr; }