Last active
February 24, 2021 09:54
-
-
Save hluwa/1a7730d65c8b53cbf3c9d9e8a0f33350 to your computer and use it in GitHub Desktop.
[WatchEvents] Frida watch android onClick event.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Author: hluwa <hluwa888@gmail.com> | |
| * HomePage: https://github.com/hluwa | |
| * CreatedTime: 2020/3/8 22:42 | |
| * */ | |
| var jclazz = null; | |
| var jobj = null; | |
| function getObjClassName(obj) { | |
| if (!jclazz) { | |
| var jclazz = Java.use("java.lang.Class"); | |
| } | |
| if (!jobj) { | |
| var jobj = Java.use("java.lang.Object"); | |
| } | |
| return jclazz.getName.call(jobj.getClass.call(obj)); | |
| } | |
| function watch(obj, mtdName) { | |
| var listener_name = getObjClassName(obj); | |
| var target = Java.use(listener_name); | |
| if (!target || !mtdName in target) { | |
| return; | |
| } | |
| // send("[WatchEvent] hooking " + mtdName + ": " + listener_name); | |
| target[mtdName].overloads.forEach(function (overload) { | |
| overload.implementation = function () { | |
| send("[WatchEvent] " + mtdName + ": " + getObjClassName(this)); | |
| return this[mtdName].apply(this, arguments); | |
| }; | |
| }) | |
| } | |
| rpc.exports = { | |
| onclick: function () { | |
| Java.perform(function () { | |
| Java.use("android.view.View").setOnClickListener.implementation = function (listener) { | |
| if (listener != null) { | |
| watch(listener, 'onClick'); | |
| } | |
| return this.setOnClickListener(listener); | |
| }; | |
| Java.choose("android.view.View$ListenerInfo", { | |
| onMatch: function (instance) { | |
| instance = instance.mOnClickListener.value; | |
| if (instance) { | |
| watch(instance, 'onClick'); | |
| } | |
| }, | |
| onComplete: function () { | |
| } | |
| }) | |
| }) | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment