[Q] Why am I receiving NoSuchMethod for adjustStreamVolume - Xposed General

I wrote a module for myself to get started with xposed development when my phone (LG G2) was on Jelly Bean. I upgraded my phone to Kit Kat and noticed my module was no longer working and was firing a NoSuchMethod exception:
Code:
java.lang.NoSuchMethodError: android.media.AudioService#adjustStreamVolume(int,int,int)#exact
at de.robv.android.xposed.XposedHelpers.findMethodExact(XposedHelpers.java:179)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:129)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:136)
at com.bkdev.android.xposed.mods.ringtonesync.VolumeSync.handleLoadPackage(VolumeSync.java:21)
at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
at de.robv.android.xposed.XposedBridge$2.beforeHookedMethod(XposedBridge.java:228)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
at com.android.server.ServerThread.initAndLoop(Native Method)
at com.android.server.SystemServer.main(SystemServer.java:1478)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
at com.android.server.SystemServer.main(Native Method)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
I checked the API and it doesn't appear that adjustStreamVolume was deprecated or changed in any way, so I'm kind of confused as to why this would be happening. Maybe it's just my ignorance of xposed development so far, but here's my code with all of meat stripped out. From what I gather, the findAndHookMethod is the problem anyway. Any assistance as to why this is no longer working would be greatly appreciated. Let me know if more details are needed.
Code:
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("android"))
return;
// XposedBridge.log("In com.android.media");
findAndHookMethod("android.media.AudioService", lpparam.classLoader, "adjustStreamVolume", int.class, int.class, int.class, new XC_MethodHook() {
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("********Hooked 'adjustStreamVolume'********");
}
});
}

Try use InitZygote for "android".

Checking the source:
Java:
/** [user=690402]@see[/user] AudioManager#adjustStreamVolume(int, int, int) */
public void adjustStreamVolume(int streamType, int direction, int flags,
String callingPackage) {
…
}

@GermainZ
When I look at the developer reference for adjustStreamVolume in the AudioManager class, I don't see the extra parameter (String callingPackage) that you reference. Am I looking in the wrong place for the method I want to hook?
http://developer.android.com/reference/android/media/AudioManager.html#adjustStreamVolume(int, int, int)
Sent from my LG-LS980 using Tapatalk

bkertz said:
@GermainZ
When I look at the developer reference for adjustStreamVolume in the AudioManager class, I don't see the extra parameter (String callingPackage) that you reference. Am I looking in the wrong place for the method I want to hook?
http://developer.android.com/reference/android/media/AudioManager.html#adjustStreamVolume(int, int, int)
Sent from my LG-LS980 using Tapatalk
Click to expand...
Click to collapse
You're hooking AudioService, the page you're linking is the documentation for AudioManager.

GermainZ said:
You're hooking AudioService, the page you're linking is the documentation for AudioManager.
Click to expand...
Click to collapse
Well I really feel dumb now. It helps to look in the right place. Strange that this worked before for me. Do you have any recommendations between using AudioManager vs. AudioService? It appears AudioService is not on the developer pages.
Sent from my LG-LS980 using Tapatalk

