diff options
Diffstat (limited to 'aoe2hd/include')
-rwxr-xr-x | aoe2hd/include/CodeGenerator.h | 40 | ||||
-rwxr-xr-x | aoe2hd/include/CodeInjector.h | 61 | ||||
-rwxr-xr-x | aoe2hd/include/CodePatcher.h | 45 | ||||
-rwxr-xr-x | aoe2hd/include/ModuleMemory.h | 57 | ||||
-rwxr-xr-x | aoe2hd/include/aoe2hd.h | 58 | ||||
-rwxr-xr-x | aoe2hd/include/native.h | 56 | ||||
-rwxr-xr-x | aoe2hd/include/utils.h | 13 |
7 files changed, 330 insertions, 0 deletions
diff --git a/aoe2hd/include/CodeGenerator.h b/aoe2hd/include/CodeGenerator.h new file mode 100755 index 0000000..e0649dd --- /dev/null +++ b/aoe2hd/include/CodeGenerator.h @@ -0,0 +1,40 @@ +#ifndef CODEGENERATOR_H +#define CODEGENERATOR_H + +#include <string> +#include <vector> + +#include "CodeInjector.h" + + +std::vector<unsigned char> x86_relJump(unsigned long dst, + unsigned long src); + +class CodeGenerator +{ +public: + CodeGenerator(const native_data& nd); + virtual ~CodeGenerator(); + void clear() + { + codes.clear(); + } + bool hasCode(int index); + CodeGenerator& addCode(const std::vector<unsigned char>& code); + CodeGenerator& setCode(int index, const std::vector<unsigned char>& code); + CodeGenerator& setCodeSized(int index, const std::vector<unsigned char>& code); + CodeGenerator& setRel32JMP(int index, unsigned long dst, unsigned long src, bool reversed = false); + std::vector<unsigned char>::size_type buildSize(int maxCodes = -1); + std::vector<unsigned char> build(); + std::vector<unsigned char> buildAndClear(); + std::string toString(); +private: + const native_data& nd; + std::vector<std::vector<unsigned char>> codes; + unsigned long diffRel32JMP(bool reversed, int index = -1) + { + return (!reversed ? buildSize(index) - 0x5 : buildSize(index)); + } +}; + +#endif // CODEGENERATOR_H diff --git a/aoe2hd/include/CodeInjector.h b/aoe2hd/include/CodeInjector.h new file mode 100755 index 0000000..189b580 --- /dev/null +++ b/aoe2hd/include/CodeInjector.h @@ -0,0 +1,61 @@ +#ifndef CODEINJECTOR_H +#define CODEINJECTOR_H + +#include <vector> +#include <map> +#include <string> + +extern "C" { +#include "native.h" +} + + +typedef struct code_bin +{ + unsigned long addr; + unsigned long siz; + bool operator<(const code_bin& a) const + { + return addr < a.addr; + } +} code_bin; + +typedef struct code_seg +{ + unsigned long addr; + unsigned long siz; + std::map<const std::string, code_bin> children; +} code_seg; + +class CodeInjector +{ +public: + CodeInjector(const native_data& nd); + virtual ~CodeInjector(); + bool allocCodeSegment(const std::string& name, + unsigned long siz = 4096); + bool addCode(const std::string& name, const std::string& code_name, + const std::vector<unsigned char>& code); + bool addCode(const std::string& name, const std::string& code_name, + unsigned long siz); + bool setCode(const std::string& name, const std::string& code_name, + const std::vector<unsigned char>& code, + unsigned long offset = 0); + bool delCode(const std::string& name, const std::string& code_name); + unsigned long getCodeAddr(const std::string& name, const std::string& code_name); + bool getCodeSeg(const std::string& name, code_seg *seg); + bool getCodeBin(const std::string& name, const std::string& code_name, code_bin *bin); + std::string toString(); +private: + const native_data& nd; + std::map<std::string, code_seg> code_map; + bool codeSegExists(const std::string& name) + { + return code_map.find(name) != code_map.end(); + } + bool codeBinExists(const std::string& name, const std::string& code_name); + std::vector<code_bin> convertCodeSegChildren(const std::string& name); + unsigned long findCodeCave(const std::string& name, unsigned long siz); +}; + +#endif // CODEINJECTOR_H diff --git a/aoe2hd/include/CodePatcher.h b/aoe2hd/include/CodePatcher.h new file mode 100755 index 0000000..1713b21 --- /dev/null +++ b/aoe2hd/include/CodePatcher.h @@ -0,0 +1,45 @@ +#ifndef CODEPATCHER_H +#define CODEPATCHER_H + +#include <vector> +#include <map> + +extern "C" { +#include "native.h" +} + + +typedef struct code_patch +{ + unsigned long addr; + std::vector<unsigned char> old_code; + std::vector<unsigned char> new_code; + long new_offset; + long suspend; +} code_patch; + +class CodePatcher +{ +public: + CodePatcher(const native_data& nd); + virtual ~CodePatcher(); + bool addPatch(const std::string& name, + unsigned long addr, + const std::vector<unsigned char>& old_code, + const std::vector<unsigned char>& new_code, + long new_offset = 0); + void setPatchSuspend(const std::string& name, long doSuspend); + bool doPatch(const std::string& name, int doUnPatch); + bool autoPatch(const std::string& name); + std::string toString(); +private: + const native_data& nd; + std::map<std::string, code_patch> patch_map; + bool codePatchExists(const std::string& name) + { + return patch_map.find(name) != patch_map.end(); + } + bool codeCmp(unsigned long addr, std::vector<unsigned char> code); +}; + +#endif // CODEPATCHER_H diff --git a/aoe2hd/include/ModuleMemory.h b/aoe2hd/include/ModuleMemory.h new file mode 100755 index 0000000..2fa2584 --- /dev/null +++ b/aoe2hd/include/ModuleMemory.h @@ -0,0 +1,57 @@ +#ifndef PROCESSMEMORY_H +#define PROCESSMEMORY_H + +#include <map> +#include <set> +#include <string> + +extern "C" { +#include "native.h" +} + + +typedef struct target_ptr +{ + unsigned long base; + unsigned long offset; + unsigned long ptr; + bool valid; + std::string dependency; + std::set<std::string> children; +} target_ptr; + +class ModuleMemory +{ +public: + ModuleMemory(const native_data& nd); + virtual ~ModuleMemory(); + unsigned long getPtr(const std::string& name); + unsigned long getPtr(const std::string& name, unsigned long *dest_ptr); + unsigned long getPtr(const std::string& name, unsigned long base, unsigned long offset); + unsigned long recheckPtr(const std::string& name); + void revalidateAllPtr(); + bool ptrSetDependency(const std::string& name, const std::string& dependency); + bool getData(const std::string& name, void *buffer, unsigned long siz); + std::string toString(); + std::string toStringStats(); +private: + const native_data& nd; + std::map<std::string, target_ptr> ptr_map; + unsigned long ptr_read_count; + unsigned long ptr_invalid_count; + bool ptrExists(const std::string& name) + { + return ptr_map.find(name) != ptr_map.end(); + } + bool ptrValid(const std::string& name) + { + if (ptrExists(name) && ptr_map[name].valid) + { + return true; + } + else ++ptr_invalid_count; + return false; + } +}; + +#endif // PROCESSMEMORY_H diff --git a/aoe2hd/include/aoe2hd.h b/aoe2hd/include/aoe2hd.h new file mode 100755 index 0000000..424f71f --- /dev/null +++ b/aoe2hd/include/aoe2hd.h @@ -0,0 +1,58 @@ +#ifndef AOE2HD_H_INCLUDED +#define AOE2HD_H_INCLUDED + +#define DUMMY5 0x90,0x90,0x90,0x90,0x90 /* nop; nop; nop; nop; nop */ + +/* SAFE! */ +#define MAP_NOFOG 0x45BE43 +#define MAP_NOFOG0 0x8B,0x0C,0x81 /* mov ecx,[ecx+eax*4] */ +#define MAP_NOFOG1 0x8B,0x45,0x10 /* mov eax,[ebp+10] */ +#define MAP_NOFOGI 0x81,0xC9,0x00,0x04,0x00,0x00 /* or ecx,0x00000400 */ + +/* SAFE! */ +#define MAP_MINI 0x46CA33 +#define MAP_MINI0 0x8B,0x0C,0x88 /* mov ecx,[eax+ecx*4] */ +#define MAP_MINI1 0x8B,0x87,0x34,0x01,0x00,0x00 /* mov eax,[edi+00000134] */ +#define MAP_MINII 0x81,0xC9,0x00,0x00,0x00,0x04 /* or ecx,0x04000000 */ + +/* NOT SAFE -> DESYNC POSSIBLE! */ +#define MAP_SMTH 0x46CEE8 +#define MAP_SMTH0 0x8B,0x04,0x88 /* mov eax,[eax+ecx*4] */ +#define MAP_SMTH1 0x8B,0x8F,0x34,0x01,0x00,0x00 /* mov ecx,[edi+00000134] */ +#define MAP_SMTHI 0x0D,0x00,0x04,0x00,0x00 /* or eax,0x00000400 */ + +/* NOT SAFE! .> DESYNC POSSIBLE! */ +#define MAP_UNIT 0x47F851 +#define MAP_UNIT0 0x8B,0x01 /* mov eax,[ecx] */ +#define MAP_UNIT1 0x8B,0xD0,0x8B,0x8D,0x34,0xFF,0xFF,0xFF /* mov edx,eax; mov ecx,[ebp-000000CC] */ +#define MAP_UNITI 0x0D,0x00,0x04,0x00,0x00 /* or eax,0x00000400 */ + +/* MAP/MINIMAP FLAGS: + * NOFOG_BY_UNIT.....: 0x00000002 + * NOFOG_ALL.........: 0x00000400 + * DISCOVERED_BY_UNIT: 0x00020000 + * DISCOVERED_ALL....: 0x04000000 + * MAP_FULL_VISIABLE.: DISCOVERED_ALL | NOFOG_ALL + * MAP_SPY_LIKE......: DISCOVERED_BY_UNIT | NOFOG_BY_UNIT + */ + +struct resources +{ + float food; + float wood; + float stone; + float gold; + float remainingPop; + unsigned char garbage_1[4]; + float currentAge; + unsigned char garbage_2[16]; + float currentPop; +}; + +struct mapsize +{ + uint32_t cells_x; + uint32_t cells_y; +}; + +#endif // AOE2HD_H_INCLUDED diff --git a/aoe2hd/include/native.h b/aoe2hd/include/native.h new file mode 100755 index 0000000..b599e0d --- /dev/null +++ b/aoe2hd/include/native.h @@ -0,0 +1,56 @@ +#ifndef NATIVE_H_INCLUDED +#define NATIVE_H_INCLUDED + +#include <windows.h> +#include <stdbool.h> + +#define EXPORT __declspec(dllexport) + +typedef struct native_data native_data; + +typedef unsigned long(*alloc_mem_fn)(const native_data *nd, + unsigned long siz); +typedef bool(*read_mem_fn)(const native_data *nd, + unsigned long addr, void *buffer, + unsigned long siz); +typedef bool(*write_mem_fn)(const native_data *nd, + unsigned long addr, const void *buffer, + unsigned long siz); +typedef bool(*suspend_proc_fn)(const native_data *nd, + int doResume); + +typedef struct win_proc +{ + DWORD pid; + HANDLE hndl; + unsigned long modbase; +} win_proc; + +typedef struct native_data +{ + win_proc proc; + alloc_mem_fn alloc_fn; + read_mem_fn read_fn; + write_mem_fn write_fn; + suspend_proc_fn suspend_fn; +} native_data; + +EXPORT void initNativeData(native_data *nd); +EXPORT void cls(HANDLE hConsole); +EXPORT bool get_module_proc(native_data *nd, + LPCTSTR window_name); +EXPORT bool get_module_base(native_data *nd, + LPCTSTR module_name); + +EXPORT unsigned long mem_alloc(const native_data *nd, + unsigned long siz); +EXPORT bool read_procmem(const native_data *nd, + unsigned long addr, void *buffer, + unsigned long siz); +EXPORT bool write_procmem(const native_data *nd, + unsigned long addr, const void *buffer, + unsigned long siz); +EXPORT bool suspendProcess(const native_data *nd, + int doResume); + +#endif // NATIVE_H_INCLUDED diff --git a/aoe2hd/include/utils.h b/aoe2hd/include/utils.h new file mode 100755 index 0000000..1d71b90 --- /dev/null +++ b/aoe2hd/include/utils.h @@ -0,0 +1,13 @@ +#ifndef UTILS_H +#define UTILS_H + +#include <vector> +#include <string> + + +namespace utils +{ +std::string convertBinToHexstr(const std::vector<unsigned char>& bin); +}; + +#endif // UTILS_H |