From db4d32c26eaad3fe5f11a47da8c2ba646d7fe90c Mon Sep 17 00:00:00 2001 From: jmp0 Date: Thu, 29 Sep 2022 16:18:23 +0800 Subject: [PATCH] bugfix unidbg wrapper --- core/build.gradle | 1 - .../interceptor/unidbg/UnidbgInterceptor.kt | 2 +- .../interceptor/unidbg/UnidbgWrapperUtils.kt | 29 +++++++++++++++---- core/src/main/java/jmp0/util/ZipUtility.kt | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index c2a5f2d..f68c6ce 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -33,7 +33,6 @@ dependencies { implementation "log4j:log4j:$log4j_version" api "org.javassist:javassist:$javassist_version" implementation 'io.github.classgraph:classgraph:4.8.146' - api 'com.github.zhkl0228:unidbg-parent:0.9.7' api 'com.github.zhkl0228:unidbg-api:0.9.7' api 'com.github.zhkl0228:unidbg-android:0.9.7' implementation 'net.lingala.zip4j:zip4j:2.10.0' diff --git a/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgInterceptor.kt b/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgInterceptor.kt index df4f890..188688b 100644 --- a/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgInterceptor.kt +++ b/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgInterceptor.kt @@ -51,7 +51,7 @@ abstract class UnidbgInterceptor(private val soName:String): IInterceptor { private fun callUnidbgJniMethod(clazz: DvmClass,methodName:String,signature:String,signatureInfo: ReflectUtilsBase.SignatureInfo,param: Array): IInterceptor.ImplStatus { - val params = UnidbgWrapperUtils.wrapperToUnidbgParams(vm,param) + val params = UnidbgWrapperUtils.wrapperToUnidbgParams(vm,param,signatureInfo) val res:Any? = when(signatureInfo.returnType!!){ Int::class.java-> clazz.callStaticJniMethodInt(emulator,methodName+signature,*params) Boolean::class.java-> clazz.callStaticJniMethodBoolean(emulator,methodName+signature,*params) diff --git a/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgWrapperUtils.kt b/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgWrapperUtils.kt index ffe973e..8278c3e 100644 --- a/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgWrapperUtils.kt +++ b/core/src/main/java/jmp0/app/interceptor/unidbg/UnidbgWrapperUtils.kt @@ -37,6 +37,22 @@ object UnidbgWrapperUtils { val longObj = vaList.getLongArg(i) retArr.add(longObj) } + "byte"->{ + val byteObj = vaList.getIntArg(i).toByte() + retArr.add(byteObj) + } + "char"->{ + val charObj = vaList.getIntArg(i).toChar() + retArr.add(charObj) + } + "short"->{ + val shortObj = vaList.getIntArg(i).toShort() + retArr.add(shortObj) + } + "boolean"->{ + val booleanObj = vaList.getIntArg(i) == 1 + retArr.add(booleanObj) + } else -> { val dvmObj = vaList.getObjectArg>(i) dvmObj.repair(androidEnvironment) @@ -70,15 +86,18 @@ object UnidbgWrapperUtils { return ArrayObject(*objectList.toTypedArray()) } } - val clazzName = className?:obj.javaClass.name.replace(".","/") + val clazzName = className?:obj::class.java.name.replace(".","/") return DvmObjectWrapper(vm.resolveClass(clazzName),obj) } - fun wrapperToUnidbgParams(vm: VM,param: Array): Array { - val retArr = ArrayList() + fun wrapperToUnidbgParams(vm: VM,param: Array,signatureInfo: ReflectUtilsBase.SignatureInfo): Array { + val retArr = ArrayList() if (param.isEmpty()) return retArr.toArray() - param.forEach { - retArr.add(toUnidbgObject(vm,it)) + for (i in param.indices){ + when(signatureInfo.paramTypes[i].name){ + "byte","short","int","long","char","float","double","boolean"-> retArr.add(param[i]) + else -> retArr.add(toUnidbgObject(vm,param[i],signatureInfo.paramTypes[i].name)) + } } return retArr.toArray() } diff --git a/core/src/main/java/jmp0/util/ZipUtility.kt b/core/src/main/java/jmp0/util/ZipUtility.kt index 1060692..d8c91c1 100644 --- a/core/src/main/java/jmp0/util/ZipUtility.kt +++ b/core/src/main/java/jmp0/util/ZipUtility.kt @@ -57,7 +57,7 @@ object ZipUtility { } bos.close() } - @SuppressWarnings("unused") + fun zip(sourceDirPath: String, zipFilePath: String) { ZipFile(zipFilePath).addFolder(File(sourceDirPath)) // val p: Path = Files.createFile(Paths.get(zipFilePath))