2022-06-13 02:20:18 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2022-07-05 21:26:24 -05:00
|
|
|
#include <sys/stat.h>
|
2022-06-13 02:20:18 +02:00
|
|
|
#include <unistd.h>
|
2022-06-28 23:08:23 +02:00
|
|
|
#include <assert.h>
|
2022-06-13 02:20:18 +02:00
|
|
|
|
2023-01-22 21:07:37 -05:00
|
|
|
// 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.
|
2023-01-23 10:25:36 -05:00
|
|
|
#define WIN_ENTRY __attribute__((force_align_arg_pointer))
|
|
|
|
|
#define WIN_FUNC WIN_ENTRY __attribute__((stdcall))
|
2022-06-29 13:19:45 +02:00
|
|
|
#define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__)
|
2022-06-13 02:20:18 +02:00
|
|
|
|
2022-07-27 12:28:29 +02:00
|
|
|
namespace user32 {
|
|
|
|
|
int WIN_FUNC MessageBoxA(void *hwnd, const char *lpText, const char *lpCaption, unsigned int uType);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-13 02:20:18 +02:00
|
|
|
namespace wibo {
|
|
|
|
|
extern uint32_t lastError;
|
|
|
|
|
extern char *commandLine;
|
2022-06-29 15:24:58 +02:00
|
|
|
extern bool debugEnabled;
|
2022-06-13 02:20:18 +02:00
|
|
|
|
2022-06-29 01:29:26 +02:00
|
|
|
void debug_log(const char *fmt, ...);
|
|
|
|
|
|
2022-06-28 23:08:23 +02:00
|
|
|
void *resolveVersion(const char *name);
|
2022-06-13 02:20:18 +02:00
|
|
|
void *resolveKernel32(const char *name);
|
2022-06-28 23:08:23 +02:00
|
|
|
void *resolveUser32(const char *name);
|
2022-06-29 17:23:33 +02:00
|
|
|
void *resolveOle32(const char *name);
|
2022-06-13 02:20:18 +02:00
|
|
|
void *resolveAdvApi32(const char *name);
|
2022-06-29 17:33:41 +02:00
|
|
|
void *resolveLmgr(uint16_t ordinal);
|
2022-07-15 00:45:35 +02:00
|
|
|
void *resolveFuncByName(const char *dllName, const char *funcName);
|
|
|
|
|
void *resolveFuncByOrdinal(const char *dllName, uint16_t ordinal);
|
2022-06-13 02:20:18 +02:00
|
|
|
|
|
|
|
|
struct Executable {
|
|
|
|
|
Executable();
|
|
|
|
|
~Executable();
|
|
|
|
|
bool loadPE(FILE *file);
|
|
|
|
|
|
|
|
|
|
void *imageBuffer;
|
|
|
|
|
size_t imageSize;
|
|
|
|
|
void *entryPoint;
|
2022-06-29 13:19:45 +02:00
|
|
|
void *rsrcBase;
|
2022-06-13 02:20:18 +02:00
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
T *fromRVA(uint32_t rva) {
|
|
|
|
|
return (T *) (rva + (uint8_t *) imageBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
T *fromRVA(T *rva) {
|
|
|
|
|
return fromRVA<T>((uint32_t) rva);
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-06-29 13:19:45 +02:00
|
|
|
|
|
|
|
|
extern Executable *mainModule;
|
2022-06-13 02:20:18 +02:00
|
|
|
}
|