-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhook_method.js
More file actions
60 lines (52 loc) · 1.9 KB
/
hook_method.js
File metadata and controls
60 lines (52 loc) · 1.9 KB
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
/**
* Dynamically hooks all overloads of a specified Java method in an Android app,
* logs its invocation and arguments, and replaces its arguments with user-specified ones.
*
* @param {Object} args - The input arguments for the hook.
* @param {string} args.className - Fully-qualified name of the Java class to hook (e.g., "com.example.MyClass").
* @param {string} args.methodName - Name of the method in the class to hook.
* @param {Array<any>} args.fnArgs - Array of values to overwrite the original method arguments with.
*
*/
import Java from "frida-java-bridge";
rpc.exports = {
run: function (args) {
const { className, methodName, fnArgs } = args;
Java.perform(function () {
var TargetClass = Java.use(className);
// Get all overloads of the method
var overloads = TargetClass[methodName].overloads;
send("[*] Hooking " + overloads.length + " overload(s) of " + className + "." + methodName);
overloads.forEach(function (overload) {
overload.implementation = function () {
send("\n[>] Called " + className + "." + methodName);
send(" ↪ Overload: " + overload.argumentTypes.map(t => t.className).join(", "));
// Log arguments
for (var i = 0; i < arguments.length; i++) {
send(" ↳ arg[" + i + "]: " + arguments[i]);
}
for (var i = 0; i < fnArgs.length; i++) {
arguments[i] = fnArgs[i];
}
// Call original method
overload.apply(this, arguments);
};
});
});
},
schema: function () {
return {
type: "object",
properties: {
className: { type: "string" },
methodName: { type: "string" },
fnArgs: {
type: "array",
items: {}, // Accepts any types
},
},
required: ["className", "methodName", "fnArgs"],
additionalProperties: false,
};
},
};