--- Daodan/src/Daodan_Patch.c 2014/04/06 17:06:02 993 +++ Daodan/src/Daodan_Patch.c 2014/04/09 00:10:18 995 @@ -1,5 +1,5 @@ #include "Daodan_Patch.h" -#include "Daodan_Utility.h" +#include "Patches/Utility.h" #include #include @@ -41,28 +41,11 @@ bool DDrPatch_MakeCall(void* from, void* void* DDrPatch_MakeDetour(void* from, void* to) { int len = 0; + /* - DISASM MyDisasm; - int i = 0; - STARTUPMESSAGE("", 0); - STARTUPMESSAGE("", 0); - - memset (&MyDisasm, 0, sizeof(DISASM)); - MyDisasm.EIP = (UIntPtr) from; - i = 0; - STARTUPMESSAGE("Orig before @ 0x%06x", from); - while (i<10){ - len = Disasm(&MyDisasm); - if (len != UNKNOWN_OPCODE) { - STARTUPMESSAGE("%s, Opcode: 0x%x, len: %d, branch: %d, to: 0x%06x", MyDisasm.CompleteInstr, MyDisasm.Instruction.Opcode, len, MyDisasm.Instruction.BranchType, MyDisasm.Instruction.AddrValue); - STARTUPMESSAGE(" Cat: 0x%04x, prefix count: %d", MyDisasm.Instruction.Category & 0xffff, MyDisasm.Prefix.Number ); - MyDisasm.EIP += (UIntPtr)len; - i++; - } - }; - STARTUPMESSAGE("", 0); + STARTUPMESSAGE("Orig before", 0); + DDrPatch_PrintDisasm(from, 10, 0); */ - DISASM disasm; memset(&disasm, 0, sizeof(DISASM)); disasm.EIP = (UIntPtr) from; @@ -174,52 +157,17 @@ void* DDrPatch_MakeDetour(void* from, vo return (void*)-1; } DDrPatch_MakeJump(from, to); + /* - memset (&MyDisasm, 0, sizeof(DISASM)); - MyDisasm.EIP = (UIntPtr) trampoline; - i = 0; - STARTUPMESSAGE("Trampoline @ 0x%06x", trampoline); - while (i<10){ - len = Disasm(&MyDisasm); - if (len != UNKNOWN_OPCODE) { - STARTUPMESSAGE("%s", MyDisasm.CompleteInstr); - MyDisasm.EIP += (UIntPtr)len; - i++; - } - }; - STARTUPMESSAGE("", 0); - - memset (&MyDisasm, 0, sizeof(DISASM)); - MyDisasm.EIP = disasm.EIP; - i = 0; - STARTUPMESSAGE("Orig after @ 0x%06x", disasm.EIP); - while (i<7){ - len = Disasm(&MyDisasm); - if (len != UNKNOWN_OPCODE) { - STARTUPMESSAGE("%s", MyDisasm.CompleteInstr); - MyDisasm.EIP += (UIntPtr)len; - i++; - } - }; - STARTUPMESSAGE("", 0); - - memset (&MyDisasm, 0, sizeof(DISASM)); - MyDisasm.EIP = (UIntPtr) from; - i = 0; - STARTUPMESSAGE("Orig start after @ 0x%06x", from); - while (i<3){ - len = Disasm(&MyDisasm); - if (len != UNKNOWN_OPCODE) { - STARTUPMESSAGE("%s", MyDisasm.CompleteInstr); - MyDisasm.EIP += (UIntPtr)len; - i++; - } - }; - STARTUPMESSAGE("", 0); - STARTUPMESSAGE("", 0); - STARTUPMESSAGE("", 0); -*/ + STARTUPMESSAGE("Trampoline", 0); + DDrPatch_PrintDisasm(trampoline, 10, 6); + + STARTUPMESSAGE("Orig after", 0); + DDrPatch_PrintDisasm(disasm.EIP, 7, 0); + STARTUPMESSAGE("Orig start after", 0); + DDrPatch_PrintDisasm(from, 3, 6); +*/ return trampoline; } @@ -279,20 +227,6 @@ bool DDrPatch_Int16(short* dest, unsigne return false; } -bool DDrPatch__strdup(int* dest, const char* value) -{ - DWORD oldp; - - if (VirtualProtect(dest, 4, PAGE_EXECUTE_READWRITE, &oldp)) - { - *dest = (int)_strdup(value); - VirtualProtect(dest, 4, oldp, &oldp); - return true; - } - else - return false; -} - bool DDrPatch_NOOP(char* dest, unsigned int length) { DWORD oldp; @@ -306,3 +240,37 @@ bool DDrPatch_NOOP(char* dest, unsigned else return false; } + + +void DDrPatch_PrintDisasm(void* addr, int instLimit, int sizeLimit) +{ + DISASM MyDisasm; + int len = 0; + int size = 0; + int i = 0; + + memset(&MyDisasm, 0, sizeof(DISASM)); + + MyDisasm.EIP = (UIntPtr) addr; + + STARTUPMESSAGE("", 0); + STARTUPMESSAGE("Disassembly @ 0x%06x", addr); + + if (sizeLimit <= 0) + sizeLimit = 20 * instLimit; + + while ((i < instLimit) && (size < sizeLimit)) { + len = Disasm(&MyDisasm); + if (len != UNKNOWN_OPCODE) { + size += len; + STARTUPMESSAGE(" %s, Opcode: 0x%x, len: %d, branch: %d, to: 0x%06x", MyDisasm.CompleteInstr, MyDisasm.Instruction.Opcode, len, MyDisasm.Instruction.BranchType, MyDisasm.Instruction.AddrValue); + STARTUPMESSAGE(" Cat: 0x%04x, prefix count: %d", MyDisasm.Instruction.Category & 0xffff, MyDisasm.Prefix.Number ); + + MyDisasm.EIP += (UIntPtr)len; + i++; + } + }; + + STARTUPMESSAGE("", 0); +} +