Hi,
I am trying to analyze an application(obfuscated with dexguard) which uses DexFile to load classes during runtime.
To list out what all classes the application call, I use the following Xposed code - (that's because the code is obfuscated and we cannot search for DexFile on the decompiled code).
Code:
findAndHookMethod("java.lang.ClassLoader", lpparam.classLoader, "loadClass", String.class, new XC_MethodHook() {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String classname = (String) param.args[0];
XposedBridge.log("Class Called - " + classname + " " + i++);
}
This lists all the classes and I see that the application calls "dalvik.system.DexFile". I used the following code to hook into DexFile constructor -
Code:
Constructor<?> constructDexFile = findConstructorExact(dalvik.system.DexFile.class, String.class);
XposedBridge.hookMethod(constructDexFile, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("DexFile Class 1 called");
}
});
Constructor<?> constructDexFile1 = findConstructorExact(dalvik.system.DexFile.class, File.class);
XposedBridge.hookMethod(constructDexFile1, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("DexFile Class 2 called");
}
});
Analyzing the log output, I see no trace of DexFile constructor being called.
Can someone help me out on how to analyze such application?
Related
Is there a way to use System context from non system app?
I try to create xposed module that enable double-tap to sleep in my specific app (the app is for G3 smart case only, so I try to mimic LG's stock Quick Circle apps).
I tried to override PowerManager.gotoSleep that will do
[CODEjava] mService.gotoSleep(time, GO_TO_SLEEP_REASON_DEVICE_ADMIN)[/CODE]
but it seem that the GO_TO_SLEEP_REASON_USER isn't the problem.
can I save the context of a system app for later use? using this code, context somewhy is null...
Java:
public class XposedModule implements IXposedHookLoadPackage {
static Context context;
[user=439709]@override[/user]
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.yoavst.quickapps")) {
findAndHookMethod("com.yoavst.quickapps.DoubleTapper", lpparam.classLoader, "onDoubleTap", Context.class, MotionEvent.class, new XC_MethodHook() {
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("onDoubleTap After; context: " + (context == null ? "null" : "notNull"));
if (context != null) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
powerManager.goToSleep(((MotionEvent) param.args[1]).getEventTime());
}
}
});
} else if (lpparam.packageName.equals("com.android.systemui")) {
findAndHookMethod("com.android.systemui.SystemUIService", lpparam.classLoader, "onCreate", new XC_MethodHook() {
[user=439709]@override[/user]
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// this will be called before the clock was updated by the original method
}
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("hooking onCreate: " + (param.thisObject == null ? "null" :"not Null"));
context = (Service) param.thisObject;
XposedBridge.log("context: " + (context == null ? "null" :"not Null"));
}
});
}
}
}
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
GermainZ said:
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
Click to expand...
Click to collapse
I need the context of an app with DEVICE_POWER permission (level 2 permission).
Oh, wait — your code won't work at all the way you expect it to work. Keep in mind the hooked code is running in the hooked app's process, so even though you set "context" in com.android.systemui, the "context" variable is still null in the "com.yoavst.quickapps" process (and will *always* be null).
You probably want to send a broadcast from your app instead, and register a BroadcastReceiver somewhere in SystemUI to handle it.
@yoavst you need to use a Device Policy Manager that will allow you to turn off the display. Doesn't even require root or xposed.
How to hook a onReceive method which is inside BroadcastReceiver?
Code:
public class RecentsActivity extends Activity
{
mIntentReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
...
}
};
}
I want to get my hook called when onReceive is invoked.
Anyone know?
mIntentReceiver is registered within onCreate method, so...
PHP:
XposedHelpers.findAndHookMethod(RecentsActivity.class, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// get the field
final BroadcastReceiver mIntentReceiver = (BroadcastReceiver) XposedHelpers.getObjectField(param.thisObject, "mIntentReceiver");
// hook its class
XposedHelpers.findAndHookMethod(mIntentReceiver.getClass(), "onReceive", Context.class, Intent.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// check it !!!
BroadcastReceiver thiz = (BroadcastReceiver) param.thisObject;
if (thiz == mIntentReceiver) {
// get parameters
Context context = (Context) param.args[0];
Intent intent = (Intent) param.args[1];
// do your job...
}
}
});
}
});
Hope that helps you!!
Hi there. I'm trying to write a module for an app that looks like this:
Code:
public class ThirdPartyAppView extends View {
// ...
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// ...
// do some stuff to calculate desired dimensions
// ...
setMeasuredDimension(desiredWidth, desiredHeight);
}
// ...
}
I want to change the calculated dimensions, so I'm replacing the onMeasure method of this class, like this:
Code:
XC_MethodReplacement onMeasure_replacement = new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
View v = (View) param.thisObject;
int paramInt1 = (Integer) param.args[0];
int paramInt2 = (Integer) param.args[1];
// ...
// do MY OWN stuff to calculate desired dimensions
// ...
setMeasuredDimension(myDesiredWidth, myDesiredHeight); // here is the problem call
return null;
}
};
findAndHookMethod("com.third.party.app.ThirdPartyAppView",
lpparam.classLoader,
"onMeasure", int.class, int.class,
onMeasure_replacement);
The roadblock I'm hitting is
Code:
The method setMeasuredDimension(int, int) is undefined for the type new XC_MethodReplacement(){}
Any pointers?
On closer look, that should be v.setMeasuredDimension:
Code:
View v = (View) param.thisObject;
// ...
v.setMeasuredDimension(myDesiredWidth, myDesiredHeight); // here is the problem call
return null;
But both onMeasure() and setMeasuredDimension() are protected methods on class ThirdPartyAppView. How could I call them from the module? I can't instance ThirdPartyAppView...
Found a solution thanks to http://forum.xda-developers.com/showpost.php?p=57190802&postcount=2
Ended up hooking on the superclass instead (android.view.View), doing things before calling setMeasuredDimension() there, and checking class name within the hook. This did the trick.
Code:
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(com.third.party.app))
return;
XC_MethodHook setMeasuredDimensionHook = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.thisObject.getClass().getName().equals(com.third.party.app.ThirdPartyAppView") {
View v = (View) param.thisObject;
int paramInt1 = (Integer) param.args[0];
int paramInt2 = (Integer) param.args[1];
// ...
// calculate my dimensions here
// ...
param.args[0] = desiredWidth;
param.args[1] = desiredHeight;
}
};
findAndHookMethod("android.view.View",
lpparam.classLoader,
"setMeasuredDimension", int.class, int.class,
setMeasuredDimensionHook);
}
Nephiel said:
Found a solution thanks to http://forum.xda-developers.com/showpost.php?p=57190802&postcount=2
Ended up hooking on the superclass instead (android.view.View), doing things before calling setMeasuredDimension() there, and checking class name within the hook. This did the trick.
Code:
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(com.third.party.app))
return;
XC_MethodHook setMeasuredDimensionHook = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.thisObject.getClass().getName().equals(com.third.party.app.ThirdPartyAppView") {
View v = (View) param.thisObject;
int paramInt1 = (Integer) param.args[0];
int paramInt2 = (Integer) param.args[1];
// ...
// calculate my dimensions here
// ...
param.args[0] = desiredWidth;
param.args[1] = desiredHeight;
}
};
findAndHookMethod("android.view.View",
lpparam.classLoader,
"setMeasuredDimension", int.class, int.class,
setMeasuredDimensionHook);
}
Click to expand...
Click to collapse
Another way is to "emulate" call to setMeasuredDimension directly from onMeasure hook.
Example: https://github.com/GravityBox/Gravi...kitkat/gravitybox/ModQuickSettings.java#L1358
"Emulating" means you basically execute the same code that the original method does.
Of course, attention should be paid to different android versions and potential differences in setMeasuredDimension implementation.
Hi all,
I tried (partially succesful) to shift the status bar to the bottom of the screen. Unfortunatelly a black rectangle at the former statusbar position stays and keeps the apps away to use the full space (see picture below).
Here is my code so far:
Code:
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("com.android.systemui"))
return;
else {
XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.phone.PhoneStatusBar", lpparam.classLoader, "getStatusBarGravity", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) {
return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL;
}
});
XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.phone.PhoneStatusBar", lpparam.classLoader, "getStatusBarHeight", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) {
return 65;
}
});
}
I tried already to override the resource "status_bar_height" with "0", but without success (Not found):
Code:
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
String MODULE_PATH = startupParam.modulePath;
XModuleResources modRes = XModuleResources.createInstance(MODULE_PATH, null);
XResources.setSystemWideReplacement("android", "dimension", "status_bar_height", modRes.fwd(R.dimen.my_height));
}
The XPosed-Modul Dimension Editor also doesn't work by the way.
Maybe I could somehow make some magic in the PhoneWindowManager.java to let the apps fill till the screen top, but I don't know how:
https://github.com/DirtyUnicorns-Ki.../internal/policy/impl/PhoneWindowManager.java
Further information: Dirty Unicorn ROM for Galaxy Note N7000 KitKat.
Thank you very much!
I have searched relative keyword such as `sensor` in the repo, but could not find the answer.
I want to hook the step counter's sensor to do some auto-testing jobs on a health-kit app. Basically, we could get the steps by listening the SensorManager, the demo code would be
Code:
public class StepsActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private TextView count;
boolean activityRunning;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_steps);
count = (TextView) findViewById(R.id.count);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
@Override
protected void onResume() {
super.onResume();
activityRunning = true;
Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if (countSensor != null) {
sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
} else {
Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onPause() {
super.onPause();
activityRunning = false;
}
@Override
public void onSensorChanged(SensorEvent event) {
if (activityRunning) {
count.setText(String.valueOf(event.values[0]));
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
I've read the tutorial, I know we could hook a specific function in a specific class, such as
Code:
findAndHookMethod("com.android.systemui.statusbar.policy.Clock", lpparam.classLoader, "updateClock", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
TextView tv = (TextView) param.thisObject;
String text = tv.getText().toString();
tv.setText("time is:"+text);
tv.setTextColor(Color.RED);
}
});
But I'm wondering how to hook the data on system sensor?
I got the answer from github user townbull right now
I'm still a new user here and I was not permitted to publish external link here.
/XposedExp/blob/master/src/com/samsung/xposedexp/SensorHooks.java
coom said:
I got the answer from github user townbull right now
I'm still a new user here and I was not permitted to publish external link here.
/XposedExp/blob/master/src/com/samsung/xposedexp/SensorHooks.java
Click to expand...
Click to collapse
hi,i found that code is about samsung,what about nexus5 or other phone?