bkertz said:
Well I really feel dumb now. It helps to look in the right place. Strange that this worked before for me. Do you have any recommendations between using AudioManager vs. AudioService? It appears AudioService is not on the developer pages.
Sent from my LG-LS980 using Tapatalk
Click to expand...
Click to collapse
Hook methods that are available in the SDK when you can. Hooking internal methods may stop working on newer versions since they can change at any time (they're internal methods after all).

Thanks.
Sent from my LG-LS980 using Tapatalk

Related

[Q] Can't hook com.android.commands.pm.PM

Hello,
I want to hook a method in com.android.commands.pm.PM but i fail to load this class (i get class not found exception)
I tried both using initZygote approach and handleLoadPackage approach, both with the same result..
what am i doing wrong?
Thanks!
Maybe @GermainZ can help?
Can you post the relevant Xposed code and exact error, please?
Hi,
Thanks.
Yes, here are my both tries...
Code:
public class XPm implements IXposedHookZygoteInit, IXposedHookLoadPackage {
[user=439709]@override[/user]
public void initZygote(StartupParam startupParam) throws Throwable {
String methodName = "installFailureToString";
XC_MethodHook hookMethod = new XC_MethodHook() {
[user=439709]@override[/user]
protected void beforeHookedMethod(final MethodHookParam param)
throws Throwable {
int result = (Integer) param.args[0];
switch (result) {
case 1:
param.setResult("BLA");
break;
case 2:
param.setResult("BLA BLA");
break;
}
}
};
final Class<?> clsPMS = XposedHelpers.findClass(
"com.android.commands.pm.Pm$1", XPm.class.getClassLoader());
XposedHelpers.findAndHookMethod(clsPMS, methodName, int.class,
hookMethod);
}
[user=439709]@override[/user]
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
String methodName = "installFailureToString";
if (!lpparam.packageName.equals("com.android.commands.pm"))
return;
Log.d(TAG, "com.android.commands.pm is loaded...");
XC_MethodHook hookMethod = new XC_MethodHook() {
[user=439709]@override[/user]
protected void beforeHookedMethod(final MethodHookParam param)
throws Throwable {
int result = (Integer) param.args[0];
switch (result) {
case 1:
param.setResult("BLA");
break;
case 2:
param.setResult("BLA BLA");
break;
}
}
};
final Class<?> clsPMS = XposedHelpers.findClass(
"com.android.commands.pm.Pm", XPm.class.getClassLoader());
XposedHelpers.findAndHookMethod(clsPMS, methodName, int.class,
hookMethod);
}
}
Well, there is no android.commands.pm. Not sure what you're trying to hook, but you should get the correct class name first.
PS. Please wrap your code in [CODE][/CODE] tags next time.
GermainZ said:
Well, there is no android.commands.pm. Not sure what you're trying to hook, but you should get the correct class name first.
PS. Please wrap your code in [CODE][/CODE] tags next time.
Click to expand...
Click to collapse
Hi,
sure, Sorry.
one of the things android.commands.pm.Pm is doing is to print the ADB installation message like "Failure [INVALIED_APK]"
my goal is to print my own message, so it's either by hooking the method i tried or by hooking PackageManager.class.getFields() and add my own fields.
this is the code from Pm.Java
Code:
/**
* Converts a failure code into a string by using reflection to find a matching constant
* in PackageManager.
*/
private String installFailureToString(int result) {
Field[] fields = PackageManager.class.getFields();
for (Field f: fields) {
if (f.getType() == int.class) {
int modifiers = f.getModifiers();
// only look at public final static fields.
if (((modifiers & Modifier.FINAL) != 0) &&
((modifiers & Modifier.PUBLIC) != 0) &&
((modifiers & Modifier.STATIC) != 0)) {
String fieldName = f.getName();
if (fieldName.startsWith("INSTALL_FAILED_") ||
fieldName.startsWith("INSTALL_PARSE_FAILED_")) {
// get the int value and compare it to result.
try {
if (result == f.getInt(null)) {
return fieldName;
}
} catch (IllegalAccessException e) {
// this shouldn't happen since we only look for public static fields.
}
}
}
}
}
// couldn't find a matching constant? return the value
return Integer.toString(result);
}
If it's not possible to hook this method, i understand i should add my own fields to packageManager
Thanks!
So we're talking about this? You haven't pasted the exact error but I'm guessing it's failing because you're using the wrong classloader. In initZygote, you shouldn't normally pass a classloader — just pass "null". In handleLoadPackage, use the hooked process' classloader (lpparam.classLoader).
EDIT: You can change/get a method's return value using param.setResult/param.getResult. Check the wiki for some more info.
GermainZ said:
So we're talking about this? You haven't pasted the exact error but I'm guessing it's failing because you're using the wrong classloader. In initZygote, you shouldn't normally pass a classloader — just pass "null". In handleLoadPackage, use the hooked process' classloader (lpparam.classLoader).
EDIT: You can change/get a method's return value using param.setResult/param.getResult. Check the wiki for some more info.
Click to expand...
Click to collapse
Hi,
First of all thanks a lot!
this is the exception I'm getting when trying to initZygote and pass null as classloader:
Code:
de.robv.android.xposed.XposedHelpers$ClassNotFoundError: java.lang.ClassNotFoundException: com.android.commands.pm.Pm
I/Xposed ( 8491): at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:52)
I/Xposed ( 8491): at com.myapp.Hooks.XPm.initZygote(XPm.java:29)
I/Xposed ( 8491): at de.robv.android.xposed.XposedBridge.loadModule(XposedBridge.java:437)
I/Xposed ( 8491): at de.robv.android.xposed.XposedBridge.loadModules(XposedBridge.java:386)
I/Xposed ( 8491): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:120)
I/Xposed ( 8491): at dalvik.system.NativeStart.main(Native Method)
I/Xposed ( 8491): Caused by: java.lang.ClassNotFoundException: com.android.commands.pm.Pm
I/Xposed ( 8491): at java.lang.Class.classForName(Native Method)
I/Xposed ( 8491): at java.lang.Class.forName(Class.java:204)
I/Xposed ( 8491): at external.org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823)
I/Xposed ( 8491): at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:50)
I/Xposed ( 8491): ... 5 more
I/Xposed ( 8491): Caused by: java.lang.NoClassDefFoundError: com/android/commands/pm/Pm
I/Xposed ( 8491): ... 9 more
I/Xposed ( 8491): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.commands.pm.Pm" on path: DexPathList[[zip file "/data/data/de.robv.android.xposed.installer/bin/XposedBridge.jar"],nativeLibraryDirectories=[/system/lib]]
BTW, i also tried this approach:
Code:
final Class<?> clsPm = XposedHelpers.findClass("android.content.pm.PackageManager", XPm.class.getClassLoader());
XposedHelpers.setAdditionalStaticField(clsPm, "MY_MESSAGE", 1000);
But it doesn't seem to work either...
As I said, you're using the wrong class loader.
Yes, i understand that, but which class loader should I use?
actually, which approach is better for this case? use initZygote or handleLoadPackage?
this how i did it this time:
Code:
final Class<?> clsPMS = XposedHelpers.findClass("com.android.commands.pm.Pm", null);
XposedHelpers.findAndHookMethod(clsPMS, methodName,int.class, hookMethod);
I'd use initZygote since it's more readable/shorter.
As for which class loader to use, please see post #7.
I tried that (please see post #10), is that what you meant? since i got the same exception as in post #8
shnapsi said:
I tried that (please see post #10), is that what you meant? since i got the same exception as in post #8
Click to expand...
Click to collapse
You didn't indicate anything was wrong in post #10, I assumed that had worked. As usual, you should post the full code (including the initZygote/handleLoadPackage part so we know which you're using) and the exact error.
This is how you'd do it in initZygote:
Java:
public void initZygote(StartupParam startupParam) throws Throwable {
findAndHookMethod("full.class.Name", null, "methodName",
SomeArgument.class, new XC_MethodHook() {
[PLAIN]@Override[/PLAIN]
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
// Do something.
}
}
);
}
And in handleLoadPackage:
Java:
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("some.package.name"))
return;
findAndHookMethod("full.class.Name", lpparam.classLoader, "methodName",
SomeArgument.class, new XC_MethodHook() {
[PLAIN]@Override[/PLAIN]
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
// Do something.
}
}
);
}
GermainZ said:
You didn't indicate anything was wrong in post #10, I assumed that had worked. As usual, you should post the full code (including the initZygote/handleLoadPackage part so we know which you're using) and the exact error.
This is how you'd do it in initZygote:
Java:
public void initZygote(StartupParam startupParam) throws Throwable {
findAndHookMethod("full.class.Name", null, "methodName",
SomeArgument.class, new XC_MethodHook() {
[PLAIN]@Override[/PLAIN]
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
// Do something.
}
}
);
}
And in handleLoadPackage:
Java:
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("some.package.name"))
return;
findAndHookMethod("full.class.Name", lpparam.classLoader, "methodName",
SomeArgument.class, new XC_MethodHook() {
[PLAIN]@Override[/PLAIN]
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
// Do something.
}
}
);
}
Click to expand...
Click to collapse
Hi,
Strange since i do see in #10 an example (not full code...) of how i tried to do it.
anyway, I don't think that this is my problem. here is my code:
Code:
public class XPm implements IXposedHookZygoteInit {
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
String methodName = "installFailureToString";
XC_MethodHook hookMethod = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
int result = (Integer) param.args[0];
switch(result) {
case 1:
param.setResult("BLA");
break;
case 2:
param.setResult("BLA BLA");
break;
}
}
};
final Class<?> clsPMS = XposedHelpers.findClass("com.android.commands.pm.Pm", null);
XposedHelpers.findAndHookMethod(clsPMS, methodName,int.class, hookMethod);
}
}
shnapsi said:
Hi,
Strange since i do see in #10 an example (not full code...) of how i tried to do it.
Click to expand...
Click to collapse
Not the initZygote/handleLoadPackage part, though, so I couldn't know which you're using.
shnapsi said:
anyway, I dont think that this is my problem. here is my code:
Click to expand...
Click to collapse
That looks correct to me. What's the error you're getting?
GermainZ said:
Not the initZygote/handleLoadPackage part, though, so I couldn't know which you're using.
That looks correct to me. What's the error you're getting?
Click to expand...
Click to collapse
The same exception as i posted in #8
I think this might be your problem (see post #2): http://forum.xda-developers.com/xposed/xposed-api-changelog-developer-news-t2714067
GermainZ said:
I think this might be your problem (see post #2): http://forum.xda-developers.com/xposed/xposed-api-changelog-developer-news-t2714067
Click to expand...
Click to collapse
So, I'm not sure I understand, can i hook it or not?
I didn't find IXposedHookCmdInit under XposedHelpers...
Thanks!
shnapsi said:
So, Im not sure I understand, can i hook it or not?
I didnt find IXposedHookCmdInit under XposedHelpers...
Thanks!
Click to expand...
Click to collapse
Also check post #4 in the same thread.
Basically, you could do it, but you probably don't want to since it's deprecated and disabled by default. I guess you'll want to look into hooking PackageManager instead.
GermainZ said:
Also check post #4 in the same thread.
Basically, you could do it, but you probably don't want to since it's deprecated and disabled by default. I guess you'll want to look into hooking PackageManager instead.
Click to expand...
Click to collapse
I agree, so if this the method I wanted to hook (under PM):
Code:
private String installFailureToString(int result) {
Field[] fields = PackageManager.class.getFields();
for (Field f: fields) {
if (f.getType() == int.class) {
int modifiers = f.getModifiers();
// only look at public final static fields.
if (((modifiers & Modifier.FINAL) != 0) &&
((modifiers & Modifier.PUBLIC) != 0) &&
((modifiers & Modifier.STATIC) != 0)) {
String fieldName = f.getName();
if (fieldName.startsWith("INSTALL_FAILED_") ||
fieldName.startsWith("INSTALL_PARSE_FAILED_")) {
// get the int value and compare it to result.
try {
if (result == f.getInt(null)) {
return fieldName;
}
} catch (IllegalAccessException e) {
// this shouldn't happen since we only look for public static fields.
}
}
}
}
}
// couldn't find a matching constant? return the value
return Integer.toString(result);
}
I now need to hook this part:
Code:
Field[] fields = PackageManager.class.getFields();
which as i understand means to add more fields under PackageManager. is this the right way to do it? (since it didn't work for me)
Code:
final Class<?> clsPMS = XposedHelpers.findClass("android.content.pm.PackageManager", XPm.class.getClassLoader());
XposedHelpers.setAdditionalStaticField(clsPMS, "MY_KEY", 1000);
Thanks!

[Q] Please help, my Xposed module doesn't work in CM12

I wrote an Xposed module to modify the visibility of the navigation bar.
Code snippet:
Code:
public class disableHideNavigationBar implements IXposedHookZygoteInit {
public void initZygote(StartupParam startupParam) throws Throwable {
findAndHookMethod("com.android.server.wm.WindowState", null, "getSystemUiVisibility",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
The full code can be found here: https://github.com/aidfarh/DontHideNavbar/blob/master/app/src/main/java/com/aidfarh/DisableHideNavigationBar/disableHideNavigationBar.java
The module works perfectly in Android 4.4. However, it fails in CM12 (Android 5.0). The error log contains this:
Code:
03-21 06:48:46.710 I/Xposed (11748): Loading modules from /data/app/com.aidfarh.DisableHideNavigationBar-1/base.apk
03-21 06:48:46.864 I/Xposed (11748): Loading class com.aidfarh.DisableHideNavigationBar.disableHideNavigationBar
03-21 06:48:46.871 E/Xposed (11748): de.robv.android.xposed.XposedHelpers$ClassNotFoundError: java.lang.ClassNotFoundException: com.android.server.wm.WindowState
The full error log is attached.
The thing is, the class "com.android.server.wm.WindowState" does exists in CM12, as seen here: https://github.com/CyanogenMod/android_frameworks_base/blob/cm-12.0/services/core/java/com/android/server/wm/WindowState.java, but Xposed is reporting ClassNotFound. Can somebody please help?
BTW, my module contains another part that uses handleLoadPackage to hook into "com.android.systemui" and that part works perfectly. Only the part under initZygote doesn't work.
Never mind, I figured out how to make it work. Turns out that instead of initZygote, I had to use handleLoadPackage with package name "android". Good thing is, it works with both android 5.0 and 4.4 .

Dagger2 And Xposed

So I'm trying to hook my specific application's class onCreate method, because that's when I initialize my DaggerComponent.
My application looks like this:
Code:
private ApplicationComponent component;
@Override
public void onCreate() {
super.onCreate();
component = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this))
.build();
}
public ApplicationComponent getComponent() {
return component;
}
And in my Xposed loadPackage method, I'm trying to hook the component so I can inject it into the module like so:
Code:
String name = lpparam.packageName;
if (name.equals(Common.PACKAGE_NAME)) {
XposedHelpers.findAndHookMethod(Application.class, "attach", Context.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
findAndHookMethod(
XposedHelpers.findClass(Common.APPLICATION, lpparam.classLoader),
"onCreate",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Application application = (Application) param.thisObject;
Class clazz = param.method.getDeclaringClass();
for (Field field: clazz.getDeclaredFields()) {
String typeName = field.getType().getName();
if (typeName.equals(ApplicationComponent.class.getName())) {
Object object = XposedHelpers.getObjectField(param.thisObject, field.getName());
Class<?> component = object.getClass();
Method injector = component.getDeclaredMethod(
ApplicationComponent.INJECTOR, Loader.class);
injector.invoke(Loader.this);
Logg.log("GOT PAST THE BULL");
}
}
}
});
}
});
}
However, this always leads to a ClassNotFoundException where my Loader (the xposed module) is not found on my apk.
Code:
03-29 15:13:05.186 8571-8571/software.umlgenerator I/Xposed: java.lang.NoClassDefFoundError: software/umlgenerator/xposed/loaders/Loader
at java.lang.Class.getDeclaredConstructorOrMethod(Native Method)
at java.lang.Class.getConstructorOrMethod(Class.java:468)
at java.lang.Class.getDeclaredMethod(Class.java:640)
at software.umlgenerator.xposed.loaders.Loader$1$1.afterHookedMethod(Loader.java:67)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:645)
at software.umlgenerator.UMLApplication.onCreate(Native Method)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
at android.app.ActivityThread.handleBindApplication(Native Method)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "software.umlgenerator.xposed.loaders.Loader" on path: DexPathList[[zip file "/data/app/software.umlgenerator-1.apk"],nativeLibraryDirectories=[/data/app-lib/software.umlgenerator-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at java.lang.Class.getDeclaredConstructorOrMethod(Native Method)*
at java.lang.Class.getConstructorOrMethod(Class.java:468)*
at java.lang.Class.getDeclaredMethod(Class.java:640)*
at software.umlgenerator.xposed.loaders.Loader$1$1.afterHookedMethod(Loader.java:67)*
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:645)*
at software.umlgenerator.UMLApplication.onCreate(Native Method)*
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)*
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)*
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)*
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)*
at android.app.ActivityThread.handleBindApplication(Native Method)*
at android.app.ActivityThread.access$1500(ActivityThread.java:135)*
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)*
at android.os.Handler.dispatchMessage(Handler.java:102)*
at android.os.Looper.loop(Looper.java:136)*
at android.app.ActivityThread.main(ActivityThread.java:5001)*
at java.lang.reflect.Method.invokeNative(Native Method)*
at java.lang.reflect.Method.invoke(Method.java:515)*
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)*
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)*
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)*
at dalvik.system.NativeStart.main(Native Method)*
Any ideas?

