more more more

This commit is contained in:
rjkiv 2025-08-07 14:35:39 -07:00
parent 4546ab04d5
commit 61fa3084fb
3 changed files with 67 additions and 15 deletions

View File

@ -5,10 +5,24 @@ namespace advapi32 {
DEBUG_LOG("RegOpenKeyExA(key=%p, subkey=%s, ...)\n", hKey, lpSubKey); DEBUG_LOG("RegOpenKeyExA(key=%p, subkey=%s, ...)\n", hKey, lpSubKey);
return 1; // screw them for now 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) { static void *resolveByName(const char *name) {
if (strcmp(name, "RegOpenKeyExA") == 0) return (void *) advapi32::RegOpenKeyExA; if (strcmp(name, "RegOpenKeyExA") == 0) return (void *) advapi32::RegOpenKeyExA;
if (strcmp(name, "CryptAcquireContextW") == 0) return (void*) advapi32::CryptAcquireContextW;
return nullptr; return nullptr;
} }

View File

@ -468,7 +468,7 @@ namespace kernel32 {
} }
LPWSTR WIN_FUNC GetCommandLineW() { LPWSTR WIN_FUNC GetCommandLineW() {
DEBUG_LOG("GetCommandLineW -> "); DEBUG_LOG("GetCommandLineW -> \n");
return wibo::commandLineW.data(); 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) { 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); 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. int prot = PROT_READ | PROT_WRITE;
assert(mem < (void*)0x80000000); if (flProtect == 0x04 /* PAGE_READWRITE */) {
prot = PROT_READ | PROT_WRITE;
DEBUG_LOG("-> %p\n", mem); } else if (flProtect == 0x02 /* PAGE_READONLY */) {
return mem; prot = PROT_READ;
} else if (flProtect == 0x40 /* PAGE_EXECUTE_READWRITE */) {
prot = PROT_READ | PROT_WRITE | PROT_EXEC;
} else { } else {
assert(lpAddress != NULL); DEBUG_LOG("Unhandled flProtect: %u, defaulting to RW\n", flProtect);
return lpAddress;
} }
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) { unsigned int WIN_FUNC VirtualFree(void *lpAddress, unsigned int dwSize, int dwFreeType) {

View File

@ -341,6 +341,12 @@ namespace msvcrt {
return std::wcsncmp(string1, string2, count); 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, "_write") == 0) return (void*)msvcrt::_write;
if (strcmp(name, "exit") == 0) return (void*)msvcrt::exit; if (strcmp(name, "exit") == 0) return (void*)msvcrt::exit;
if (strcmp(name, "wcsncmp") == 0) return (void*)msvcrt::wcsncmp; if (strcmp(name, "wcsncmp") == 0) return (void*)msvcrt::wcsncmp;
if (strcmp(name, "_vswprintf_c_l") == 0) return (void*)msvcrt::_vswprintf_c_l;
return nullptr; return nullptr;
} }