[HELP] Xposed Module : load & hook native libraries - Xposed Framework Development

Hi,
After modding APKs and that XPOSED is now back for a long time I guess with EdXposed, I'm trying to make my first XPOSED modules by following tutorials.
I've setup android studio, wrote my code but now I can't load native library. I guess it's a permission problem but coudn't figure how to solve it.
Here is my code :
Code:
package com.hpnotiq.myapp;
import android.content.res.XModuleResources;
import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
import de.robv.android.xposed.XposedBridge;
public class Main implements IXposedHookInitPackageResources {
@Override
public void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable {
// replacements only for Waze
if (!resparam.packageName.equals("com.waze"))
return;
// different ways to specify the resources to be replaced
System.load("/data/data/com.waze/lib/libwaze.so");
XposedBridge.log("Loaded native hook");
resparam.res.setReplacement("com.waze", "integer", "Variabletomodify", 1);
}
}
I've got error java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/data/com.waze/lib/libwaze.so" not found when using logcat on my device.

I'm back with some news.
I managed to get it working but now I'm blocked hooking a constructor (I Think).
My problem :
I can hook both method isEnforcementPoliceEnabledNTV/isEnforcementAlertsEnabledNTV but they are not hooked when they are call with invoke function.
Here is the constructor I'm trying to hook :
Code:
# direct methods
.method public constructor <init>(Landroid/content/Context;Z)V
.locals 1
.line 28
invoke-direct {p0}, Landroid/widget/BaseAdapter;-><init>()V
const-string v0, "layout_inflater"
.line 29
invoke-virtual {p1, v0}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;
move-result-object p1
check-cast p1, Landroid/view/LayoutInflater;
iput-object p1, p0, Lcom/waze/main/navigate/c;->d:Landroid/view/LayoutInflater;
.line 30
iput-boolean p2, p0, Lcom/waze/main/navigate/c;->e:Z
.line 31
invoke-static {}, Lcom/waze/NativeManager;->getInstance()Lcom/waze/NativeManager;
move-result-object p1
iput-object p1, p0, Lcom/waze/main/navigate/c;->f:Lcom/waze/NativeManager;
.line 32
iget-object p1, p0, Lcom/waze/main/navigate/c;->f:Lcom/waze/NativeManager;
invoke-virtual {p1}, Lcom/waze/NativeManager;->isEnforcementPoliceEnabledNTV()I
move-result p1
.line 33
iget-object p1, p0, Lcom/waze/main/navigate/c;->f:Lcom/waze/NativeManager;
invoke-virtual {p1}, Lcom/waze/NativeManager;->isEnforcementAlertsEnabledNTV()Z
return-void
.end method
Here is my xposed module code :
Code:
package com.hpnotiq.waze_enhancer;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import java.util.Calendar;
import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import de.robv.android.xposed.XSharedPreferences;
public class Main implements IXposedHookLoadPackage {
// This current package.
private static final String PACKAGE_NAME = "com.hpnotiq.Waze_enhancer";
/**
* Constants useful for debugging mode.
*/
// Whether debugging mode is on or off - configurable via Settings.
private boolean debugMode = true;
private static final String WAZE_ENFORCEMENT_METHOD = "isEnforcementAlertsEnabledNTV";
private static final String WAZE_ENFORCEMENT_METHOD2 = "isEnforcementPoliceEnabledNTV";
// The class that contains the above internal Waze methods.
private static final String WAZE_PACKAGE = "com.waze";
private static final String WAZE_NATIVEMANAGER_CLASS_NAME = WAZE_PACKAGE+".NativeManager";
private static final String WAZE_NATIVEMANAGER_CLASS_NAME2 = WAZE_PACKAGE+".main.navigate.c";
@Override
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
loadPreferences();
// This method is called once per package, so we only want to apply hooks to Waze.
if (WAZE_PACKAGE.equals(lpparam.packageName)) {
XposedBridge.log("We are in Waze");
System.load("/data/data/" + WAZE_PACKAGE + "/lib/libsqlite.so");
System.load("/data/data/" + WAZE_PACKAGE + "/lib/libwaze.so");
XposedBridge.log("Loaded native hook");
//this.hookWazeEnforcement(lpparam.classLoader);
XposedHelpers.findAndHookMethod(WAZE_NATIVEMANAGER_CLASS_NAME, lpparam.classLoader, WAZE_ENFORCEMENT_METHOD, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Alerts before "+(String) param.getResult());
}
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
//param.setResult("false");
XposedBridge.log("Alerts after "+(String) param.getResult());
}
});
XposedHelpers.findAndHookMethod(WAZE_NATIVEMANAGER_CLASS_NAME, lpparam.classLoader, WAZE_ENFORCEMENT_METHOD2, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Police before "+(String) param.getResult());
}
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
//param.setResult("false");
XposedBridge.log("Police after "+(String) param.getResult());
}
});
XposedHelpers.findAndHookConstructor(WAZE_NATIVEMANAGER_CLASS_NAME2, lpparam.classLoader, WAZE_ENFORCEMENT_METHOD, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Alerts Cons before "+(String) param.getResult());
}
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
//param.setResult("false");
XposedBridge.log("Alerts Cons after "+(String) param.getResult());
}
});
}
}
/**
*
* @param classLoader ClassLoader for the com.waze package.
*/
private void hookWazeEnforcement(final ClassLoader classLoader) {
XposedHelpers.findAndHookMethod(WAZE_NATIVEMANAGER_CLASS_NAME, classLoader, WAZE_ENFORCEMENT_METHOD, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Police "+(String) param.getResult());
}
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult("false");
}
});
XposedHelpers.findAndHookMethod(WAZE_NATIVEMANAGER_CLASS_NAME, classLoader, WAZE_ENFORCEMENT_METHOD2, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Police "+(String) param.getResult());
}
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult("false");
}
});
}
/**
* Load the preferences from our shared preference file.
*/
private void loadPreferences() {
XSharedPreferences prefApps = new XSharedPreferences(PACKAGE_NAME);
prefApps.makeWorldReadable();
this.debugMode = prefApps.getBoolean("waze_radar_debug", false);
}
/**
* Capture debugging messages.
*
* @param message
*/
private void debug(String message) {
if (this.debugMode) {
String currentDateTime = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
XposedBridge.log(currentDateTime + ": " + message);
}
}
}

