Skip to content

Commit d20b56b

Browse files
authored
Create jit_modify_class_function_argument.js
1 parent 496b390 commit d20b56b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { MonoApiHelper, MonoApi } from '../vendors/frida-mono-api'
2+
import ClassHelper from '../libraries/class_helper'
3+
4+
/*
5+
// For JIT-compiled applications only.
6+
// This example script can intercept the following method (non-constructor).
7+
// Furthermore it modifies the first argument (string id).
8+
9+
namespace CompanyName.ProjectName.Views.Web.Html {
10+
11+
class HtmlWebView {
12+
13+
GetElement(string id) {
14+
// This function will be intercepted.
15+
}
16+
17+
}
18+
19+
}
20+
*/
21+
22+
// Intercept settings
23+
var settingClassName = "CompanyName.ProjectName.Views.Web.Html.HtmlWebView";
24+
var settingMethodName = "GetElement";
25+
var settingMethodArgCount = 1;
26+
27+
// The root AppDomain is the initial domain created by the runtime when it is initialized. Programs execute on this AppDomain.
28+
const domain = MonoApi.mono_get_root_domain()
29+
30+
// Get a reference to a certain class within the Xamarin application.
31+
var classInformation = ClassHelper.getClassByName(settingClassName);
32+
33+
// Attach interceptor and fish out the first method argument
34+
MonoApiHelper.Intercept(classInformation, settingMethodName, {
35+
onEnter: function(args) {
36+
console.log("Entered " + settingMethodName + " with " + settingMethodArgCount + " argument(s).");
37+
console.log("Value of `string id`: " + MonoApiHelper.StringToUtf8(args[1]));
38+
39+
args[1] = MonoApiHelper.StringNew('This is the replaced value of `string id`.', domain);
40+
},
41+
onLeave: function onLeave(log, retval, state) {
42+
console.log("Left " + settingMethodName + ".");
43+
}
44+
})
45+
46+
console.log(`'jit_modify_class_function_argument.js' attached and ready.`)

0 commit comments

Comments
 (0)