-
Notifications
You must be signed in to change notification settings - Fork 14
/
fridaHookSkeleton.js
86 lines (74 loc) · 2.52 KB
/
fridaHookSkeleton.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
/*
* iOS Frida Hooking Skeleton Script
*
* (c) 2017 INTEGRITY S.A.
* By: Herman Duarte <hd@integrity.pt>
*/
// lets check if the env is available
if (ObjC.available)
{
// class or classes that we want to hook methods
var classes = [''];
// methods we want to hook, at least from one of the classes above
var methodsWhiteList = [''];
for (var className in ObjC.classes)
{
if (ObjC.classes.hasOwnProperty(className))
{
if (classes.indexOf(className) > -1)
{
console.log('[*] Start: Hooking into "' + className + '" methods');
var methods = ObjC.classes[className].$ownMethods;
for (var i = 0; i < methods.length; i++)
{
// if the method is in the whitelist then we can intercepted it
if (methodsWhiteList.indexOf(methods[i]) > -1)
{
try
{
var _className = "" + className;
var _methodName = "" + methods[i];
var method = ObjC.classes[_className][_methodName];
console.log('Hooking: ' + _methodName);
Interceptor.attach(method.implementation, {
onEnter: function (args) {
this._className = ObjC.Object(args[0]).toString();
this._methodName = ObjC.selectorAsString(args[1]);
console.log("\n[*] Detected call to: " + this._className + " -> " + this._methodName);
if (this._methodName == '')
{
console.log(" [*] param1: " + (new ObjC.Object(args[2])).toString());
console.log(" [*] param2': " + (new ObjC.Object(args[3])).toString());
//console.log('\tBacktrace:\n\t' + Thread.backtrace(this.context,Backtracer.ACCURATE).map(DebugSymbol.fromAddress).join('\n\t'));
}
},
onLeave: function (retval) {
if (this._methodName == '' )
{
var returnvalue = new ObjC.Object(retval);
console.log(" [*] Return value: " + returnvalue.toString());
}
}
});
console.log(' [*] Hooked: ' + _methodName);
}
catch(error)
{
console.log('Hooking Falied');
}
}
}
console.log('[*] Completed: Hooking into "' + className + '" methods');
}
}
}
}
else
{
console.log('Objective-C Runtime is not available!');
}
/*
* ToDo:
* - obtain the methods param automatically
* - create onenter and onleave skeletons to print the params
*/