Search code examples
javaandroidconstructorinner-classesxposed

Xposed Hook Constructor in Nested Class


I am trying to hook the constructor of a nested class using Xposed, but I'm getting a ClassNotFoundException for the nested class (SettingsAdapter). However, there is another method in the nested class that it has no trouble hooking. Is there anything wrong I'm doing with the constructor call?

This is the constructor call:

findAndHookConstructor("com.angrydoughnuts.android.alarmclock.ActivityAlarmSettings$SettingsAdapter", lpparam.classLoader, "SettingsAdapter", "android.content.Context", "java.util.List", new XC_MethodHook() {

And this is the other working method call:

findAndHookMethod("com.angrydoughnuts.android.alarmclock.ActivityAlarmSettings$SettingsAdapter", lpparam.classLoader, "getView", "int", "android.view.View", "android.view.ViewGroup", new XC_MethodHook() {

Thanks in advance!


Solution

  • Inner classes have an implicit parameter, which holds the super instance. In your case that would be a reference to ActivityAlarmSettings.

    You can either try

    findAndHookConstructor("com.angrydoughnuts.android.alarmclock.ActivityAlarmSettings$SettingsAdapter", lpparam.classLoader, "com.angrydoughnuts.android.alarmclock.ActivityAlarmSettings", "android.content.Context", "java.util.List", new XC_MethodHook() {
    

    or just use hookAllConstructors

    By the way: your call to findAndHookConstructor seems to include the name of the constructor. This is not an expected parameter! Constructor names are always the class name, and xposed doesn't expect you to pass it.