package com.match.app9;
import
com.github.unidbg.linux.android.dvm.AbstractJni;
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.pointer.UnidbgPointer;
import
com.github.unidbg.utils.Inspector;
import
java.io.
File
;
import
java.io.IOException;
import
java.nio.ByteBuffer;
import
java.util.ArrayList;
import
java.util.
List
;
public
class
App9 extends AbstractJni {
private final AndroidEmulator emulator;
private final VM vm;
private final Module module;
private DvmObject AsyncTCP;
public byte[]
input
;
public byte[] data;
App9() throws IOException {
emulator
=
AndroidEmulatorBuilder.for64Bit().setProcessName(
"com.yuanrenxue.match2022"
).build();
/
/
创建模拟器实例
final Memory memory
=
emulator.getMemory();
/
/
模拟器的内存操作接口
memory.setLibraryResolver(new AndroidResolver(
23
));
/
/
设置系统类库解析
vm
=
emulator.createDalvikVM(new
File
(
"unidbg-android/src/test/resources/match/app-match.apk"
));
/
/
创建Android虚拟机
DalvikModule dm
=
vm.loadLibrary(new
File
(
"unidbg-android/src/test/resources/match/arm64-v8a/libmatch09.so"
), true);
/
/
加载so到虚拟内存
module
=
dm.getModule();
/
/
获取本SO模块的句柄
vm.setJni(this);
vm.setVerbose(true);
dm.callJNI_OnLoad(emulator);
AsyncTCP
=
vm.resolveClass(
"com.yuanrenxue.match2022.nine.tcp.AsyncTCP"
).newObject(null);
}
public static String printHexString(byte[] b) {
StringBuilder resp
=
new StringBuilder();
for
(
int
i
=
0
; i < b.length; i
+
+
) {
String
hex
=
Integer.toHexString(b[i] &
0xff
);
if
(
hex
.length()
=
=
1
)
hex
=
'0'
+
hex
;
resp.append(
hex
.toUpperCase());
}
/
/
System.out.println(
"StringBuilder: "
+
resp);
return
resp.toString();
}
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2){
byte[] byte_3
=
new byte[byte_1.length
+
byte_2.length];
System.arraycopy(byte_1,
0
, byte_3,
0
, byte_1.length);
System.arraycopy(byte_2,
0
, byte_3, byte_1.length, byte_2.length);
return
byte_3;
}
public String call_enc(String page){
/
/
准备入参
List
<
Object
>
list
=
new ArrayList<>(
10
);
byte[] bArr1
=
{
0x08
};
byte[] bArr2
=
String.
format
(
"%04d"
, Integer.valueOf(page)).getBytes();
byte[] bArr
=
byteMerger(bArr1,bArr2);
/
/
拼接byte数组
UnidbgPointer buff0
=
emulator.getMemory().malloc(
0x100
, true).getPointer();
/
/
为第一个参数开辟内存
buff0.write(
0
,bArr,
0
,bArr.length);
/
/
写入数据
UnidbgPointer buff
=
emulator.getMemory().malloc(
0x100
, true).getPointer();
/
/
为第二个参数开辟内存
list
.add(buff0.peer);
list
.add(buff.peer);
Number number
=
module.callFunction(emulator,
0xe7a28
,
list
.toArray());
String s
=
printHexString(buff.getByteArray(
0
,
0x42
));
System.out.println(s);
return
s;
}
public static void main(String[] args) throws IOException {
App9 test
=
new App9();
test.call_enc(
"10"
);
}
}