forked from CreditTone/hooker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.js
281 lines (277 loc) · 12.1 KB
/
rpc.js
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
function mkdirs(dirpath) {
var FileClz = Java.use("java.io.File");
var file = FileClz.$new(dirpath);
if (!file.exists()) {
file.mkdirs();
}
}
function writeFileAsBase64Content(filepath, base64) {
try {
var FileUtilsClz = Java.use("android.os.FileUtils");
var StringClz = Java.use('java.lang.String');
var Base64Clz = Java.use("android.util.Base64");
var ByteArrayInputStreamClz = Java.use("java.io.ByteArrayInputStream");
var FileOutputStreamClz = Java.use("java.io.FileOutputStream");
var FileClz = Java.use("java.io.File");
var distFilepath = FileClz.$new(filepath);
mkdirs(distFilepath.getParent());
var javaBase64String = StringClz.$new(base64);
var getBytesMehtod = StringClz.getBytes.overload('java.lang.String');
var bytes = getBytesMehtod.call(javaBase64String, 'UTF-8');
var decodeMethod = Base64Clz.decode.overload('[B', 'int');
var originalBinary = decodeMethod.call(Base64Clz, bytes, 0);
var bais = ByteArrayInputStreamClz.$new(originalBinary);
if (FileUtilsClz.copy) {
var copyMehtod = FileUtilsClz.copy.overload('java.io.InputStream', 'java.io.OutputStream');
var fos = FileOutputStreamClz.$new(distFilepath);
copyMehtod.call(FileUtilsClz, bais, fos);
} else if (FileUtilsClz.copyToFile) {
var copyMehtod = FileUtilsClz.copyToFile.overload('java.io.InputStream', 'java.io.File');
copyMehtod.call(FileUtilsClz, bais, distFilepath);
}
} catch(err) {
console.warn(err);
}
};
function checkFile(filepath, checkLength) {
var FileClz = Java.use("java.io.File");
var file = FileClz.$new(filepath);
return file.exists() && file.length() == checkLength;
};
//可能会超时 为了防止这个发生,可以在函数 setImmediate 中给你的脚本添加一层包装
rpc.exports = {
loaddex: function(checkClassName, dexPath) {
Java.perform(function() {
if (!classExists(checkClassName)) {
Java.openClassFile(dexPath).load();
}
});
},
containsclass: function(className) {
var result = false;
Java.perform(function() {
result = classExists(className);
});
return result;
},
so: function(moduleName) {
return findSOLibrary(moduleName);
},
findclasses: function(classRegex) {
var report = "";
Java.perform(function() {
var radarClassResults = findClasses(classRegex);
report += ("Found Classes: " + radarClassResults.length) + "\n";
for (var j = 0; j < radarClassResults.length; j++) {
var radarClassResult = radarClassResults[j];
report += ("\t" + radarClassResult.describ()) + "\n";
}
});
return report;
},
findclasses2: function(className) {
var report = "";
Java.perform(function() {
var radarClassResults = findOffspringsClasses(className.trim());
report += ("Found Classes: " + radarClassResults.length) + "\n";
for (var j = 0; j < radarClassResults.length; j++) {
var radarClassResult = radarClassResults[j];
report += ("\t" + radarClassResult.describ()) + "\n";
}
});
return report;
},
hookjs: function(className, toSpace) {
var found = true;
var hookJs = "Java.perform(function() {\n";
var className = className;
var methodName = toSpace;
Java.perform(function() {
var radarClassResult = discoverClass(className);
if (radarClassResult) {
hookJs += generateMethodHookJs(radarClassResult, methodName);
hookJs += "});";
} else {
found = false;
console.error("Not found class " + className);
}
});
if (found) {
return jsbeautify(hookJs);
}
return "";
},
write: function(filename, contentAsBase64) {
Java.perform(function() {
//console.log(contentAsBase64);
writeFileAsBase64Content(filename, contentAsBase64);
});
},
checkfile: function(filename, filelength) {
var ret = false;
Java.perform(function() {
ret = checkFile(filename, filelength);
});
return ret;
},
activitys: function() {
var report = "";
Java.perform(function() {
try {
var radarAndroidClz = Java.use("gz.radar.Android");
var activityInfos = radarAndroidClz.getActivityInfos();
report += ("Found Activities: " + activityInfos.length) + "\n";
for (var i = 0; i < activityInfos.length; i++) {
try {
report += ("------------------" + (i) + "--------------------") + "\n";
var activityInfo = activityInfos[i];
report += ("Activity Title: " + activityInfo.getTitle()) + "\n";
report += ("Activity Class: " + activityInfo.getClazz()) + "\n";
report += ("Activity SuperClass: " + activityInfo.getSuperClazz()) + "\n";
report += ("Activity ImplementInterfaces: " + activityInfo.getImplementInterfaces()) + "\n";
report += ("Activity OnTop: " + activityInfo.isOnTop()) + "\n";
report += ("Activity Paused: " + activityInfo.isPaused()) + "\n";
report += ("Activity Stopped: " + activityInfo.isStopped()) + "\n";
var androidApkFields = activityInfo.getAndroidApkFields();
report += ("Activity Fields: " + androidApkFields.length) + "\n";
for (var j = 0; j < androidApkFields.length; j++) {
report += ("\t" + androidApkFields[j].toLine()) + "\n";
}
var methods = activityInfo.methods();
report += ("Activity Methods: " + methods.length) + "\n";
for (var j = 0; j < methods.length; j++) {
report += ("\t" + methods[j]) + "\n";
}
} catch(err) {
console.log(err);
}
}
} catch(err) {
console.log(err);
}
});
return report;
},
services: function() {
var report = "";
Java.perform(function() {
var radarAndroidClz = Java.use("gz.radar.Android");
var serviceInfos = radarAndroidClz.getServiceInfos();
report += "Found Services: " + serviceInfos.length + "\n";
for (var i = 0; i < serviceInfos.length; i++) {
report += ("------------------" + (i) + "--------------------") + "\n";
var serviceInfo = serviceInfos[i];
report += ("Service Class: " + serviceInfo.getName()) + "\n";
report += ("Service SuperClass: " + serviceInfo.getSuperClazz()) + "\n";
report += ("Service ImplementInterfaces: " + serviceInfo.getImplementInterfaces()) + "\n";
var androidApkFields = serviceInfo.getAndroidApkFields();
report += ("Service Fields: " + androidApkFields.length) + "\n";
for (var j = 0; j < androidApkFields.length; j++) {
report += ("\t" + androidApkFields[j].toLine()) + "\n";
}
var methods = serviceInfo.methods();
report += ("Service Methods: " + methods.length) + "\n";
for (var j = 0; j < methods.length; j++) {
report += ("\t" + methods[j]) + "\n";
}
}
});
return report;
},
objectinfo: function(objectId) {
var report = "";
Java.perform(function() {
var radarAndroidClz = Java.use("gz.radar.Android");
var objectInfo = radarAndroidClz.getObjectInfo(objectId);
if (!objectInfo) {
report += "Not Found Any Object."
return;
}
report += ("------------------Object--------------------") + "\n";
report += ("Object Class: " + objectInfo.getName()) + "\n";
report += ("Object SuperClass: " + objectInfo.getSuperClazz()) + "\n";
report += ("Object ImplementInterfaces: " + objectInfo.getImplementInterfaces()) + "\n";
var androidApkFields = objectInfo.getAndroidApkFields();
report += ("Object Fields: " + androidApkFields.length) + "\n";
for (var j = 0; j < androidApkFields.length; j++) {
report += ("\t" + androidApkFields[j].toLine()) + "\n";
}
var methods = objectInfo.methods();
report += ("Object Methods: " + methods.length) + "\n";
for (var j = 0; j < methods.length; j++) {
report += ("\t" + methods[j]) + "\n";
}
});
return report;
},
objecttoexplain: function(objectId) {
var report = "";
Java.perform(function() {
var radarAndroidClz = Java.use("gz.radar.Android");
var explainObjs = radarAndroidClz.object2Explain(objectId);
if (explainObjs == null) {
report += "Not Found Any Object.";
return;
}
if (explainObjs.isEmpty()) {
report += "Cannot Explain the Object " + objectId+".";
return;
}
report += "Found Objects: " + explainObjs.size() + "\n";
for (var i = 0; i < explainObjs.size(); i++) {
var key = explainObjs.getKey(i);
var _objectId = explainObjs.getObjectId(i);
report += ("------------------[" + key + "]--------------------") + "\n";
report += ("Object Class: " + explainObjs.getObjectClass(i)) + "\n";
report += ("Object Id:" + _objectId) + "\n";
}
});
return report;
},
viewinfo: function(viewId) {
var report = "";
Java.perform(function() {
var radarAndroidClz = Java.use("gz.radar.Android");
var viewInfo = radarAndroidClz.getViewInfo(viewId + "");
if (!viewInfo) {
report += "Not Found Any Views."
return;
}
report += ("------------------View--------------------") + "\n";
report += ("View Id: " + viewInfo.getViewId()) + "\n";
report += ("View IdName: " + viewInfo.getViewIdName()) + "\n";
report += ("View Text: " + viewInfo.getViewText()) + "\n";
report += ("View Visible: " + viewInfo.isVisible()) + "\n";
report += ("View Class: " + viewInfo.getName()) + "\n";
report += ("View SuperClass: " + viewInfo.getSuperClazz()) + "\n";
report += ("View ImplementInterfaces: " + viewInfo.getImplementInterfaces()) + "\n";
var androidApkFields = viewInfo.getAndroidApkFields();
report += ("View Fields: " + androidApkFields.length) + "\n";
for (var j = 0; j < androidApkFields.length; j++) {
report += ("\t" + androidApkFields[j].toLine()) + "\n";
}
var methods = viewInfo.methods();
report += ("View Methods: " + methods.length) + "\n";
for (var j = 0; j < methods.length; j++) {
report += ("\t" + methods[j]) + "\n";
}
});
return report;
},
appversion: function() {
var versionName = "";
Java.perform(function() {
var radarAndroidClz = Java.use("gz.radar.Android");
versionName = radarAndroidClz.getVersionName();
});
return versionName;
},
mainactivity: function() {
var mainactivityName = "";
Java.perform(function() {
var radarAndroidClz = Java.use("gz.radar.Android");
mainactivityName = radarAndroidClz.getMainActivity();
});
return mainactivityName;
},
};