-
Notifications
You must be signed in to change notification settings - Fork 4
/
patching.c
79 lines (71 loc) · 2.14 KB
/
patching.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "patching.h"
#include "payload.h"
void* memfind(const void* data, unsigned int size, const void* search, unsigned int n) {
void* ret = NULL;
unsigned int i = 0;
unsigned char* pdata = (unsigned char*) data;
for(i = 0; i < size; i++) {
if(!_memcmp(pdata, search, n)) {
ret = pdata;
break;
}
pdata++;
}
return ret;
}
void* memfind4(const void* data, unsigned int size, unsigned int search) {
void *ret = NULL;
unsigned int i = 0;
unsigned char* pdata = (unsigned char*) data;
for(i = 0; i < size; i+=2) {
if(*((unsigned int*) pdata)==search) {
ret = (void*) pdata;
break;
}
pdata+=2;
}
return ret;
}
void* memfind8(const void* data, unsigned int size, const void* search) {
void *ret = NULL;
unsigned int i = 0;
unsigned char* pdata = (unsigned char*) data;
for(i = 0; i < size; i+=2) {
if(mem8eq(pdata, search)) {
ret = (void*) pdata;
break;
}
pdata+=2;
}
return ret;
}
void* memfind16(const void* data, unsigned int size, const void* search) {
void *ret = NULL;
unsigned int i = 0;
unsigned char* pdata = (unsigned char*) data;
for(i = 0; i < size; i+=2) {
if(mem16eq(pdata, search)) {
ret = (void*) pdata;
break;
}
pdata+=2;
}
return ret;
}
void* memfindref8(const void* data, unsigned int size, const void* search) {
void *ref = memfind8(data, size, search);
if (ref==NULL) return NULL;
return memfind4(data, size, (unsigned int) ref);
}
void dump(void *addr, unsigned int size) {
unsigned int i;
unsigned int count = size >> 2;
unsigned int *daddr = (unsigned int *) addr;
for (i = 0; i < count; i+=4) {
IOLog("%08x %08x %08x %08x\n", daddr[i], daddr[i+1], daddr[i+2], daddr[i+3]);
}
}