frida android hooking, unicode decode issue

Created on 7 Dec 2017  ·  4Comments  ·  Source: frida/frida

Hi,
I want to hook the android code(dex file) below.

    private static boolean ᐨ() {
        boolean v2_1;
        Runtime v2 = Runtime.getRuntime();
        try {
            v2.exec("su");
            v2_1 = true;
        }
        catch(Exception ) {
            v2_1 = false;
        }

        if(!v2_1) {
            String[] v2_2 = new String[]{"/system/bin/su", "/system/xbin/su", "/system/app/SuperUser.apk", "/data/data/com.noshufou.android.su", "/"};
            boolean v3 = false;
            int v4;
            for(v4 = 0; v4 < v2_2.length; ++v4) {
                File v0 = new File(v2_2[v4]);
                File v3_1 = v0;
                if((v0.exists()) && (v3_1.isFile())) {
                    v3 = true;
                    break;
                }

                v3 = false;
            }

            v2_1 = v3;
        }

        return v2_1;
    }

and I will modify return values. So, I write down the python code below.

a[1] = Java.use("o.h");
a[1].ᐨ.implementation = function() {
var ret = this.ᐨ()
console.log("o/h;->ᐨ [*] ret: " + ret)
return ret
}; 

However, python code is occured Error... T.T
I think the method name( ᐨ) is a problem.

Traceback (most recent call last):
  File "C:/Users/cgbcsh/android_hook.py", line 89, in <module>
    script = session.create_script(jscode)
  File "C:\Python27\lib\site-packages\frida\core.py", line 182, in create_script
    return Script(self._impl.create_script(*args, **kwargs))

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 1635: ordinal not in range(128)

I want to solve this problem. T.T
Thank you.

Most helpful comment

Hi @cgbcsh,

I see you wrote JS instead of Python code for your hooks, right? Several things to discuss:

  1. Try to use unicode encoding instead of non-ascii characters. ( e.g. this.\u0345() instead of this.ᐨ())
  2. Python script should include both the JS file opening and encoding with UTF8
  3. Did you try with Frida REPL? Shouldn't give you errors

Cheers,
Eduardo N.

All 4 comments

Hi @cgbcsh,

I see you wrote JS instead of Python code for your hooks, right? Several things to discuss:

  1. Try to use unicode encoding instead of non-ascii characters. ( e.g. this.\u0345() instead of this.ᐨ())
  2. Python script should include both the JS file opening and encoding with UTF8
  3. Did you try with Frida REPL? Shouldn't give you errors

Cheers,
Eduardo N.

The issue is that create_script() expects either a unicode value, or a str value that's valid UTF-8. One common way to do this is:

import codecs

with codecs.open("agent.js", "r", "utf-8") as f:
    source = f.read()
script = session.create_script(source)

awesome!!!!!!!!!!!!!!!
frida is also excellent.
Thanks for your response.

@oleavr
I have this same problem:

clz2.-getcom-oppo-findphone-common-InstructionTypeSwitchesValues.implementation

there is the special code - in the script,I use the above method can't resolve this problem。

Was this page helpful?
0 / 5 - 0 ratings