Letts assume there is a method
public static native boolean doSomething(params...);
which gets called by regular Java code.
Can Xposed hook it?
EDIT: I'm wrong, see rovo's answer.
Yes, native methods can be hooked. However, in case this is for an app's code, it has to be done after System.loadLibrary(), otherwise the latter overwrites the hook. Ideally, the framework should take care of this itself, but it's not straight-forward and the has been vey little need for this.
rovo89 said:
Yes, native methods can be hooked. However, in case this is for an app's code, it has to be done after System.loadLibrary(), otherwise the latter overwrites the hook. Ideally, the framework should take care of this itself, but it's not straight-forward and the has been vey little need for this.
Click to expand...
Click to collapse
I've always assumed this wasn't the case. Just to clarify, Xposed is able to hook native functions, but not (native) C/C++ code/libraries? I've read more than once it can't so I'm a bit confused. Thanks for the correction.
GermainZ said:
Just to clarify, Xposed is able to hook native functions, but not (native) C/C++ code/libraries?
Click to expand...
Click to collapse
Correct. Only JNI functions can be hooked, i.e. those which are declared in and called by Java code.
How to do it "after System.loadLibrary()"?
How you go about hooking such methods? I am trying to hook some API methods, mainly the ones declared in the "Connectivity" class one such example is "isTetheringSupported" however I am struggling to do so as when I hook the method directly, the hook is never executed as I believe it is being called via the java.lang.reflect.Method invoke method, and when I try and hook that method I get the following error "java.lang.NoSuchMethodError: java.lang.reflect.Method#invoke()#exact"
hwhh_1 said:
How you go about hooking such methods? I am trying to hook some API methods, mainly the ones declared in the "Connectivity" class one such example is "isTetheringSupported" however I am struggling to do so as when I hook the method directly, the hook is never executed as I believe it is being called via the java.lang.reflect.Method invoke method, and when I try and hook that method I get the following error "java.lang.NoSuchMethodError: java.lang.reflect.Method#invoke()#exact"
Click to expand...
Click to collapse
Are you talking about EdXposed? If so it should be noted that hook not working for a particular method can also be a result of art compiler optimizations. E.g. if the method is simple and not called from many places, compiler will include body of such method directly into methods that call that method. It's called inlining. So while you can see method at source code level, during runtime it's empty and never called as original body became part of another method. To overcome this you have to find a different strategy, e.g. hook such methods that are less likely to become inlined.
C3C076 said:
Are you talking about EdXposed? If so it should be noted that hook not working for a particular method can also be a result of art compiler optimizations. E.g. if the method is simple and not called from many places, compiler will include body of such method directly into methods that call that method. It's called inlining. So while you can see method at source code level, during runtime it's empty and never called as original body became part of another method. To overcome this you have to find a different strategy, e.g. hook such methods that are less likely to become inlined.
Click to expand...
Click to collapse
In order to see if it inlined, there is a setting in EDXPOSED to deoptimize boot image.
Currently I'm reading off a SQLITE database and storing the results in memory for further processing, lets call this Object X.
I put Object X is lets say in Class A, so I basically have a static reference to it.
Is it possible in any way to maintain the same copy of Object X in all of the process that I hook to?
Currently, Object X will become null as a package loads via my class that implements IXposedHookLoadPackage (it appears that it has its own version of Object X for every package loaded).
jasonpohzh said:
Is it possible in any way to maintain the same copy of Object X in all of the process that I hook to?
Click to expand...
Click to collapse
In short: No. Every process has its own memory. Whatever you set up in initZygote() will be cloned for the application processes, but any changes you do in one process won't be reflected in the other processes (including the main/Zygote process). You have to use some kind of IPC (inter-process communication) for that, like broadcasts or simply a file.
i am programing a module, in some case, i try to use AndroidAppHelper.currentApplication to get the context, but it return null. is there any way to get context? or build a communication with another app. i just want to receive data form another app. thank you
If you mean android.app.Service class, simply cast param.thisObject to Context. Service class is derived from Context. http://developer.android.com/reference/android/app/Service.html
I have used NDK development techs to create a simple Android App that connects remote server using socket.
The JNI method name is "public native static void doConnect(String ip,int port,String imei);"
While my attempt to hook it results in "java.lang.NoSuchMethodError"
Is Xposed not able to hook JNI functions?
PS: If there is a function hooked, how can I get the parameters it received?
XDAchushu10 said:
I have used NDK development techs to create a simple Android App that connects remote server using socket.
The JNI method name is "public native static void doConnect(String ip,int port,String imei);"
While my attempt to hook it results in "java.lang.NoSuchMethodError"
Is Xposed not able to hook JNI functions?
PS: If there is a function hooked, how can I get the parameters it received?
Click to expand...
Click to collapse
I've read this post: http://forum.xda-developers.com/xposed/creating-nfc-module-nosuchmethoderror-t2811440
The problem is that I didn't list the paramters in "findAndHookMethod".
And that's it! It's been solved.
I developed a module to monitor the performance of an app (for example: wechat , whatsapp, any app is ok), my motivation is to get the delay of all the methods of the app. So first I get all the classes list and save as a txt file in sdcard, then in my module I read the class name one by one and get declaredmethods and hook every method of the class.
Actually this module successed, but the app (wechat app) crashed (NO RESPONSE) , the app is very complicated and the large amount of classes,methods hook impact the app's normal running.
Q: I want to know tracking and hooking all methods of an app is possible? HOW TO FIX THIS PROBLEM THAT THE APP DO NOT RESPONSE?