[Q] Is static members shared between processes in XPosed hook class? - Xposed General

Here's what I think XPosed does:
1. Before zygote_init, hook all apis and insert xposed_before_xxx and xposed_after_xxx method (where xxx is the name of the api).
2. Load modules. Load hook class, realize it and keep it in memory of zygote. For each injecting method, add it to the private list of xposed_before/after_xxx.
3. When an new app loads (forks from zygote), it also forked the hook class and the hooked method.
4. When an app calls xxx, it actually runs xposed_before_xxx first, and the latter calls every inject method in its private list. Then the original api is called. Then xposed_after_xxx is called, and deals with itself's list.
So for each app, hook class is individual after forking from zygote. So, static members are not shared. Cause each hook class has only one instance in an app, static members act the same as non-static members. Am I right?
And by the way, how does a xposed module to communicate between processes? I've seen a post realizing its own rpc by getting context and creating a service. Any simpler ways for just single direction transferring? Currently I'm using XSharedPreference and SharedPreference, but then then the hook method can't write back anything (such as logging). Any ideas to solve this?
Thanks for reading my long & poor English...

Related

[Q] Can Xposed hook native methods?

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.

Global Static Object Possible?

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.

[Q] how can i get the context in a service?

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

[Q] Is Java native function unhookable?

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.

Q:xposed hook all methods of an app and monitor performance

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?

Categories

Resources