Help with developement Xposed modules

Hi, I'm new development Xposed modules i have one problem in the hook process. My goal is to log the device imei by XposedBridge i tried by different forms but i can't have success . I all ready can change the imei but i can't do the correct log of the imei or put the value the correct value in a string anyone can help me? Thanksss Best regards... my code is this:
public class TelephoneManager implements IXposedHookLoadPackage {
@override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
// TODO Auto-generated method stub
if(lpparam.packageName.equals("fca.up.identityspoofing")){
XposedHelpers.findAndHookMethod(TelephonyManager.class, "getDeviceId", new XC_MethodReplacement() {
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("in....");
String id_device = (String) param.thisObject.toString();
//TextView id = (TextView) param.thisObject;
//String device_id = id.getText().toString();
XposedBridge.log(id_device);
return "0000000";
}
});
Well you don't even need xposed to get imei, you can simply just do
Code:
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
If you still want to go with the xposed module way, the correct code would be
Code:
@override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if(lpparam.packageName.equals("fca.up.identityspoo fing")){
XposedHelpers.findAndHookMethod(TelephonyManager.class, lpparam.classLoader, "getDeviceId", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String deviceId = (String) param.thisObject;
}
});
You hook after the original method has called so you can get the return value. You can still manipulate the result at this point if you want to do that.
Thanks for yoour help!
I tried that but does not result. In ;
if(lpparam.packageName.equals("fca.up.identityspoofing")){
XposedHelpers.findAndHookMethod(TelephonyManager.class, lpparam.classLoader, "getDeviceId", new XC_MethodHook() {
TelephonyManager.class needs to be a String. I tried "TelephonyManager.class" but Xposed can't find the class.
Then i tried with all all path to getDeviceId and not working too :
Code:
[user=439709]@override[/user]
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if(lpparam.packageName.equals("fc.up.identityspoofing")){
XposedHelpers.findAndHookMethod("com.android.internal.telephony.PhoneSubInfo", lpparam.classLoader, "getDeviceId", new XC_MethodHook(){
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String deviceId = (String) param.thisObject;
XposedBridge.log(deviceId);
}
});
}
The logcat error's are :
W/System.err( 4247): at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
W/System.err( 4247): at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
W/System.err( 4247): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
W/System.err( 4247): at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
W/System.err( 4247): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
Do you have an idea of what may be happening? Best Regards
[QUOTE="sokie, post: 66189459, member: 2502626"]Well you don't even need xposed to get imei, you can simply just do
[CODE]
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
If you still want to go with the xposed module way, the correct code would be
Code:
[user=439709]@override[/user]
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if(lpparam.packageName.equals("fca.up.identityspoofing")){
XposedHelpers.findAndHookMethod(TelephonyManager.class, lpparam.classLoader, "getDeviceId", new XC_MethodHook() {
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String deviceId = (String) param.thisObject;
}
});
You hook after the original method has called so you can get the return value. You can still manipulate the result at this point if you want to do that.[/QUOTE]
jmarques00 said:
Do you have an idea of what may be happening? Best Regards
Click to expand...
Click to collapse
Yeah, sorry wrote this quickly.
Code:
@override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if(lpparam.packageName.equals("android.telephony")){
XposedHelpers.findAndHookMethod("android.telephony.TelephonyManager", lpparam.classLoader, "getDeviceId", new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
String deviceId = (String) param.getResult();
}
});
This will work.
Also I take for granted you know your device and Android ver and know this method gets called.
Because depending on your android version there are other classes that take care of imei like:
- com.android.internal.telephony.PhoneSubInfo getDeviceId
- com.android.internal.telephony.gsm.GSMPhone getDeviceId
- com.android.internal.telephony.PhoneProxy getDeviceId
- android.telephony.TelephonyManager getImei
Cheers
Thanks for yoour help!
Thanks for your feedback i allready test the new code but unfortunately don't work too ! If the new code works all packages that require the emei this emei changed right? For that we don't need to implement IXposedHookZygoteInit instead IXposedHookLoadPackage? The code break in the frist if condition when lpparam.packageName.equals("android.telephony") :/ .
package fc.up.identityspoofing;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
public class TelephoneManager implements IXposedHookLoadPackage {
private static final String TAG = "Xposed";
@override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("aaaaa");
if(lpparam.packageName.equals("android.telephony")){
XposedBridge.log("bbbbb");
//XposedHelpers.findAndHookMethod("com.android.internal.telephony.PhoneSubInfo", lpparam.classLoader, "getDeviceId", new XC_MethodHook() {
XposedHelpers.findAndHookMethod("android.telephony.TelephonyManager", lpparam.classLoader, "getDeviceId", new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("cccc");
super.afterHookedMethod(param);
String deviceId = (String) param.getResult();
XposedBridge.log(deviceId);
}
});
}
}
}
What doesn't work? How are you testing?
As said earlier, depending on your android version, the above code if you go to Settings ->About Phone -> Status -> IMEI Information you will hit the log ( if not and you're in europe you could try com.android.internal.telephony.gsm.GSMPhone ).
Also keep in mind that changing IMEI will probably work only for apps requesting it and the OS, network carriers get that info directly from the sim afaik.
EDIT: this is an example complete app that should work http://pastebin.com/uPjY47VR
I'm testing in in 2 modes my phone version 4.2.2 and with genymotion with 4.2.2 version too. My frist goal is to this package when wants to receive the device_id the device_id revived must be fake and i want to log the original one. Thanks for your help
sokie said:
What doesn't work? How are you testing?
As said earlier, depending on your android version, the above code if you go to Settings ->About Phone -> Status -> IMEI Information you will hit the log ( if not and you're in europe you could try com.android.internal.telephony.gsm.GSMPhone ).
Also keep in mind that changing IMEI will probably work only for apps requesting it and the OS, network carriers get that info directly from the sim afaik.
Click to expand...
Click to collapse
jmarques00 said:
I'm testing in in 2 modes my phone version 4.2.2 and with genymotion with 4.2.2 version too. My frist goal is to this package when wants to receive the device_id the device_id revived must be fake and i want to log the original one. Thanks for your help
Click to expand...
Click to collapse
Read my last edit:
EDIT: this is an example complete app that should work http://pastebin.com/uPjY47VR
Thanks for all sokie it really works fine in my mobile phone !!!
sokie said:
Read my last edit:
EDIT: this is an example complete app that should work http://pastebin.com/uPjY47VR
Click to expand...
Click to collapse

[Q] can i use setResult and callMethod inside afterHookedMethod?

hi i am new to xposed framework and java as well. :laugh:
my objective:
1. hook a class method - DONE
2. modify its first param using beforehooked - DONE
3. log the output and call the same method again in afterhooked. NEED HELP
i am tried like this
PHP:
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("result " + param.setResult);
param.setResult(null);
XposedBridge.log("calling method ");
XposedHelpers.callMethod(param.thisObject, "BodyDataByStr",param.args[0],param.args[1],param.args[2],param.args[3]);
}
but this is throwing null pointer exception in logs.
PHP:
java.lang.NullPointerException
at de.robv.android.xposed.XposedHelpers.callMethod(XposedHelpers.java:947)
at just.trust.me.Main$1.afterHookedMethod(Main.java:70)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:645)
at com.nob.mypp.h.a.BodyDataByStr(Native Method)
at com.nob.myapp.h.a.getBody(Unknown Source)
at com.nob.myapp.h.a.<init>(Unknown Source)
at com.nob.myapp.k.bk.<init>(Unknown Source)
at com.nob.myapp.k.bk.a(Unknown Source)
at com.mob.mypp.n.b$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
please help me.
hotwap said:
hi i am new to xposed framework and java as well. :laugh:
my objective:
1. hook a class method - DONE
2. modify its first param using beforehooked - DONE
3. log the output and call the same method again in afterhooked. NEED HELP
i am tried like this
PHP:
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("result " + param.setResult);
param.setResult(null);
XposedBridge.log("calling method ");
XposedHelpers.callMethod(param.thisObject, "BodyDataByStr",param.args[0],param.args[1],param.args[2],param.args[3]);
}
but this is throwing null pointer exception in logs.
PHP:
java.lang.NullPointerException
at de.robv.android.xposed.XposedHelpers.callMethod(XposedHelpers.java:947)
at just.trust.me.Main$1.afterHookedMethod(Main.java:70)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:645)
at com.nob.mypp.h.a.BodyDataByStr(Native Method)
at com.nob.myapp.h.a.getBody(Unknown Source)
at com.nob.myapp.h.a.<init>(Unknown Source)
at com.nob.myapp.k.bk.<init>(Unknown Source)
at com.nob.myapp.k.bk.a(Unknown Source)
at com.mob.mypp.n.b$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
please help me.
Click to expand...
Click to collapse
Code:
XposedBridge.log("result " + param.[COLOR="Red"]setResult[/COLOR]);
It should be getResult() right?
Also, you can use XC_MethodReplacement() instead of XC_MethodHook(), something like this:
PHP:
XposedHelpers.findAndHookMethod(........ new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
if (mBlaBlaBla == true) {
mBlaBlaBla = false;
XposedBridge.log("log this");
} else {
mBlaBlaBla = true;
// invoke original method
XposedBridge.invokeOriginalMethod(param.method, param.thisObject, param.args);
}
return null;
}
});
serajr said:
Code:
XposedBridge.log("result " + param.[COLOR="Red"]setResult[/COLOR]);
It should be getResult() right?
yes you are right. in the source its already getResult(), i made mistake while creating the thread.
Click to expand...
Click to collapse
Also note, calling the same method using callMethod inside its hook will basically run your hook recursively until stack overflows.
If you need to call the original method you should use XposedBridge.invokeOriginalMethod()
This will bypass any hooks attached to this method.

Categories

Resources