-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMemRead_64.h
143 lines (116 loc) · 4.52 KB
/
MemRead_64.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifdef __LP64__
#include <vector>
#import "Util.h"
#import "process.h"
void getValueArea(vm_address_t startAddress,vm_address_t endAddress, void* buffer,long number,bool check){
kern_return_t result;
long readArea = 0;
vm_size_t outsize;
while(endAddress > startAddress){
if(check){
if (readArea != (startAddress & 0xFFFFFFFFFFFFF000)) {
readArea = startAddress & 0xFFFFFFFFFFFFF000;
outsize = 0;
result = vm_read_overwrite(target_task, readArea, 4096, (vm_address_t)buffer, &outsize);
if(!outsize){
printf("stardAddress 64 : %lx, %lx\n",startAddress,endAddress);
fprintf(stderr,"vm_read_overwrite failed: %lu\n",startAddress & 0xFFFFFFFFFFFFF000);
}
}
if (result == KERN_SUCCESS) {
for (int i=0; i<512; i++) {
memInfoStruct.address = startAddress;
memInfoStruct.value = *(long*)((char*)buffer + ((startAddress - (startAddress & 0xFFFFFFFFFFFFF000)) & 0xFFFFFFFFFFFFFFF8));
memDataList.push_back(memInfoStruct);
startAddress += 8;
}
}else{
startAddress += 8;
}
}else{
if (readArea != startAddress) {
readArea = startAddress;
outsize = 0;
result = vm_read_overwrite(target_task, readArea, 4096, (vm_address_t)buffer, &outsize);
if(!outsize){
printf("stardAddress 64 : %lx, %lx\n",startAddress,endAddress);
fprintf(stderr,"vm_read_overwrite failed: %lu\n",startAddress);
}
}
if (result == KERN_SUCCESS) {
for (int i=0; i<512; i++) {
memInfoStruct.address = startAddress;
memInfoStruct.value = *(long*)((char*)buffer + (startAddress - readArea));
memDataList.push_back(memInfoStruct);
startAddress += 8;
}
}else{
startAddress += 8;
}
}
}
}
void readMemory(long number){
if (attach()) {
void *buffer = malloc(4096);
for(int i = 0;i < regionList.size();i++){
regionStruct = regionList.at(i);
vm_address_t startAddress = regionStruct.startAddr;
vm_address_t endAddress = regionStruct.endAddr;
getValueArea(startAddress,endAddress,buffer,number,1);
}
free(buffer);
if(task_resume(target_task)){
printf("Cannot resume task!\n");
}
}else{
printf("attach failed");
}
}
void reReadMemory(long number){
if (attach()) {
vm_address_t startAddress = 0, endAddress = 0;
void *buffer = malloc(4096);
for(int i = 0;i < findDataList.size();i++){
findInfoStruct = findDataList.at(i);
vm_address_t cmp = findInfoStruct.address;
if((startAddress >= cmp) || (cmp >= endAddress)){
startAddress = findInfoStruct.address;
endAddress = startAddress + 4096;
getValueArea(startAddress,endAddress,buffer,number,0);
}
}
free(buffer);
if(task_resume(target_task)){
printf("Cannot resume task!\n");
}
}else{
printf("attach failed");
}
}
void getValueAddress(vm_address_t address){
kern_return_t result;
void *buffer;
buffer = malloc(8);
vm_size_t outsize;
if (attach()) {
result = vm_read_overwrite(target_task, address, 8, (vm_address_t)buffer, &outsize);
if(!outsize){
printf("stardAddress 64 : %lx\n",address);
fprintf(stderr,"vm_read_overwrite failed: %lu\n",address & 0xFFFFFFFFFFFFFFF8);
}
if (result == KERN_SUCCESS) {
printf("stardAddress 64 : %lx\n",address);
printf("Address : %lx, int32 Value: %ld\n",address,*(long*)buffer & 0x00000000FFFFFFFF);
printf("Address : %lx, int32 Value: %ld\n",address + 4,*(long*)buffer >> 32);
}
if(task_resume(target_task)){
printf("Cannot resume task!\n");
}
}else{
printf("attach failed");
}
free(buffer);
}
#else
#endif