From aec6f0dbe9f5f4d016a2d8f8a433d16ce7c8abe9 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Thu, 29 Dec 2022 17:37:21 -0700 Subject: [PATCH] Implement GetShortPathNameA (#28) --- dll/kernel32.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dll/kernel32.cpp b/dll/kernel32.cpp index 8d3f59d..83fff2f 100644 --- a/dll/kernel32.cpp +++ b/dll/kernel32.cpp @@ -438,6 +438,22 @@ namespace kernel32 { } } + unsigned int WIN_FUNC GetShortPathNameA(const char* lpszLongPath, char* lpszShortPath, unsigned int cchBuffer) { + DEBUG_LOG("GetShortPathNameA(%s)...\n",lpszShortPath); + std::filesystem::path absPath = std::filesystem::absolute(files::pathFromWindows(lpszLongPath)); + std::string absStr = files::pathToWindows(absPath); + + if (absStr.length() + 1 > cchBuffer) + { + return absStr.length()+1; + } + else + { + strcpy(lpszShortPath, absStr.c_str()); + return absStr.length(); + } + } + struct FILETIME { unsigned int dwLowDateTime; unsigned int dwHighDateTime; @@ -1609,6 +1625,7 @@ void *wibo::resolveKernel32(const char *name) { // fileapi.h if (strcmp(name, "GetFullPathNameA") == 0) return (void *) kernel32::GetFullPathNameA; + if (strcmp(name, "GetShortPathNameA") == 0) return (void *) kernel32::GetShortPathNameA; if (strcmp(name, "FindFirstFileA") == 0) return (void *) kernel32::FindFirstFileA; if (strcmp(name, "FindNextFileA") == 0) return (void *) kernel32::FindNextFileA; if (strcmp(name, "FindClose") == 0) return (void *) kernel32::FindClose;