Global Static Object Possible? - Xposed General

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.

Related

[Q] Sharing data between Xposed module and activity

Hi,
I have an Xposed module that listens for certain events and then notify the main application/Activity that contains this module about the events. I tried to put the events into a static buffer class that's accessible from both the module and Activity. But the buffer is always empty. Right now, I have to use Broadcast to achieve the notification. Is it impossible to share data between the module and Activity via static in-memory objects? Thank you!
AFAIK, you can't do it like that when xposed module runs in a different process than your app.
Xposed module hooking on one package and your app package are isolated processes that cannot share memory.
One way is to use broadcast, as you mentioned.
Another way is to create a service within your app and use ServiceConnection to bind to it and execute actions on it
Example of such service: https://github.com/GravityBox/Gravi...o/kitkat/gravitybox/KeyguardImageService.java
Example how that service is called from system context (different process): https://github.com/GravityBox/Gravi...m/ceco/kitkat/gravitybox/ModDisplay.java#L521

[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

Put Settings from hook

Hook is in PhoneWindowManager class, I need to put a value to Settings.System. ContentResolver from the available mContext variable is used.
I get the following:
Code:
InvocationTargetError: java.lang.SecurityException: Package android does not belong to 10036
10036 is UID of my module.
- Which context did you use to get content resolver?
- Depends on where your hook is.
Although your hook is in phone window manager, it still depends from where method you are hooking was called from. If it was called from different package that has different permissions (such as your module app), you will have to clear an identity of calling package while using system settings.
Something like:
Code:
long ident = Binder.clearCallingIdentity();
try {
// store to system settings or whatever
} finally {
Binder.restoreCallingIdentity(ident);
}
- Another option is to add necessary permission to your module's manifest
My module already has WRITE_SETTINGS permission. I use mContext variable that is available in PhoneWindowManager, never had a problem with it. Calling from a separate thread that is created in screenTurnedOff() method.
PhoneWindowManager has a lot of similar code involving Settings.System:
Code:
android.provider.Settings.System.putIntForUser(mContext.getContentResolver(), "screen_brightness_mode", 0, -3);
I tried ...ForUser methods with -2, -3 and 1000 UIDs - still the same error. Regular methods should use current process UID, so it's 1000 anyway.
No idea how it still knows that Xposed module is involved, code is supposed to be executed as if it's a part of a hooked app.
But I guess it knows) so clearing calling identity works perfectly, thanks.
I assume thread in screenTurnedOff you mentioned is your own you created? If yes, then for some reason thread in which runs phone window manager is thinking it's some kind of a foreign thread although created within phone window manager. Question is where screenTurnedOff was called from. If it's an IPC call then it's clear it has different identity. If it's not that case then it's definitely strange.
C3C076 said:
Question is where screenTurnedOff was called from. If it's an IPC call then it's clear it has different identity. If it's not that case then it's definitely strange.
Click to expand...
Click to collapse
screenTurnedOff is a stock method, it's called whenever it's called Definitely not from my module. I bet there is an explanation, something complicated)

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

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...

[Help] Creating/Modifying touch events

I'd like to make a module that can either create or modify touch events on a specific app. I don't have access to the app's source.
An example of the usage would be to make every x value of a touch event in that app to have an offset of say 200 pixels, so if you tap the center, the touch will be registered as a bit more to the right.
I've tried to override the getX() method of the MotionEvent class. From logging, I can see that the method is called, but changing the return value has no effect.
Is there any other method within the framework that I should look into, or would my best bet be trying to find the exact view that will be affected?
And if I were to modify a framework method, how would I get it to only work for a specific view/activity? I haven't found a way to find which app is currently in view, as they may be loaded before being accessed.

Categories

Resources