ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Daodan_Patch.c
(Generate patch)

Comparing Daodan/src/Daodan_Patch.c (file contents):
Revision 995 by alloc, Wed Apr 9 00:10:18 2014 UTC vs.
Revision 1008 by alloc, Mon Aug 25 23:21:09 2014 UTC

# Line 241 | Line 241 | bool DDrPatch_NOOP(char* dest, unsigned
241                  return false;
242   }
243  
244 + void* DDrPatch_ExecutableASM(char* from, char* nextInst, const unsigned char* code, int length)
245 + {
246 +        char* newCode = malloc(length+5);
247 +        if (!DDrPatch_NOOP(newCode, length+5))
248 +                return (void*)-1;
249 +
250 +        memcpy(newCode, code, length);
251 +        if (!DDrPatch_MakeJump(&newCode[length], nextInst))
252 +                return (void*)-1;
253 +
254 +        DWORD oldp;
255 +        if (!VirtualProtect(newCode, length+5, PAGE_EXECUTE_READWRITE, &oldp)) {
256 +                STARTUPMESSAGE("ExecASM: Could not mark page for new code as executable: from address 0x%08x", from);
257 +                return (void*)-1;
258 +        }
259 +        
260 +        if (!DDrPatch_MakeJump(from, newCode))
261 +                return (void*)-1;
262 +
263 +        return newCode;
264 + }
265  
266   void DDrPatch_PrintDisasm(void* addr, int instLimit, int sizeLimit)
267   {

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)