1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| package com.dongchedi;
import com.github.unidbg.AndroidEmulator; import com.github.unidbg.Module; import com.github.unidbg.linux.android.AndroidEmulatorBuilder; import com.github.unidbg.linux.android.AndroidResolver; import com.github.unidbg.linux.android.dvm.*; import com.github.unidbg.memory.Memory; import com.github.unidbg.virtualmodule.android.AndroidModule; import org.apache.log4j.Level; import org.apache.log4j.Logger;
import java.io.File; import java.util.ArrayList; import java.util.List;
public class dongchedi extends AbstractJni { private final AndroidEmulator emulator; private final VM vm; private final Module module; dongchedi() { Logger.getLogger("com.github.unidbg.linux.ARM32SyscallHandler").setLevel(Level.DEBUG); Logger.getLogger("com.github.unidbg.unix.UnixSyscallHandler").setLevel(Level.DEBUG); Logger.getLogger("com.github.unidbg.AbstractEmulator").setLevel(Level.DEBUG); Logger.getLogger("com.github.unidbg.linux.android.dvm.DalvikVM").setLevel(Level.DEBUG); Logger.getLogger("com.github.unidbg.linux.android.dvm.BaseVM").setLevel(Level.DEBUG); Logger.getLogger("com.github.unidbg.linux.android.dvm").setLevel(Level.DEBUG);
emulator = AndroidEmulatorBuilder.for32Bit().build(); final Memory memory = emulator.getMemory(); memory.setLibraryResolver(new AndroidResolver(23)); vm = emulator.createDalvikVM(new File("unidbg-android\\src\\test\\java\\com\\dongchedi\\dongchedi_6_5_1.apk")); vm.setJni(this); vm.setVerbose(true); new AndroidModule(emulator, vm).register(memory); DalvikModule dm = vm.loadLibrary("cjtfcc", true); module = dm.getModule(); dm.callJNI_OnLoad(emulator); }
public String tfccDecrypt(int param1, int param2, String param3, String param4) { List<Object> list = new ArrayList<>(); list.add(vm.getJNIEnv()); list.add(0); list.add(param1); list.add(param2); StringObject stringObject1 = new StringObject(vm, param3); list.add(vm.addLocalObject(stringObject1)); StringObject stringObject2 = new StringObject(vm, param4); list.add(vm.addLocalObject(stringObject2)); Number number = module.callFunction(emulator, 0xa2ac, list.toArray()); System.out.println(vm.getObject(number.intValue()).getValue().toString()); return null; }
public static void main(String[] args) { dongchedi test = new dongchedi(); test.tfccDecrypt(9, 1, "14zRM+40n2UGVx0DlI7hqDFjsxGR6eJsnnxUME5ZDT8=", "AQAAAIY8QCEBiAWgEHTCmugnR4hHWlbOmpfOHoYQ+gXQHXvSrCBlQtFmGM8T7eHljYYTD8vWOsQa8SuOaBwMTYOS03qjuUktB2dRu3+mWr4z5N3uMrb1Es/MTUrWx8JGHVoX1z7f6luarDvT9Wf0KKbfHRkqaJANlwVEqULsZU6HkJ0zkaFh3AnU5eQRsPoxttOPOhsVLv/kNjpm1" + "qBHkENXSedO4MN+PGybTCOKH3Ri6dvoX9EXCUr41o2W0ujI46nYn7vUrRkHgHNOOrGkIL7Acn0wrU6nj3cZuFpxb+W+u6r+MFI8ScE9XQya3322RRqOQUr1xWXpCucv/zknN7pjyzptYk8iWRfeaCT+iSjkmwa+3EStu3U/TQakF1xh46hjPOczx7elte6qV9ztDyF61Eu" + "Nrz4K+9O4TgqDeg9FGv7k+sNXg4M8L+Vx2BzJ/9MfaOFF5YXlI2oeMk0FReBTV8cBdXv2j23ju5HUpNo45dYF+tLihymL3maOiuWYviIAk8OKjNG+juruF4YuYoAqJoJSvuZ9Avujl3mqL66AdZmzG7vTa29S1MWIwu3XYj96lcbGSav9m5g4yRb6zXcQDIpqAmYHVgRjX" + "7adt09SOuvrcuORpUh2jSt5smO+lpR7fuHk4tlCr6OlRr360IgJr82PmeAAKz1dV9tHGYlV+618tjgi36J4iLuWaw6Ix9iJ1R6cFJY6JIX8pU8NoGoUFDjK3Dm8Pm9j72J9cTQpEMR/HCT3BOw5YTTTQHl3eQgdZevUD8HFnECMvajFZxKe6obyPieE41WBk/EQ5WI2Bwtu" + "rmyzxEq/VPIm1Ufoq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MIvOzOrPbLwJjs8xXbkCH8GvEYiqQfMw2B3w6YIawzwVlcx+4CypfZvtYTatE+XCzs2j8rjFUZWUBv2olwN3ZfL3a0AfpAo0+LTSRIivoQSNEEuk7sIg2xU1lonGUe8JRYJovoyczZNNC/OUI5wD5kWCEM0v3A/kO" + "Du50mX+Sl1LtmX8FQdy1q5nbS1BWFqfF6cibw4CL5yMH"); } }
|
运行样本后报错:
GetObjectClass 的 object 为 null
当前报错位置已经断下来了,输入bt查看调用栈
用ida打开样本so,跳到 0x092b8 地址
先分析一下,查看GetObjectClass的文档
1
| jclass GetObjectClass(JNIEnv *env, jobject obj);
|
有两个参数,env和object,根据ARM函数调用约定采用,参数1参数4 分别保存到 R0R3 寄存器中
所以往上看R1出现的地址位置,0x92A8,进行断点查看调用的位置
ida跳到0x0a554,转为汇编代码后,可以看到object是v24,也就是入参a2,
查看该函数的地址为0xa2ac,这跟我们一开始调用的地址一样的,在看当时传递的第二个object,确实传的0
可以通过jadx查看正确的对象
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public String tfccDecrypt(int param1, int param2, String param3, String param4) { List<Object> list = new ArrayList<>(); list.add(vm.getJNIEnv());
DvmClass Tfcc = vm.resolveClass("com/bdcaijing/tfccsdk/Tfcc"); DvmObject<?> TfccObject = Tfcc.newObject(null); list.add(vm.addLocalObject(TfccObject)); list.add(param1); list.add(param2); StringObject stringObject1 = new StringObject(vm, param3); list.add(vm.addLocalObject(stringObject1)); StringObject stringObject2 = new StringObject(vm, param4); list.add(vm.addLocalObject(stringObject2)); Number number = module.callFunction(emulator, 0xa2ac, list.toArray()); System.out.println(vm.getObject(number.intValue()).getValue().toString()); return null; }
|
再次运行就可以了