Related

[SOLVED] java.lang.NoSuchMethodError where such a method exists

Hello, I get the following exception in logcat
Code:
E/Xposed (10014): java.lang.NoSuchMethodError: com.android.keyguard.KeyguardSecurityContainer#updateSecurityView(android.view.View,java.lang.Boolean)#exact
and my code is
Code:
public class XposedMod implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && (lpparam.packageName.contains("android.keyguard") || lpparam.packageName.contains("com.android.systemui")))
{
Class<?> KeyguardHostView = XposedHelpers.findClass("com.android.keyguard.KeyguardSecurityContainer", lpparam.classLoader);
findAndHookMethod(KeyguardHostView, "updateSecurityView", View.class, Boolean.class, mUpdateSecurityViewHook);
}
}
The method exists here https://github.com/android/platform.../keyguard/KeyguardSecurityContainer.java#L139
What should I do? Thanks for your help!
Code:
findAndHookMethod(KeyguardHostView, "updateSecurityView", View.class, boolean.class, mUpdateSecurityViewHook);
The primitive boolean was to be used instead of the boxed Boolean
Rijul.A said:
Hello, I get the following exception in logcat
Code:
E/Xposed (10014): java.lang.NoSuchMethodError: com.android.keyguard.KeyguardSecurityContainer#updateSecurityView(android.view.View,java.lang.Boolean)#exact
and my code is
Code:
public class XposedMod implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && (lpparam.packageName.contains("android.keyguard") || lpparam.packageName.contains("com.android.systemui")))
{
Class<?> KeyguardHostView = XposedHelpers.findClass("com.android.keyguard.KeyguardSecurityContainer", lpparam.classLoader);
findAndHookMethod(KeyguardHostView, "updateSecurityView", View.class, Boolean.class, mUpdateSecurityViewHook);
}
}
The method exists here https://github.com/android/platform.../keyguard/KeyguardSecurityContainer.java#L139
What should I do? Thanks for your help!
Click to expand...
Click to collapse
Make class and paste this content
PHP:
import java.lang.reflect.Method;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
public class XposedWrapper {
public static XC_MethodHook.Unhook hookMethod(Class<?> sClass,String method_Name,Object... parameterTypesAndCallback) {
Method method = XposedHelpers.findMethodBestMatch(sClass,method_Name,removeCallback(parameterTypesAndCallback));
XC_MethodHook callback = (XC_MethodHook) parameterTypesAndCallback[parameterTypesAndCallback.length-1];
return XposedBridge.hookMethod(method,callback);
}
private static Object[] removeCallback(Object... args) {
Object[] list = new Object[args.length-1];
for (int i = 0 ; i < args.length ; i++) {
if (!(args[i] instanceof XC_MethodHook)) {
list[i] = args[i];
}
}
return list;
}
}
Now in the xposed class
do like this
PHP:
XposedWrapper.hookMethod(KeyguardHostView, "updateSecurityView", View.class, Boolean.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Hooked");
}
});

FindViewById from hooked method?

