Add functions for pspld.exe

This commit is contained in:
Mark Street 2024-02-11 17:40:39 +00:00
parent d71a902ace
commit 77d3562c8f
2 changed files with 33 additions and 0 deletions

View File

@ -132,6 +132,10 @@ namespace kernel32 {
return (PVOID)handler;
}
void WIN_FUNC RaiseException(DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments, void *lpArguments) {
DEBUG_LOG("STUB: RaiseException(0x%x, %u, %u, %p)\n", dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments);
}
// @brief returns a pseudo handle to the current process
void *WIN_FUNC GetCurrentProcess() {
// pseudo handle is always returned, and is -1 (a special constant)
@ -275,6 +279,11 @@ namespace kernel32 {
return 0;
}
void WIN_FUNC Sleep(DWORD dwMilliseconds) {
DEBUG_LOG("Sleep (%u)\n", dwMilliseconds);
sleep(dwMilliseconds);
}
int WIN_FUNC GetSystemDefaultLangID() {
return 0;
}
@ -649,6 +658,25 @@ namespace kernel32 {
return strlen(tmp_dir);
}
unsigned int WIN_FUNC GetTempFileNameA(LPCSTR lpPathName, LPCSTR lpPrefixString, unsigned int uUnique, LPSTR lpTempFileName) {
DEBUG_LOG("GetTempFileNameA: %s, %s, %u\n", lpPathName, lpPrefixString, uUnique);
if (uUnique == 0) {
// currently deterministic due to srand() in main.cpp
uUnique = rand();
}
std::filesystem::path filename = std::string(lpPrefixString) + std::to_string(uUnique);
std::filesystem::path path = files::pathFromWindows(lpPathName) / filename;
std::string pathStr = files::pathToWindows(path);
strcpy(lpTempFileName, pathStr.c_str());
DEBUG_LOG("GetTempFileNameA pathStr: %s\n", pathStr.c_str());
return uUnique;
}
struct FILETIME {
unsigned int dwLowDateTime;
unsigned int dwHighDateTime;
@ -2166,6 +2194,7 @@ static void *resolveByName(const char *name) {
if (strcmp(name, "GetLastError") == 0) return (void *) kernel32::GetLastError;
if (strcmp(name, "SetLastError") == 0) return (void *) kernel32::SetLastError;
if (strcmp(name, "AddVectoredExceptionHandler") == 0) return (void *) kernel32::AddVectoredExceptionHandler;
if (strcmp(name, "RaiseException") == 0) return (void *) kernel32::RaiseException;
// processthreadsapi.h
if (strcmp(name, "IsProcessorFeaturePresent") == 0) return (void *) kernel32::IsProcessorFeaturePresent;
@ -2215,6 +2244,7 @@ static void *resolveByName(const char *name) {
if (strcmp(name, "ReleaseSRWLockExclusive") == 0) return (void *) kernel32::ReleaseSRWLockExclusive;
if (strcmp(name, "TryAcquireSRWLockExclusive") == 0) return (void *) kernel32::TryAcquireSRWLockExclusive;
if (strcmp(name, "WaitForSingleObject") == 0) return (void *) kernel32::WaitForSingleObject;
if (strcmp(name, "Sleep") == 0) return (void *) kernel32::Sleep;
// winbase.h
if (strcmp(name, "GlobalAlloc") == 0) return (void *) kernel32::GlobalAlloc;
@ -2282,6 +2312,7 @@ static void *resolveByName(const char *name) {
if (strcmp(name, "FileTimeToLocalFileTime") == 0) return (void *) kernel32::FileTimeToLocalFileTime;
if (strcmp(name, "GetFileInformationByHandle") == 0) return (void *) kernel32::GetFileInformationByHandle;
if (strcmp(name, "GetTempPathA") == 0) return (void *) kernel32::GetTempPathA;
if (strcmp(name, "GetTempFileNameA") == 0) return (void *) kernel32::GetTempFileNameA;
// sysinfoapi.h
if (strcmp(name, "GetSystemTime") == 0) return (void *) kernel32::GetSystemTime;

View File

@ -424,6 +424,8 @@ int main(int argc, char **argv) {
exec.loadPE(f, true);
fclose(f);
srand(0x5EED);
uint16_t tibSegment = (tibDesc.entry_number << 3) | 7;
// Invoke the damn thing
asm(