BWAPI
|
00001 /* HackUtil is a set of functions that make import detours and code patching easier. 00002 Copyright (C) 2010 Adam Heinermann 00003 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #include <stdio.h> 00019 #include <string> 00020 #include <windows.h> 00021 #include <vector> 00022 00023 // Typedefs 00024 typedef unsigned __int8 u8 ; 00025 typedef unsigned __int16 u16; 00026 typedef unsigned __int32 u32; 00027 typedef unsigned __int64 u64; 00028 00029 typedef signed __int8 s8 ; 00030 typedef signed __int16 s16; 00031 typedef signed __int32 s32; 00032 typedef signed __int64 s64; 00033 00034 // Variables 00035 #define __TOSTRING(l) #l 00036 #define _TOSTRING(l) __TOSTRING(l) 00037 #define FILELINE __FILE__ ":" _TOSTRING(__LINE__) 00038 00039 namespace HackUtil 00040 { 00041 // Imports 00042 IMAGE_IMPORT_DESCRIPTOR* _GetImportDescriptor(HMODULE module); 00043 IMAGE_THUNK_DATA32* _GetImportsList(char* sourceModule, char* importModule); 00044 DWORD* _GetFunctionsList(char* sourceModule, char* importModule); 00045 /* These functions are not specifically made for public use */ 00046 00047 FARPROC PatchImport(char* sourceModule, char* importModule, LPCSTR name, void* patchFunction); 00048 FARPROC PatchImport(char* importModule, LPCSTR name, void* patchFunction); 00049 FARPROC PatchImport(char* sourceModule, char* importModule, int ordinal, void* patchFunction); 00050 FARPROC PatchImport(char* importModule, int ordinal, void* patchFunction); 00051 /* Creates a detour for the specified import function in any loaded module */ 00052 00053 FARPROC GetImport(char* importModule, LPCSTR name); 00054 FARPROC GetImport(char* importModule, int ordinal); 00055 /* Retrieves the address of the imported function from the specified module */ 00056 00057 // Memory 00058 void WriteNops(void* dest, u32 size); 00059 void WriteNops(u32 dest, u32 size); 00060 /* Writes NOPs to the specified destination */ 00061 00062 void WriteMem(void* dest, void* source, u32 size); 00063 void WriteMem(u32 dest, void* source, u32 size); 00064 /* Writes data to the specified destination from the source */ 00065 00066 void JmpPatch(void* dest, void* patch); 00067 void JmpPatch(u32 dest, void* patch); 00068 /* Writes a jump to the specified patch at the destination */ 00069 00070 void CallPatch(void* dest, void* patch); 00071 void CallPatch(u32 dest, void* patch); 00072 /* Writes a call to the specified patch at the destination */ 00073 00074 void Revert(const char *logline); 00075 /* Reverts all changes made with any function except for WriteMemRaw */ 00076 00077 void WriteMemRaw(void* dest, void* source, u32 size); 00078 void WriteMemRaw(u32 dest, void* source, u32 size); 00079 /* Writes to memory and does not include the change in the changes list */ 00080 };