byte[] ttEncrypt() {
if
(logging) {
Symbol sbox0
=
module.findSymbolByName(
"sbox0"
);
/
/
在libttEncrypt.so模块中查找sbox0导出符号
Symbol sbox1
=
module.findSymbolByName(
"sbox1"
);
Inspector.inspect(sbox0.createPointer(emulator).getByteArray(
0
,
256
),
"sbox0"
);
/
/
打印sbox0导出符号在unicorn中的内存数据
Inspector.inspect(sbox1.createPointer(emulator).getByteArray(
0
,
256
),
"sbox1"
);
IHookZz hookZz
=
HookZz.getInstance(emulator);
/
/
加载HookZz,支持inline hook,文档看https:
/
/
github.com
/
jmpews
/
HookZz
hookZz.enable_arm_arm64_b_branch();
/
/
测试enable_arm_arm64_b_branch,可有可无
hookZz.wrap(module.findSymbolByName(
"ss_encrypt"
), new WrapCallback<RegisterContext>() {
/
/
inline wrap导出函数
@Override
public void preCall(Emulator<?> emulator, RegisterContext ctx, HookEntryInfo info) {
Pointer pointer
=
ctx.getPointerArg(
2
);
int
length
=
ctx.getIntArg(
3
);
byte[] key
=
pointer.getByteArray(
0
, length);
Inspector.inspect(key,
"ss_encrypt key"
);
}
@Override
public void postCall(Emulator<?> emulator, RegisterContext ctx, HookEntryInfo info) {
System.out.println(
"ss_encrypt.postCall R0="
+
ctx.getLongArg(
0
));
}
});
hookZz.disable_arm_arm64_b_branch();
hookZz.instrument(module.base
+
0x00000F5C
+
1
, new InstrumentCallback<Arm32RegisterContext>() {
@Override
public void dbiCall(Emulator<?> emulator, Arm32RegisterContext ctx, HookEntryInfo info) {
/
/
通过base
+
offset inline wrap内部函数,在IDA看到为sub_xxx那些
System.out.println(
"R3="
+
ctx.getLongArg(
3
)
+
", R10=0x"
+
Long
.toHexString(ctx.getR10Long()));
}
});
Dobby dobby
=
Dobby.getInstance(emulator);
dobby.replace(module.findSymbolByName(
"ss_encrypted_size"
), new ReplaceCallback() {
/
/
使用Dobby inline hook导出函数
@Override
public HookStatus onCall(Emulator<?> emulator, HookContext context,
long
originFunction) {
System.out.println(
"ss_encrypted_size.onCall arg0="
+
context.getIntArg(
0
)
+
", originFunction=0x"
+
Long
.toHexString(originFunction));
return
HookStatus.RET(emulator, originFunction);
}
@Override
public void postCall(Emulator<?> emulator, HookContext context) {
System.out.println(
"ss_encrypted_size.postCall ret="
+
context.getIntArg(
0
));
}
}, true);
IxHook xHook
=
XHookImpl.getInstance(emulator);
/
/
加载xHook,支持Import hook,文档看https:
/
/
github.com
/
iqiyi
/
xHook
xHook.register(
"libttEncrypt.so"
,
"strlen"
, new ReplaceCallback() {
/
/
hook libttEncrypt.so的导入函数strlen
@Override
public HookStatus onCall(Emulator<?> emulator, HookContext context,
long
originFunction) {
Pointer pointer
=
context.getPointerArg(
0
);
String
str
=
pointer.getString(
0
);
System.out.println(
"strlen="
+
str
);
context.push(
str
);
return
HookStatus.RET(emulator, originFunction);
}
@Override
public void postCall(Emulator<?> emulator, HookContext context) {
System.out.println(
"strlen="
+
context.pop()
+
", ret="
+
context.getIntArg(
0
));
}
}, true);
xHook.register(
"libttEncrypt.so"
,
"memmove"
, new ReplaceCallback() {
@Override
public HookStatus onCall(Emulator<?> emulator,
long
originFunction) {
RegisterContext context
=
emulator.getContext();
Pointer dest
=
context.getPointerArg(
0
);
Pointer src
=
context.getPointerArg(
1
);
int
length
=
context.getIntArg(
2
);
Inspector.inspect(src.getByteArray(
0
, length),
"memmove dest="
+
dest);
return
HookStatus.RET(emulator, originFunction);
}
});
xHook.register(
"libttEncrypt.so"
,
"memcpy"
, new ReplaceCallback() {
@Override
public HookStatus onCall(Emulator<?> emulator,
long
originFunction) {
RegisterContext context
=
emulator.getContext();
Pointer dest
=
context.getPointerArg(
0
);
Pointer src
=
context.getPointerArg(
1
);
int
length
=
context.getIntArg(
2
);
Inspector.inspect(src.getByteArray(
0
, length),
"memcpy dest="
+
dest);
return
HookStatus.RET(emulator, originFunction);
}
});
xHook.refresh();
/
/
使Import hook生效
}