Xposed Framework is a great tool to take actions which Android SDK doesn't provide for developers. One of the great hacks that you can do is hooking a method. You can see parameters given to a method, with many other properties of it. There are some tutorials on Internet, but in this tutorials, they show hooking method without parameters or with class parameters. Its code is:
findAndHookMethod("com.android.settings.Settings", lpparam.classLoader,
"updateHeaderList", List.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//your code
}
});
If a parameter of method is primitive type, you cannot call it by its class type. For example; if the parameter is boolean, Boolean.class will not work and it will result NoSuchMethodError exception. The correct way is:
findAndHookMethod("android.net.wifi.WifiManager", lpparam.classLoader,
"setWifiEnabled", "boolean", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.args[0] = false;
XposedBridge.log("isWifiEnabled method will keep state as disabled..");
}
});
You need to pass a String to indicate parameter type. In this case, "boolean" will work. Thus, to point out primitive paramter type, we must pass a string with type name such as 'int', 'boolean' etc.
Thank you for this! Not only did I need to learn how to hook a method with xposed but by coincidence the xposed module im planning on writing is actually needing to hook android.net.wifi.wifimanager ! what a wonderful and strange coincidence thats the one you choose for this example!
ReplyDeletewhat would the string reference to a byte[] (byte array) be? Also, if multiple parameters, how are they delineated? e.x: "boolean", "bytearray"? or "boolean, bytearray"?
ReplyDeletenew byte[0].getClass(),
ReplyDeletewhat about if it take string param ?!
ReplyDeleteThanks for clearing that
ReplyDeleteSo i don't know if you'll read this. But i have a method that is called vpn(); this method doesn't have any parameter and i need it to return false. How can i do this?
ReplyDelete