Hello!
I'm trying to make Xposed module from this patch: https://github.com/CyanogenMod/android_frameworks_base/commit/19e458f4a26fe7c8b6419cadba81a0c46dc79dad
My code looks like this:
Code:
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
MODULE_PATH = startupParam.modulePath;
}
@Override
public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable {
if (!resparam.packageName.equals(PACKAGE_NAME))
return;
XModuleResources modRes = XModuleResources.createInstance(MODULE_PATH, resparam.res);
mFakeIdScrimview = resparam.res.addResource(modRes, R.id.scrimview);
mFakeIdVisView = resparam.res.addResource(modRes, R.id.visualizerview);
}
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(PACKAGE_NAME))
return;
findAndHookMethod("com.android.systemui.statusbar.phone.PhoneStatusBar", lpparam.classLoader,
"makeStatusBarView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
FrameLayout lStatusBarWindow = (FrameLayout) XposedHelpers.getObjectField(param.thisObject, "mStatusBarWindow");
FrameLayout scrimView = (FrameLayout) lStatusBarWindow.findViewById(mFakeIdScrimview);
if (scrimView != null) {
mVisualizerView = (VisualizerView) scrimView.findViewById(mFakeIdVisView);
} else {
XposedBridge.log("scrimView = null !!!!");
}
if (mVisualizerView != null){
mVisualizerView.setKeyguardMonitor(mKeyguardMonitor);
} else {
XposedBridge.log("mVisualizerView = null !!!!! ");
}
}
});
The problem is that scrimView is always null and I can't get this piece of code working.
Anybody has any idea?
Untested, but could you try to replace your scrimView assignment line with this
Code:
FrameLayout scrimView = (FrameLayout) XposedHelpers.callMethod(lStatusBarWindow, "findViewById", mFakeIdScrimview);
Rijul.A said:
Untested, but could you try to replace your scrimView assignment line with this
Code:
FrameLayout scrimView = (FrameLayout) XposedHelpers.callMethod(lStatusBarWindow, "findViewById", mFakeIdScrimview);
Click to expand...
Click to collapse
Unfortunately scrimView is still null.

[Need Help] [Hooking init method]

Hi, I have StatusBarIconView.smali (com/android/systemui/statusbar) and I want to hook this method:
Code:
.method public constructor <init>(Landroid/content/Context;Ljava/lang/String;Landroid/app/Notification;)V
.locals 5
.param p1, "context" # Landroid/content/Context;
.param p2, "slot" # Ljava/lang/String;
.param p3, "notification" # Landroid/app/Notification;
...........................Here we have some code.......................
.line 84
.local v0, "iconPadding":I
invoke-virtual {p0, v0, v4, v0, v4}, Lcom/android/systemui/statusbar/StatusBarIconView;->setPadding(IIII)V
.line 85
return-void
.end method
I want to hook this method in order to change padding.
Using BatchApktool I can see java code:
PHP:
public StatusBarIconView(Context context, String slot, Notification notification) {
super(context);
Resources res = context.getResources();
this.mSlot = slot;
this.mNumberPain = new Paint();
this.mNumberPain.setTextAlign(Align.CENTER);
this.mNumberPain.setColor(res.getColor(R.drawable.notification_number_text_color));
this.mNumberPain.setAntiAlias(true);
this.mNotification = notification;
setContentDescription(notification);
int iconPadding = getResources().getDimensionPixelSize(R.dimen.status_bar_icon_padding);
setPadding(iconPadding, 0, iconPadding, 0);
}
I can change padding manually with .smali editing. But I want to change it with xposed module.
And I don't know how to hook this <init> method properly. Is it possible at all?
Here's what I tried:
PHP:
XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.StatusBarIconView", lpparam.classLoader, "init",Context.class,String.class, "android.app.Notification" ,new XC_MethodHook() {
@Override protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
View v = (View) param.thisObject;
v.setPadding(3, 15, 3, 15);
}
});
And I got noclassfound error (or nosuchmethod error ... forgot which one)
Also I replaced "init" with "<init>" or "StatusBarIconView" with no result as well.
<init> is basically a constructor.
Use XposedHelpers.findAndHookConstructor instead of findAndHookMethod.

