--- Daodan/src/Daodan_Patch.c 2009/06/09 12:00:41 346 +++ Daodan/src/Daodan_Patch.c 2013/03/04 15:52:19 689 @@ -1,5 +1,6 @@ #include "Daodan_Patch.h" #include +#include #include bool DDrPatch_MakeJump(void* from, void* to) @@ -8,7 +9,8 @@ bool DDrPatch_MakeJump(void* from, void* if (VirtualProtect(from, 5, PAGE_EXECUTE_READWRITE, &oldp)) { - *(char*)from++ = 0xe9; // jmp rel32 + *((unsigned char*)from) = 0xe9; // jmp rel32 + from = (char*)from + 1; *(int*)from = (unsigned int)to - (unsigned int)from - 4; VirtualProtect(from, 5, oldp, &oldp); return true; @@ -23,7 +25,8 @@ bool DDrPatch_MakeCall(void* from, void* if (VirtualProtect(from, 5, PAGE_EXECUTE_READWRITE, &oldp)) { - *(char*)from++ = 0xe8; // call rel32 + *((unsigned char*)from) = 0xe8; // call rel32 + from = (char*)from + 1; *(int*)from = (unsigned int)to - (unsigned int)from - 4; VirtualProtect(from, 5, oldp, &oldp); return true; @@ -32,7 +35,7 @@ bool DDrPatch_MakeCall(void* from, void* return false; } -bool DDrPatch_String(char* dest, const char* string, int length) +bool DDrPatch_String(char* dest, const unsigned char* string, int length) { DWORD oldp; @@ -46,7 +49,7 @@ bool DDrPatch_String(char* dest, const c return false; } -bool DDrPatch_Byte(char* dest, char value) +bool DDrPatch_Byte(char* dest, unsigned char value) { DWORD oldp; @@ -60,7 +63,7 @@ bool DDrPatch_Byte(char* dest, char valu return false; } -bool DDrPatch_Int32(int* dest, int value) +bool DDrPatch_Int32(int* dest, unsigned int value) { DWORD oldp; @@ -74,7 +77,7 @@ bool DDrPatch_Int32(int* dest, int value return false; } -bool DDrPatch_Int16(short* dest, short value) +bool DDrPatch_Int16(short* dest, unsigned short value) { DWORD oldp; @@ -88,16 +91,30 @@ bool DDrPatch_Int16(short* dest, short v return false; } -bool DDrPatch_StrDup(int* dest, const char* value) +bool DDrPatch__strdup(int* dest, const char* value) { DWORD oldp; if (VirtualProtect(dest, 4, PAGE_EXECUTE_READWRITE, &oldp)) { - *dest = (int)strdup(value); + *dest = (int)_strdup(value); VirtualProtect(dest, 4, oldp, &oldp); return true; } else + return false; +} + +bool DDrPatch_NOOP(char* dest, unsigned int length) +{ + DWORD oldp; + + if (VirtualProtect(dest, length, PAGE_EXECUTE_READWRITE, &oldp)) + { + memset(dest, 0x90, length); + VirtualProtect(dest, length, oldp, &oldp); + return true; + } + else return false; }