--- Daodan/src/Daodan_Patch.c 2014/04/09 00:10:18 995 +++ Daodan/src/Daodan_Patch.c 2016/08/28 16:01:38 1045 @@ -65,7 +65,7 @@ void* DDrPatch_MakeDetour(void* from, vo } branches++; int target = disasm.Instruction.AddrValue; - bool targetInTrampoline = ((void*)disasm.Instruction.AddrValue - from) < 5; + bool targetInTrampoline = ((void*)((int)disasm.Instruction.AddrValue) - from) < 5; switch (disasm.Instruction.BranchType) { case JmpType: case CallType: @@ -241,6 +241,27 @@ bool DDrPatch_NOOP(char* dest, unsigned return false; } +void* DDrPatch_ExecutableASM(char* from, char* nextInst, const unsigned char* code, int length) +{ + char* newCode = malloc(length+5); + if (!DDrPatch_NOOP(newCode, length+5)) + return (void*)-1; + + memcpy(newCode, code, length); + if (!DDrPatch_MakeJump(&newCode[length], nextInst)) + return (void*)-1; + + DWORD oldp; + if (!VirtualProtect(newCode, length+5, PAGE_EXECUTE_READWRITE, &oldp)) { + STARTUPMESSAGE("ExecASM: Could not mark page for new code as executable: from address 0x%08x", from); + return (void*)-1; + } + + if (!DDrPatch_MakeJump(from, newCode)) + return (void*)-1; + + return newCode; +} void DDrPatch_PrintDisasm(void* addr, int instLimit, int sizeLimit) {