|
| 1 | + |
| 2 | +## Strategy option A |
| 3 | +The preferred strategy for now. Let's use binkw32.dll as a hijack to include our own dll that initially just calls the entry function. |
| 4 | +The next function that should be implemented is the main game loop's calls. |
| 5 | +We can use pointers to these functions in header files. |
| 6 | +The .exe is initially version 1.41 (Latin-based languages), so we can hardcode pointer addresses in the header files. |
| 7 | + |
| 8 | +### API proof of concept |
| 9 | +API calls should largely be self documenting. |
| 10 | +The macro `CAST_THIS_CALL` doesn't document argument names. So maybe typedef approach is better and more clear. |
| 11 | + |
| 12 | +```cpp |
| 13 | +#include <cstdlib> |
| 14 | + |
| 15 | +#ifdef __linux__ |
| 16 | + //linux code goes here |
| 17 | + #define __cdecl __attribute__((cdecl)) |
| 18 | + #define __stdcall __attribute__((stdcall)) |
| 19 | + #define __thiscall __attribute__((thiscall)) |
| 20 | +#elif _WIN32 |
| 21 | + // windows code goes here |
| 22 | +#else |
| 23 | + |
| 24 | +#endif |
| 25 | + |
| 26 | +#define TYPEDEF_THIS_CALL_CLASS(returnType, name, cls, ...) typedef const returnType (__thiscall name)(cls*, __VA_ARGS__) |
| 27 | +#define TYPEDEF_THIS_CALL_PVOID(returnType, name, ...) TYPEDEF_THIS_CALL_CLASS(returnType, name, void, __VA_ARGS__) |
| 28 | + |
| 29 | +#define ADDR_CALL_A 0x401000 |
| 30 | +#define DO_GAME_X ((FuncDef*) ADDR_CALL_A) |
| 31 | + |
| 32 | +typedef int (__stdcall *f)(int a, int b, int c); |
| 33 | + |
| 34 | +class A { |
| 35 | + |
| 36 | +public: |
| 37 | + |
| 38 | + int v = 1; |
| 39 | + |
| 40 | + int __thiscall whatever(int a, int b) { |
| 41 | + this->v += (a * b); |
| 42 | + return this->v; |
| 43 | + } |
| 44 | + |
| 45 | +}; |
| 46 | + |
| 47 | +TYPEDEF_THIS_CALL_CLASS(int, FuncDef, A, int a, int b); |
| 48 | +TYPEDEF_THIS_CALL_CLASS(int, FuncDefVoid, void, int a, int b); |
| 49 | + |
| 50 | +TYPEDEF_THIS_CALL_PVOID(int, FuncDefTest, int* a, int* b); |
| 51 | + |
| 52 | +TYPEDEF_THIS_CALL_PVOID(int, FuncDef2, int, int); |
| 53 | + |
| 54 | +#define CAST_CDECL_CALL(addr, returnType, ...) ((const returnType (__cdecl *)(__VA_ARGS__)) addr) |
| 55 | +#define CDECL_CALL(func, ...) func(__VA_ARGS__) |
| 56 | + |
| 57 | +#define CALL_FUNC_CdeclExample(...) CDECL_CALL(CAST_CDECL_CALL(0x401000, int, int, int), __VA_ARGS__) |
| 58 | + |
| 59 | +#define CAST_STD_CALL(addr, returnType, ...) ((const returnType (__stdcall *)(__VA_ARGS__)) addr) |
| 60 | +#define STD_CALL(func, ...) func(__VA_ARGS__) |
| 61 | + |
| 62 | +#define CALL_FUNC_StdExample(...) STD_CALL(CAST_STD_CALL(0x401000, int, int, int), __VA_ARGS__) |
| 63 | + |
| 64 | +#define CAST_THIS_CALL(addr, returnType, ...) ((const returnType (__thiscall *)(void*, __VA_ARGS__)) addr) |
| 65 | +#define THIS_CALL(func, thisValue, ...) func(thisValue, __VA_ARGS__) |
| 66 | + |
| 67 | +#define CALL_FUNC_Whatever(...) THIS_CALL(CAST_THIS_CALL(0x401000, int, int, int), a, __VA_ARGS__) |
| 68 | + |
| 69 | +const auto whatever3 = CAST_THIS_CALL(0x401000, int, int); |
| 70 | + |
| 71 | +#ifdef __linux__ |
| 72 | + const FuncDef* whatever2 = (FuncDef*) 0x401000; |
| 73 | +#endif |
| 74 | + |
| 75 | +A *a = new A(); |
| 76 | + |
| 77 | +int main() { |
| 78 | + a->v = 100; |
| 79 | + |
| 80 | + int r0 = a->whatever(100, 9); |
| 81 | + |
| 82 | + void * p = (void *) 0x401000; |
| 83 | + A* b = ((A*) p); |
| 84 | + b->v = 100; |
| 85 | + int r = b->whatever(1000, r0); |
| 86 | + |
| 87 | + int r2 = 0; |
| 88 | + int r3 = 0; |
| 89 | + |
| 90 | +#ifdef __linux__ |
| 91 | + r2 = whatever2(a, r, 250); |
| 92 | + |
| 93 | + r2 = DO_GAME_X(a, r, r2); |
| 94 | + |
| 95 | + r3 = ((FuncDef*) 0x401000)(a, r, r2); |
| 96 | + |
| 97 | + FuncDef* a4 = (const int (__thiscall *)(A*, int, int)) 0x401000; |
| 98 | + FuncDefVoid* a5 = CAST_THIS_CALL(0x401000, int, int, int); |
| 99 | +#endif |
| 100 | + |
| 101 | + int r4 = CAST_THIS_CALL(0x401000, int, int, int)(a, r2, r3); |
| 102 | + int r5 = CALL_FUNC_Whatever(r3, r4); |
| 103 | + int r6 = CALL_FUNC_StdExample(r4, r5); |
| 104 | + int r7 = CALL_FUNC_CdeclExample(r6, r5); |
| 105 | + |
| 106 | + |
| 107 | + return a->whatever(r+r3, r2+r7); |
| 108 | +} |
| 109 | +``` |
0 commit comments