From 97c946fd8616922809ab450d6c31798d9694aa46 Mon Sep 17 00:00:00 2001 From: camthesaxman Date: Tue, 5 Jul 2022 21:26:24 -0500 Subject: [PATCH] implement SetEndOfFile, CreateDirectoryA, RemoveDirectoryA, SetFileAttributesA (#6) * implement SetEndOfFile, CreateDirectoryA, RemoveDirectoryA, SetFileAttributesA * call fflush before ftruncate --- common.h | 1 + kernel32.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/common.h b/common.h index f437fcf..a528cb0 100644 --- a/common.h +++ b/common.h @@ -2,6 +2,7 @@ #include #include #include +#include #include #include diff --git a/kernel32.cpp b/kernel32.cpp index e0afc73..9fac048 100644 --- a/kernel32.cpp +++ b/kernel32.cpp @@ -438,6 +438,31 @@ namespace kernel32 { return r; } + int WIN_FUNC SetEndOfFile(void *hFile) { + DEBUG_LOG("SetEndOfFile\n"); + FILE *fp = files::fpFromHandle(hFile); + fflush(fp); + return ftruncate(fileno(fp), ftell(fp)) == 0; + } + + int WIN_FUNC CreateDirectoryA(const char *lpPathName, void *lpSecurityAttributes) { + std::string path = files::pathFromWindows(lpPathName); + DEBUG_LOG("CreateDirectoryA(%s, %p)\n", path.c_str(), lpSecurityAttributes); + return mkdir(path.c_str(), 0755) == 0; + } + + int WIN_FUNC RemoveDirectoryA(const char *lpPathName) { + std::string path = files::pathFromWindows(lpPathName); + DEBUG_LOG("RemoveDirectoryA(%s)\n", path.c_str()); + return rmdir(path.c_str()) == 0; + } + + int WIN_FUNC SetFileAttributesA(const char *lpPathName, unsigned int dwFileAttributes) { + std::string path = files::pathFromWindows(lpPathName); + DEBUG_LOG("SetFileAttributesA(%s, %u)\n", path.c_str(), dwFileAttributes); + return 1; + } + /* * Time */ @@ -879,6 +904,10 @@ void *wibo::resolveKernel32(const char *name) { if (strcmp(name, "CreateFileA") == 0) return (void *) kernel32::CreateFileA; if (strcmp(name, "DeleteFileA") == 0) return (void *) kernel32::DeleteFileA; if (strcmp(name, "SetFilePointer") == 0) return (void *) kernel32::SetFilePointer; + if (strcmp(name, "SetEndOfFile") == 0) return (void *) kernel32::SetEndOfFile; + if (strcmp(name, "CreateDirectoryA") == 0) return (void *) kernel32::CreateDirectoryA; + if (strcmp(name, "RemoveDirectoryA") == 0) return (void *) kernel32::RemoveDirectoryA; + if (strcmp(name, "SetFileAttributesA") == 0) return (void *) kernel32::SetFileAttributesA; if (strcmp(name, "GetFileSize") == 0) return (void *) kernel32::GetFileSize; if (strcmp(name, "GetFileTime") == 0) return (void *) kernel32::GetFileTime; if (strcmp(name, "GetSystemTime") == 0) return (void *) kernel32::GetSystemTime;