[Xposed Framework Development] HpNoTiQ:
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 :

# 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 :

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);
}
}
}