Skip to content

Commit

Permalink
MessageBoxA
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlindholm authored and mkst committed Jul 27, 2022
1 parent ff947fb commit 42f2e69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#define WIN_FUNC __attribute__((stdcall))
#define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__)

namespace user32 {
int WIN_FUNC MessageBoxA(void *hwnd, const char *lpText, const char *lpCaption, unsigned int uType);
}

namespace wibo {
extern uint32_t lastError;
extern char *commandLine;
Expand Down
14 changes: 8 additions & 6 deletions dll/kernel32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,6 @@ namespace kernel32 {
uint32_t dwReserved1;
CharType cFileName[260];
CharType cAlternateFileName[14];
uint32_t dwFileType;
uint32_t dwCreatorType;
uint16_t wFinderFlags;
};

void *WIN_FUNC FindFirstFileA(const char *lpFileName, WIN32_FIND_DATA<char> *lpFindFileData) {
Expand All @@ -456,10 +453,10 @@ namespace kernel32 {
auto fileSize = std::filesystem::file_size(path);
lpFindFileData->nFileSizeHigh = (uint32_t)(fileSize >> 32);
lpFindFileData->nFileSizeLow = (uint32_t)fileSize;
assert(path.string().size() < 260);
strcpy(lpFindFileData->cFileName, path.c_str());
auto fileName = path.filename().string();
assert(fileName.size() < 260);
strcpy(lpFindFileData->cFileName, fileName.c_str());
strcpy(lpFindFileData->cAlternateFileName, "8P3FMTFN.BAD");
lpFindFileData->dwFileType = lpFindFileData->dwCreatorType = lpFindFileData->wFinderFlags = 0;
return (void *) 1;
}

Expand All @@ -468,6 +465,7 @@ namespace kernel32 {
}

int WIN_FUNC FindClose(void *hFindFile) {
DEBUG_LOG("FindClose\n");
return 1;
}

Expand Down Expand Up @@ -721,6 +719,7 @@ namespace kernel32 {
}

int FileTimeToLocalFileTime(const FILETIME *lpFileTime, FILETIME *lpLocalFileTime) {
DEBUG_LOG("FileTimeToLocalFileTime\n");
// we live on Iceland
*lpLocalFileTime = *lpFileTime;
return 1;
Expand All @@ -737,6 +736,7 @@ namespace kernel32 {
};

int WIN_FUNC GetTimeZoneInformation(TIME_ZONE_INFORMATION *lpTimeZoneInformation) {
DEBUG_LOG("GetTimeZoneInformation\n");
memset(lpTimeZoneInformation, 0, sizeof(*lpTimeZoneInformation));
return 0;
}
Expand All @@ -745,6 +745,7 @@ namespace kernel32 {
* Console Nonsense
*/
unsigned int WIN_FUNC SetConsoleCtrlHandler(void *HandlerRoutine, unsigned int Add) {
DEBUG_LOG("SetConsoleCtrlHandler\n");
// This is a function that gets called when doing ^C
// We might want to call this later (being mindful that it'll be stdcall I think)

Expand Down Expand Up @@ -1127,6 +1128,7 @@ namespace kernel32 {
// if (strcmp(lpProcName, "FlsFree") == 0) return (void *) FlsFree;
// if (strcmp(lpProcName, "LCMapStringEx") == 0) return (void *) LCMapStringEx;
// if (strcmp(lpProcName, "LocaleNameToLCID") == 0) return (void *) LocaleNameToLCID;
if (strcmp(lpProcName, "MessageBoxA") == 0) return (void *) user32::MessageBoxA;

return NULL;
}
Expand Down
7 changes: 7 additions & 0 deletions dll/user32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,16 @@ namespace user32 {
DEBUG_LOG("returning: %s\n", lpBuffer);
return len;
}

int WIN_FUNC MessageBoxA(void *hwnd, const char *lpText, const char *lpCaption, unsigned int uType) {
printf("MESSAGE BOX: [%s] %s\n", lpCaption, lpText);
fflush(stdout);
return 1;
}
}

void *wibo::resolveUser32(const char *name) {
if (strcmp(name, "LoadStringA") == 0) return (void *) user32::LoadStringA;
if (strcmp(name, "MessageBoxA") == 0) return (void *) user32::MessageBoxA;
return 0;
}

0 comments on commit 42f2e69

Please sign in to comment.