wibo/common.h

51 lines
1.1 KiB
C
Raw Normal View History

2022-06-13 00:20:18 +00:00
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
2022-06-13 00:20:18 +00:00
#include <unistd.h>
2022-06-28 21:08:23 +00:00
#include <assert.h>
2022-06-13 00:20:18 +00:00
#define WIN_FUNC __attribute__((stdcall))
2022-06-29 11:19:45 +00:00
#define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__)
2022-06-13 00:20:18 +00:00
namespace wibo {
extern uint32_t lastError;
extern char *commandLine;
2022-06-29 13:24:58 +00:00
extern bool debugEnabled;
2022-06-13 00:20:18 +00:00
2022-06-28 23:29:26 +00:00
void debug_log(const char *fmt, ...);
2022-06-28 21:08:23 +00:00
void *resolveVersion(const char *name);
2022-06-13 00:20:18 +00:00
void *resolveKernel32(const char *name);
2022-06-28 21:08:23 +00:00
void *resolveUser32(const char *name);
2022-06-29 15:23:33 +00:00
void *resolveOle32(const char *name);
2022-06-13 00:20:18 +00:00
void *resolveAdvApi32(const char *name);
2022-06-29 15:33:41 +00:00
void *resolveLmgr(uint16_t ordinal);
2022-06-13 00:20:18 +00:00
void *resolveStubByName(const char *dllName, const char *funcName);
void *resolveStubByOrdinal(const char *dllName, uint16_t ordinal);
struct Executable {
Executable();
~Executable();
bool loadPE(FILE *file);
void *imageBuffer;
size_t imageSize;
void *entryPoint;
2022-06-29 11:19:45 +00:00
void *rsrcBase;
2022-06-13 00:20:18 +00: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 11:19:45 +00:00
extern Executable *mainModule;
2022-06-13 00:20:18 +00:00
}