1

I’m trying to hook a method which requires a specific parameter. For example: I have a class com.example.someclass, method name is getValue. Method requires a String. If I pass "Apple", it returns "fruit", if I pass "Mellon" it returns "berry" I want it to return "slices" when I pass "Mellon". I tried to do this with findandhookmethod, but I can’t specify a parameter there.

I tried to change it in beforeHookedMethod by changing param.args[0], but it returned an error.

The problem might also be in the two hooks conflicting with each other, because I have a hookallmethods as well. The hookall always changes argument which causes an error.

This is my code using beforeHookedMethod:

XposedHelpers.findAndHookMethod(Class.forName("android.os.SystemProperties"), "get", String.class, new XC_MethodHook() {

    @Override
    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
        param.args[0] = "ro.product.brand";
    }

    @Override
    protected void afterHookedMethod(MethodHookParam param) throws Throwable {}
});

And hookAllMethods: (this doesn't work because methodHookParam.args doesn't contain params I actually need, neither for get, nor for getInt or ´getBoolean`):

XposedBridge.hookAllMethods(Class.forName("android.os.SystemProperties"), "get", new XC_MethodReplacement() {


    @Override
    protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
        XposedBridge.log(methodHookParam.args.toString());
        String[] paramList = Arrays.copyOf(methodHookParam.args, methodHookParam.args.length, String[].class);
        String param = paramList[0];
        XposedBridge.log(paramList.toString());
        for (int i = 0; i < methodHookParam.args.length; i++) {
            try {
                XposedBridge.log("1:  " + paramList[i]);
                
            } catch (NullPointerException ex) {
                XposedBridge.log("Error: "+ ex);
            }
        }

        switch (param) {
            case "ro.build.id":
                return "JZO54K";
            case "ro.build.display.id":
                return "JZO54K.I739KEAMF1";
            case "ro.build.version.incremental":
                return "I739KEAMF1";
            case "ro.build.version.sdk":
                return 31;
            case "ro.build.version.codename":
                return "REL";
            case "ro.build.version.release":
                return "12";
            case "ro.build.type":
                return "user";
            case "ro.build.user":
                return "se.infra";
            case "ro.build.host":
                return "S0210-08";
            case "ro.build.tags":
                return "release-keys";
            case "ro.product.model":
                return "SCH-I739";
            case "ro.product.brand":
                return "samsung";
            case "ro.product.name":
                return "kyleplusctc";
            case "ro.product.device":
                return "kyleplusctc";
            case "ro.product.board":
                return "MSM8625";
            case "ro.product.cpu.abi":
                return "armeabi-v7a";
            case "ro.product.cpu.abi2":
                return "armeabi";
            case "ro.product_ship":
                return "true";
            case "ro.product.manufacturer":
                return "samsung";
            case "ro.product.locale.language":
                return "zh";
            case "ro.product.locale.region":
                return "CN";
            case "ro.board.platform":
                return "msm7627a";
            case "ro.build.product":
                return "kyleplusctc";
            case "ro.build.description":
                return "kyleplusctc-user 4.1.2 JZO54K I739KEAMF1 release-keys";
            case "ro.build.fingerprint":
                return "samsung/kyleplusctc/kyleplusctc:4.1.2/JZO54K/I739KEAMF1:user/release-keys";
            case "ro.build.characteristics":
                return "china_wlan,china_cdma";
            case "ro.build.PDA":
                return "I739KEAMF1";
            case "ro.build.hidden_ver":
                return "I739KEAMF1";
            case "ro.build.changelist":
                return 1283033;
            case "ro.opengles.version":
                return 131072;
            case "ro.use_data_netmgrd":
                return true;
            case "ro.bluetooth.request.master":
                return true;
            case "ro.qualcomm.bluetooth.ftp":
                return true;
            case "ro.qualcomm.bluetooth.sap":
                return true;
            case "ro.bluetooth.remote.autoconnect":
                return true;
            case "ro.config.ehrpd":
                return true;
            case "ro.qualcomm.cabl":
                return 1;
            case "ro.fm.analogpath.supported":
                return true;
            case "ro.fm.transmitter":
                return false;
            case "ro.fm.mulinst.recording.support":
                return false;
            case "ro.emmc.sdcard.partition":
                return 18;
            case "ro.screen.layout":
                return "normal";
            case "ro.staticwallpaper.pixelformat":
                return "RGB_565";
            case "ro.max.fling_velocity":
                return 4000;
            case "ro.telephony.default_network":
                return 10;
            case "ro.cdma.ecmexittimer":
                return 0;
            case "ro.config.combined_signal":
                return true;
            case "ro.kernel.qemu":
                return 0;
            case "ro.carrier":
                return "unknown";
            case "ro.com.google.clientidbase":
                return "android-samsung";
            case "ro.ril.hsxpa":
                return 1;
            case "ro.ril.gprsclass":
                return 10;
            case "ro.adb.qemud":
                return 1;
            case "ro.setupwizard.mode":
                return "OPTIONAL";
            case "ro.debuggable":
                return 0;
            case "ro.secure":
                return 1;
        }
        return "";
    }
});

Context: I need to change device's info like brand and fingerprint, android.os.SystemProperties has different methods like get, getInt or getBoolean, but the actual value, lets say for brand, is retrieved after calling "get" with a parameter "ro.product.brand" like this (returns "Class: google"):

Class<?> newClass = Class.forName("android.os.SystemProperties");
XposedBridge.log("Class:  " + Arrays.toString(newClass.getMethods()));
Method method = newClass.getDeclaredMethod("get", String.class);
XposedBridge.log("Class:  " + method.invoke(null, "ro.product.brand").toString());

The error is:

Crash unexpextedly: java.lang.NumberFormatException: For input string: "samsung"

The problem seems to appear because a parameter value used before changing it to "ro.product.brand" required integer in return. Thus, when I constantly change it to "ro.product.brand" (I guess it happens constantly but not once because I hook the method for all his parameters, but not for one), at some point (in my case at the 3rd time) I will get an error stated above.

As you can see in hookAllMethods, I just get the value from param.args and then check if its what I need. The issue is that there's only like 6 values and all of them are not the one I need.

Kostia
  • 11
  • 5
  • I don't really understand why you use `beforeHookedMethod` to change the argument to `ro.product.brand`. Your code in `replaceHookedMethod` looks sufficient for changing the device properties. In this method you could simply call the original `get` method for values you don't want to change. – Robert Apr 27 '23 at 11:53
  • EXACTLY. But it doesn't work. Rn I just stepped aside and used Magisk module to change the values I need, but I will definelety take my time in order to solve the issue. – Kostia Apr 27 '23 at 12:45
  • One problem I see is that you don't call the original `SystemProperties.get` method in case the requested value is not in your `case` structure. – Robert Apr 28 '23 at 14:25

0 Answers0