Hi,
I was trying to hook a method of the Google Keyboard. The method is in the com.android.inputmethod.keyboard.Key.java class, and it's definied as
Code:
public final Drawable selectBackgroundDrawable(final Drawable keyBackground, final Drawable functionalKeyBackground, final Drawable spacebarBackground)
I try to hook this method with this snippet of code:
Code:
@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if(!(lpparam.packageName.equals("com.android.inputmethod.latin") || lpparam.packageName.equals("com.android.inputmethod.keyboard")))
return;
findAndHookMethod("com.android.inputmethod.keyboard.Key", lpparam.classLoader,
"selectBackgroundDrawable", Drawable.class, Drawable.class, Drawable.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
XposedBridge.log("hooked");
}
});
}
But when I run my emulator (genymotion: Custom Phone with android 4.4.4) I get the error "NoSuchMethodError".
How can I solve this?
Are you trying to target the Google Keyboard that you can download from the Play store? I'm showing it having a different package name:
package:/data/app/com.google.android.inputmethod.latin-1/base.apk=com.google.android.inputmethod.latin
The keyboard in my emulator may have the package name "com.android.inputmethod.latin" (I re.ember that I checked it yesterday, but I don't believe in my memory ). I will try the module with both keyboards.
Thanks for the answer
Argh, the package name was com.android.inputmethod.latin as expected...
I decompiled the latinIME.apk file that I found in my emulator...and then I discovered that there isn't a method called "selectBackgroundDrawable" in the class Key.... I don't know what is the android version of the keyboard that I downloaded before. Thanks for your answers
Related
I want to hook the constructor with xposed , and the code is as follows ,but there is some wrong.
Code:
XposedHelpers.findAndHookConstructor("java.io.File",
lpparam.classLoader, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
}
@Override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {
System.out.println("file interception" + "-------------->"
+ param.args[0]);
}
});
Error content:
java.lang.NoSuchMethodError: java.io.File()#exact
Thanks
That's because there is no File() constructor. To hook e.g. File(String filename), you need to use:
Code:
XposedHelpers.findAndHookConstructor("java.io.File",
lpparam.classLoader, [COLOR="Red"][B]String.class, [/B][/COLOR]new XC_MethodHook() {
or simply
Code:
XposedHelpers.findAndHookConstructor(File.class, [COLOR="Red"][B]String.class, [/B][/COLOR]new XC_MethodHook() {
Be careful with such generic classes though, you can easily get lots of calls to it.
rovo89 said:
That's because there is no File() constructor. To hook e.g. File(String filename), you need to use:
Code:
XposedHelpers.findAndHookConstructor("java.io.File",
lpparam.classLoader, [COLOR="Red"][B]String.class, [/B][/COLOR]new XC_MethodHook() {
or simply
Code:
XposedHelpers.findAndHookConstructor(File.class, [COLOR="Red"][B]String.class, [/B][/COLOR]new XC_MethodHook() {
Be careful with such generic classes though, you can easily get lots of calls to it.
Click to expand...
Click to collapse
It works, thanks you very much .
I'am trying to create an Xposed module which hooks into the tranceive methods of nfc to find out what is transfered. But sadly the hook doesn't seam to work. I've created a sample app which sends data over the tranceive method but the logs are not written. Here is my code:
Code:
if (!lpparam.packageName.equals("android"))
return;
findAndHookMethod("android.nfc.tech.BasicTagTechnology", lpparam.classLoader, "transceive", "byte[]", "boolean", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("before");
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("after");
}
});
I've also tried to hook into the service, but no logs either:
Code:
if (!lpparam.packageName.equals("com.android.nfc"))
return;
findAndHookMethod("com.android.nfc.NfcService", lpparam.classLoader, "doTransceiveNoLock", "int", "byte[]", new XC_MethodHook() {
.....
Am I doing something wrong or is it simply not possible to hook into these methods?
I found a solution for my problem. I have to hook the transceive method of com.android.nfc.NfcService$TagService to get access to every tag transmission.
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
I'm having some difficulty on hooking a lib created by me (.jar)
Apparently Xposed can't see the lib's package.
I'm using this code to see the packages hooked by the xposed and to hook my class:
Code:
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
Log.v("LogModule", lpparam.packageName);
findAndHookMethod("com.example.ClassTest", lpparam.classLoader, "lock", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable{
Log.v("LogModule", "Hooked");
Log.v("LogModule", param.thisObject.toString());
}
});
is there any issue in hooking an .jar class?
Thks
I'm guessing libraries are loaded as part of other apps and thus their package isn't shown in lpparam.packageName
you can create a dummy app, without any libraries except your own (create a ClassTest object), and in xposed print all its methods (full path). look for ClassTest
I'm not able to change the return values of a method. The hook is working. Even the logs are correct - but when i actually call the method in another app the real information is shown.
Code:
findAndHookMethod("android.net.wifi.WifiInfo", lpparam.classLoader, "getSSID",new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("getSSID1 "+(String) param.getResult());
param.setResult("\"Changed\"");
XposedBridge.log("getSSID2 "+(String) param.getResult());
}
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
});
Output:
Code:
getSSID1 "realSSID"
getSSID2 "Changed"
In app the call actually produces: "realSSID"
Can you help me with that?
what about when you setResult in beforeHookedMethod instead (thus the getSSID won't be called)?
have you ensured that the app calls getSSID to receive this information, and not from cache or something?
I tried beforeHookedMethod and MethodReplacement - same result. And getSSID is called because i can see the XposedBridge logs.
is it an app you wrote? i see from this answer that it can also be retrieved from getBSSID, and it could be the app was checking the string returned by getSSID or was using it for something else
Yes i use an own app for checking if it works. So i'm 100% sure i'm calling getSSID() - the method i've hooked.
the following works for me:
in module:
Code:
if (lpparam.packageName.equals("gitfib.hooks.sdaccounts")) {
XposedHelpers.findAndHookMethod("android.net.wifi.WifiInfo", lpparam.classLoader,
"getSSID",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult("ssid");
}
});
}
in activity (same package in onCreate):
Code:
WifiInfo info = ((WifiManager) getSystemService(WIFI_SERVICE)).getConnectionInfo();
Log.i("wifiinfo", info.getSSID());
before rebooting it showed actual ssid