Getting LongPress on Back/Volume Keys (Hooked, But Cant't Get LongPress)

Hello, I've hooked a method to get KeysEvent, but I've ran into 2 problems :
1. Can't get long press.
2. Getting up to 7 events when it's only 1 event, Explain ? I've added a log.i in "if(blabla == VOLUME_DOWN ), When i press that key i get the log 7 times.
Here's the code :
HTML:
public static void init() {
final Class localClass = XposedHelpers.findClass("com.android.internal.policy.impl.PhoneWindowManager", Xposed.CLASS_LOADER);
XposedBridge.hookAllConstructors(localClass, new XC_MethodHook() {
protected void afterHookedMethod(final XC_MethodHook.MethodHookParam paramAnonymousMethodHookParam)
throws Throwable {
}
});
XposedHelpers.findAndHookMethod(localClass, "interceptKeyBeforeQueueing", KeyEvent.class, Integer.TYPE, new XC_MethodHook() {
[user=439709]@override[/user]
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
KeyEvent event = (KeyEvent) param.args[0];
int code = event.getKeyCode();
if (code == KeyEvent.KEYCODE_BACK) {
Log.i(Xposed.TAG, "Back Pressed");
}
}
});

Hook long press notification

How can you guys capture long press notification?
I found this method on SystemUI:
Code:
Code:
protected SwipeHelper.LongPressListener getNotificatioLongnClicker() {
return new SwipeHelper.LongPressListener() {
[user=439709]@override[/user]
public boolean onLongPress(View v, int x, int y) {...
But I can't do afterHookedMethod or beforeHookedMethod.
Code:
Code:
public class Tutorial implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("Loaded app: " + lpparam.packageName);
if (!lpparam.packageName.equals("com.android.systemui"))
return;
findAndHookMethod("com.android.systemui.statusbar.BaseStatusBar", lpparam.classLoader, "getNotificationLongClicker", new XC_MethodHook() {
[user=439709]@override[/user]
protected void afterHookedMethod (MethodHookParam param) throws Throwable {
// this will be called before the clock was updated by the original method
return new View.OnLongClickListener() {
[user=439709]@override[/user]
public boolean onLongClick(final View v) {
XposedBridge.log("long press notification action");
return true;
}
}
});
}
}
}
How I can call the method from another class "SwipeHelper" and access "LongPressListener" public interface and "onLongPress" method which return boolean value?
I tried with object and method "View.OnLongClickListener" without success. Anyway, if I can't do it there is another way because I see system long press notification working on xNotification module.
PS.: I'm noobie: http://stackoverflow.com/questions/3...ing-xposed-mod
@pixeltech.dev
lukakas said:
How can you guys capture long press notification?
I found this method on SystemUI:
Code:
Code:
protected SwipeHelper.LongPressListener getNotificatioLongnClicker() {
return new SwipeHelper.LongPressListener() {
[user=439709]@override[/user]
public boolean onLongPress(View v, int x, int y) {...
But I can't do afterHookedMethod or beforeHookedMethod.
Code:
Code:
public class Tutorial implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("Loaded app: " + lpparam.packageName);
if (!lpparam.packageName.equals("com.android.systemui"))
return;
findAndHookMethod("com.android.systemui.statusbar.BaseStatusBar", lpparam.classLoader, "getNotificationLongClicker", new XC_MethodHook() {
[user=439709]@override[/user]
protected void afterHookedMethod (MethodHookParam param) throws Throwable {
// this will be called before the clock was updated by the original method
return new View.OnLongClickListener() {
[user=439709]@override[/user]
public boolean onLongClick(final View v) {
XposedBridge.log("long press notification action");
return true;
}
}
});
}
}
}
How I can call the method from another class "SwipeHelper" and access "LongPressListener" public interface and "onLongPress" method which return boolean value?
I tried with object and method "View.OnLongClickListener" without success. Anyway, if I can't do it there is another way because I see system long press notification working on xNotification module.
PS.: I'm noobie: http://stackoverflow.com/questions/3...ing-xposed-mod
@pixeltech.dev
Click to expand...
Click to collapse
Hi, View.OnLongClickListener is not a method, it's an interface. Basically what you need to do is get the method result in your hook (it would be either SwipeHelper or OnClickListener based on your Andorid version) and use it based on its methods and your needs
pixeltech.dev said:
Hi, View.OnLongClickListener is not a method, it's an interface. Basically what you need to do is get the method result in your hook (it would be either SwipeHelper or OnClickListener based on your Andorid version) and use it based on its methods and your needs
Click to expand...
Click to collapse
I tried to do this without success:
Code:
public class Tutorial implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("Loaded app: " + lpparam.packageName);
if (!lpparam.packageName.equals("com.android.systemui"))
return;
findAndHookMethod("com.android.systemui.statusbar.SwipeHelper$LongPressListener", lpparam.classLoader, "onLongPress",View.class, Integer.TYPE, Integer.TYPE, new XC_MethodHook() {
@Override
protected void afterHookedMethod (MethodHookParam param) throws Throwable {
// this will be called before the clock was updated by the original method
XposedBridge.log("long press notification action");
}
});
}
}
Logcat:
Code:
05-30 22:35:13.580 18201-18201/com.android.systemui E/Xposed: java.lang.IllegalArgumentException: Cannot hook interfaces: public abstract boolean com.android.systemui.SwipeHelper$LongPressListener.onLongPress(android.view.View,int,int)

Categories

Resources