source: Daodan/src/Daodan_Patch.c@ 342

Last change on this file since 342 was 272, checked in by rossy, 16 years ago

directory structure

File size: 1.7 KB
RevLine 
[272]1#include "Daodan_Patch.h"
2#include <windows.h>
3
4bool DDrPatch_MakeJump(void* from, void* to)
5{
6 DWORD oldp;
7
8 if (VirtualProtect(from, 5, PAGE_EXECUTE_READWRITE, &oldp))
9 {
10 *(char*)from++ = 0xe9; // jmp rel32
11 *(int*)from = (unsigned int)to - (unsigned int)from - 4;
12 VirtualProtect(from, 5, oldp, &oldp);
13 return true;
14 }
15 else
16 return false;
17}
18
19bool DDrPatch_MakeCall(void* from, void* to)
20{
21 DWORD oldp;
22
23 if (VirtualProtect(from, 5, PAGE_EXECUTE_READWRITE, &oldp))
24 {
25 *(char*)from++ = 0xe8; // call rel32
26 *(int*)from = (unsigned int)to - (unsigned int)from - 4;
27 VirtualProtect(from, 5, oldp, &oldp);
28 return true;
29 }
30 else
31 return false;
32}
33
34bool DDrPatch_String(char* dest, const char* string, int length)
35{
36 DWORD oldp;
37
38 if (VirtualProtect(dest, length, PAGE_EXECUTE_READWRITE, &oldp))
39 {
40 memcpy(dest, string, length);
41 VirtualProtect(dest, length, oldp, &oldp);
42 return true;
43 }
44 else
45 return false;
46}
47
48bool DDrPatch_Byte(char* dest, char value)
49{
50 DWORD oldp;
51
52 if (VirtualProtect(dest, 1, PAGE_EXECUTE_READWRITE, &oldp))
53 {
54 *dest = value;
55 VirtualProtect(dest, 1, oldp, &oldp);
56 return true;
57 }
58 else
59 return false;
60}
61
62bool DDrPatch_Int32(int* dest, int value)
63{
64 DWORD oldp;
65
66 if (VirtualProtect(dest, 4, PAGE_EXECUTE_READWRITE, &oldp))
67 {
68 *dest = value;
69 VirtualProtect(dest, 4, oldp, &oldp);
70 return true;
71 }
72 else
73 return false;
74}
75
76bool DDrPatch_Int16(short* dest, short value)
77{
78 DWORD oldp;
79
80 if (VirtualProtect(dest, 2, PAGE_EXECUTE_READWRITE, &oldp))
81 {
82 *dest = value;
83 VirtualProtect(dest, 2, oldp, &oldp);
84 return true;
85 }
86 else
87 return false;
88}
Note: See TracBrowser for help on using the repository browser.