zhkl0228 / unidbg

Allows you to emulate an Android native library, and an experimental iOS emulation
Apache License 2.0
3.88k stars 966 forks source link

我调试so代码Context参数UnsupportedOperationException: android/content/Context->getSharedPreferences(Ljava/lang/String;I)Landroid/content/SharedPreferences; #412

Open kaixinwangzi1982 opened 2 years ago

kaixinwangzi1982 commented 2 years ago

libcom_wuba_uc_rsa.so.zip public class RsaCryptService { private static final String TAG = "RsaCryptService"; private static boolean initSuccess;

public static String doEncrypt(String str) {
    loadSoAndInit();
    try {
        if (TextUtils.isEmpty(str)) {
            Log.w("Log", "待加密串是空!!");
            return "";
        }
        byte[] bytes = str.getBytes("utf-8");
        if (bytes == null || bytes.length == 0) {
            Log.d(TAG, "encrypt: input is null or length is 0");
        }
        String encrypt = encrypt(bytes);
        if (TextUtils.isEmpty(encrypt)) {
            Log.d(TAG, "encrypt: data is null or length is 0");
        }
        return encrypt;
    } catch (Throwable th) {
        Log.w(TAG, "加密串发生异常!" + th.getMessage(), th);
        return "";
    }
}

private static native String encrypt(byte[] bArr);

public static String getRsaVersion() {
    try {
        loadSoAndInit();
        return version();
    } catch (Exception e) {
        e.printStackTrace();
        return "UN_KNOW";
    }
}

private static native void init(Context context);

private static void loadSoAndInit() {
    if (!initSuccess) {
        try {
            b.e(com.wuba.loginsdk.login.b.n, "com_wuba_uc_rsa", a.e);
            init(com.wuba.loginsdk.login.b.n);
            initSuccess = true;
        } catch (Throwable th) {
            Log.d(TAG, "init error", th);
        }
    }
}

private static native String version();

}

下面是我java代码 // 密码加密 public static String encrypt(String info) throws IOException { // 1、需要调用的so文件所在路径 String soFilePath = "/disk/apps/wubaapp/libcom_wuba_uc_rsa.so"; // 2、需要调用函数所在的Java类完整路径,比如a/b/c/d等等,注意需要用/代替. String classPath = "com/wuba/uc/RsaCryptService"; // 3、需要调用函数的函数签名,我这里调用EncryptUtils中的getGameKey方法,由于此方法没有参数列表,所以不需要传入 String methodEncryp = "encrypt([B)Ljava/lang/String;"; // 输出getGameKey方法调用结果 WuBaAppSignUtils encryptUtilsJni = new WuBaAppSignUtils(soFilePath, classPath); //调用native init方法 String methodInit = "init(Landroid/content/Context;)V"; encryptUtilsJni.myJni(methodInit, encryptUtilsJni.vm.resolveClass("android/content/Context").newObject(null)); byte[] bytes = (byte[]) null; if(StringUtils.isNotBlank(info)) { bytes = info.getBytes(); } logger.info("加密接收到的字符为info:[{}]", info); String encryption = encryptUtilsJni.myJni(methodEncryp, new ByteArray(encryptUtilsJni.vm, bytes)); logger.info("加密结果:[{}]", encryption); encryptUtilsJni.destroy(); return encryption; }

如下是错误,应该是context传参null有问题吧,看不明白 [main]D/Psdk_so_lib: SUPPORT LIST: 58APP 58同镇 SDKDemo 招财猫 中华英才 安居客 58同镇站长 58校校 赶集 云车市 58钱柜 58二手车 金融保险 58公寓商家 58公寓管家 58好借 58商家通 58在线大学 58车商通 58白菜商家版 58新车 58到家精选 58商办通 灵活就业 优信拍卖家端 优信拍 58用车 58达人版 58直播 58车服 58全景拍摄 城阳智慧务工平台 EncryptDemo 58到家 2022-04-06 11:27:16.638 [http-apr-48080-exec-3] WARN c.g.unidbg.linux.ARM32SyscallHandler.hook - handleInterrupt intno=2, NR=-1073743984, svcNumber=0x113, PC=unicorn@0xfffe01c4, syscall=null java.lang.UnsupportedOperationException: android/content/Context->getSharedPreferences(Ljava/lang/String;I)Landroid/content/SharedPreferences; at com.github.unidbg.utils.WuBaAppSignUtils$1.callObjectMethod(WuBaAppSignUtils.java:95) at com.github.unidbg.linux.android.dvm.DvmMethod.callObjectMethod(DvmMethod.java:59) at com.github.unidbg.linux.android.dvm.DalvikVM$20.handle(DalvikVM.java:363) at com.github.unidbg.linux.ARM32SyscallHandler.hook(ARM32SyscallHandler.java:103) at unicorn.Unicorn$NewHook.onInterrupt(Unicorn.java:128) at unicorn.Unicorn.emu_start(Native Method) at com.github.unidbg.AbstractEmulator.emulate(AbstractEmulator.java:357) at com.github.unidbg.AbstractEmulator.eFunc(AbstractEmulator.java:445) at com.github.unidbg.arm.AbstractARMEmulator.eFunc(AbstractARMEmulator.java:208) at com.github.unidbg.Module.emulateFunction(Module.java:156) at com.github.unidbg.linux.android.dvm.DvmObject.callJniMethod(DvmObject.java:115) at com.github.unidbg.linux.android.dvm.DvmClass.callStaticJniMethodObject(DvmClass.java:250) at com.github.unidbg.utils.WuBaAppSignUtils.myJni(WuBaAppSignUtils.java:109) at com.github.unidbg.utils.WuBaAppSignUtils.encrypt(WuBaAppSignUtils.java:217) at com.github.servlet.YdjjEncryptServlet.doPost(YdjjEncryptServlet.java:32) at com.github.servlet.YdjjEncryptServlet.doGet(YdjjEncryptServlet.java:25) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2555) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2544) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 2022-04-06 11:27:16.708 [http-apr-48080-exec-3] WARN com.github.unidbg.AbstractEmulator.emulate - emulate RX@0x400027e5[libcom_wuba_uc_rsa.so]0x27e5 exception sp=unicorn@0xbffff6e8, msg=android/content/Context->getSharedPreferences(Ljava/lang/String;I)Landroid/content/SharedPreferences;, offset=85ms 2022-04-06 11:27:16.712 [http-apr-48080-exec-3] INFO c.g.unidbg.utils.WuBaAppSignUtils.encrypt - 加密接收到的字符为info:[test] [main]D/Psdk_so_lib: no power! 2022-04-06 11:27:16.733 [http-apr-48080-exec-3] INFO c.g.unidbg.utils.WuBaAppSignUtils.encrypt - 加密结果:[]

kaixinwangzi1982 commented 2 years ago

so文件在附件中

hmlyn commented 10 months ago

楼主解决了吗?我也是Context传参到so里,报错null为空