-
Notifications
You must be signed in to change notification settings - Fork 0
/
vnode.m
149 lines (135 loc) · 4.44 KB
/
vnode.m
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
144
145
146
147
148
149
#include "vnode.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include "SVC_Caller.h"
#include "kernel.h"
#include "libdimentio.h"
const char *vnodeMemPath;
NSArray *hidePathList = nil;
__attribute__((constructor)) void initVnodeMemPath() {
vnodeMemPath =
[NSString stringWithFormat:@"/tmp/%@.txt", NSProcessInfo.processInfo.processName].UTF8String;
}
void initPath() {
hidePathList = [NSArray
arrayWithContentsOfFile:[NSString stringWithFormat:@"/usr/share/%@/hidePathList.plist",
NSProcessInfo.processInfo.processName]];
if (hidePathList == nil) goto exit;
for (id path in hidePathList) {
if (![path isKindOfClass:[NSString class]]) goto exit;
}
return;
exit:
printf("hidePathList.plist is broken, please reinstall vnodebypass!\n");
exit(1);
}
void saveVnode() {
if (access(vnodeMemPath, F_OK) == 0) {
printf("Already exist /tmp/vnodeMem.txt, Please vnode recovery first!\n");
return;
}
initPath();
if (init_kernel() == 1) {
printf("Failed init_kernel\n");
return;
}
find_task(getpid(), &our_task);
if (!this_proc) return;
printf("this_proc: " KADDR_FMT "\n", this_proc);
FILE *fp = fopen(vnodeMemPath, "w");
int hideCount = (int)[hidePathList count];
uint64_t vnodeArray[hideCount];
for (int i = 0; i < hideCount; i++) {
const char *hidePath = [[hidePathList objectAtIndex:i] UTF8String];
int file_index = open(hidePath, O_RDONLY);
if (file_index == -1) continue;
vnodeArray[i] = get_vnode_with_file_index(file_index, this_proc);
printf("hidePath: %s, vnode[%d]: 0x%" PRIX64 "\n", hidePath, i, vnodeArray[i]);
printf("vnode_usecount: 0x%" PRIX32 ", vnode_iocount: 0x%" PRIX32 "\n",
kernel_read32(vnodeArray[i] + off_vnode_usecount),
kernel_read32(vnodeArray[i] + off_vnode_iocount));
fprintf(fp, "0x%" PRIX64 "\n", vnodeArray[i]);
close(file_index);
}
fclose(fp);
if (tfp0) mach_port_deallocate(mach_task_self(), tfp0);
printf("Saved vnode to /tmp/vnodeMem.txt\nMake sure vnode recovery to prevent kernel panic!\n");
}
void hideVnode() {
if (init_kernel() == 1) {
printf("Failed init_kernel\n");
return;
}
if (access(vnodeMemPath, F_OK) == 0) {
FILE *fp = fopen(vnodeMemPath, "r");
uint64_t savedVnode;
int i = 0;
while (!feof(fp)) {
if (fscanf(fp, "0x%" PRIX64 "\n", &savedVnode) == 1) {
printf("Saved vnode[%d] = 0x%" PRIX64 "\n", i, savedVnode);
hide_path(savedVnode);
}
i++;
}
}
if (tfp0) mach_port_deallocate(mach_task_self(), tfp0);
printf("Hide file!\n");
}
void revertVnode() {
if (init_kernel() == 1) {
printf("Failed init_kernel\n");
return;
}
if (access(vnodeMemPath, F_OK) == 0) {
FILE *fp = fopen(vnodeMemPath, "r");
uint64_t savedVnode;
int i = 0;
while (!feof(fp)) {
if (fscanf(fp, "0x%" PRIX64 "\n", &savedVnode) == 1) {
printf("Saved vnode[%d] = 0x%" PRIX64 "\n", i, savedVnode);
show_path(savedVnode);
}
i++;
}
}
if (tfp0) mach_port_deallocate(mach_task_self(), tfp0);
printf("Show file!\n");
}
void recoveryVnode() {
if (init_kernel() == 1) {
printf("Failed init_kernel\n");
return;
}
if (access(vnodeMemPath, F_OK) == 0) {
FILE *fp = fopen(vnodeMemPath, "r");
uint64_t savedVnode;
int i = 0;
while (!feof(fp)) {
if (fscanf(fp, "0x%" PRIX64 "\n", &savedVnode) == 1) {
kernel_write32(savedVnode + off_vnode_iocount,
kernel_read32(savedVnode + off_vnode_iocount) - 1);
kernel_write32(savedVnode + off_vnode_usecount,
kernel_read32(savedVnode + off_vnode_usecount) - 1);
printf("Saved vnode[%d] = 0x%" PRIX64 "\n", i, savedVnode);
printf("vnode_usecount: 0x%" PRIX32 ", vnode_iocount: 0x%" PRIX32 "\n",
kernel_read32(savedVnode + off_vnode_usecount),
kernel_read32(savedVnode + off_vnode_iocount));
}
i++;
}
remove(vnodeMemPath);
}
if (tfp0) mach_port_deallocate(mach_task_self(), tfp0);
printf("Recovered vnode! No more kernel panic when you shutdown.\n");
}
void checkFile() {
initPath();
int hideCount = (int)[hidePathList count];
for (int i = 0; i < hideCount; i++) {
const char *hidePath = [[hidePathList objectAtIndex:i] UTF8String];
int ret = 0;
ret = SVC_Access(hidePath);
printf("hidePath: %s, errno: %d\n", hidePath, ret);
}
printf("Done check file!\n");
}