Skip to content

Commit

Permalink
Various fixes for mwcc/mwld (#32)
Browse files Browse the repository at this point in the history
* Override GetFileAttributesA for MWCC license.dat

* Add WIN_FUNC to FileTimeToLocalFileTime

* Use callee_pop_aggregate_return(0)

* Lexically normalize paths
  • Loading branch information
encounter authored Jan 23, 2023
1 parent 6b6a462 commit 7d08a2b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// On Windows, the incoming stack is aligned to a 4 byte boundary.
// force_align_arg_pointer will realign the stack to match GCC's 16 byte alignment.
#define WIN_ENTRY __attribute__((force_align_arg_pointer))
#define WIN_ENTRY __attribute__((force_align_arg_pointer, callee_pop_aggregate_return(0)))
#define WIN_FUNC WIN_ENTRY __attribute__((stdcall))
#define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__)

Expand Down
9 changes: 8 additions & 1 deletion dll/kernel32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ namespace kernel32 {
unsigned int WIN_FUNC GetFileAttributesA(const char *lpFileName) {
auto path = files::pathFromWindows(lpFileName);
DEBUG_LOG("GetFileAttributesA(%s)... (%s)\n", lpFileName, path.c_str());

// See ole32::CoCreateInstance
if (endsWith(path, "/license.dat")) {
DEBUG_LOG("MWCC license override\n");
return 0x80; // FILE_ATTRIBUTE_NORMAL
}

auto status = std::filesystem::status(path);

wibo::lastError = 0;
Expand Down Expand Up @@ -868,7 +875,7 @@ namespace kernel32 {
return 1;
}

int FileTimeToLocalFileTime(const FILETIME *lpFileTime, FILETIME *lpLocalFileTime) {
int WIN_FUNC FileTimeToLocalFileTime(const FILETIME *lpFileTime, FILETIME *lpLocalFileTime) {
DEBUG_LOG("FileTimeToLocalFileTime\n");
// we live on Iceland
*lpLocalFileTime = *lpFileTime;
Expand Down
4 changes: 2 additions & 2 deletions files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace files {

// Return as-is if it exists, else traverse the filesystem looking for
// a path that matches case insensitively
std::filesystem::path path = std::filesystem::path(str);
std::filesystem::path path = std::filesystem::path(str).lexically_normal();
if (std::filesystem::exists(path)) {
return path;
}
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace files {
}

std::string pathToWindows(const std::filesystem::path &path) {
std::string str = path;
std::string str = path.lexically_normal();

if (path.is_absolute()) {
str.insert(0, "Z:");
Expand Down
5 changes: 5 additions & 0 deletions files.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <filesystem>
#include <string>

namespace files {
std::filesystem::path pathFromWindows(const char *inStr);
Expand All @@ -9,3 +10,7 @@ namespace files {
unsigned int setStdHandle(uint32_t nStdHandle, void *hHandle);
void init();
}

static bool endsWith(const std::string &str, const std::string &suffix) {
return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}

0 comments on commit 7d08a2b

Please sign in to comment.