public
class
iBox extends AbstractJni implements IOResolver<AndroidFileIO> {
private final AndroidEmulator emulator;
private final VM vm;
private final Module module;
iBox() {
emulator
=
AndroidEmulatorBuilder.for64Bit().build();
/
/
创建模拟器实例,要模拟
32
位或者
64
位,在这里区分
final Memory memory
=
emulator.getMemory();
/
/
模拟器的内存操作接口
memory.setLibraryResolver(new AndroidResolver(
23
));
/
/
设置系统类库解析
vm
=
emulator.createDalvikVM(new
File
(
"unidbg-android/src/test/resources/box.apk"
));
new AndroidModule(emulator, vm).register(memory);
vm.setVerbose(false);
DalvikModule dm
=
vm.loadLibrary(new
File
(
"unidbg-android/src/test/resources/libtiger_tally.so"
), true);
module
=
dm.getModule();
vm.setJni(this);
dm.callJNI_OnLoad(emulator);
DvmClass dvmClass
=
vm.resolveClass(
"com/aliyun/TigerTally/TigerTallyAPI"
);
dvmClass.callStaticJniMethodObject(emulator,
"_genericNt1(ILjava/lang/String;)I"
,
1
,vm.addLocalObject(new StringObject(vm,
"EWA40T3eMNVkLmj8Ur9CuQExbcOti8c3yd-I8xDkLhvphNMuRujkY7V6lKbvAtE2qXa4kTWSnXmo0HXfuUXRgyFNXYwhwvvf7yUYQ-DjWjAa34fjA9yJCam4Llddmcu3D8BQKw4gR-nkYzzOx0uGj9OkfgUHoFxF00akZNyeMrs="
)));
DvmObject<?> dvmObject
=
dvmClass.callStaticJniMethodObject(emulator,
"_genericNt3(I[B)Ljava/lang/String;"
,
2
,new ByteArray(vm,"".getBytes(StandardCharsets.UTF_8)));
System.out.println(dvmObject);
}
public static void main(String[] args) {
iBox test
=
new iBox();
}
@Override
public DvmObject<?> callStaticObjectMethodV(BaseVM vm, DvmClass dvmClass, String signature, VaList vaList) {
switch (signature){
case
"com/aliyun/TigerTally/A->ct()Landroid/content/Context;"
:
return
vm.resolveClass(
"android/app/Application"
,vm.resolveClass(
"android/content/ContextWrapper"
,vm.resolveClass(
"android/content/Context"
))).newObject(signature);
case
"com/aliyun/TigerTally/A->pb(Ljava/lang/String;[B)Ljava/lang/String;"
:
return
new StringObject(vm,
"NaNzfpjiUUl2gNOrCC7S4XS4SD0CH48UatD3GXb5Fh+NYB+0CenYh5nXysYWCfwd+sD4NbdYBDrlKPo5teC09A=="
);
}
return
super
.callStaticObjectMethodV(vm, dvmClass, signature, vaList);
}
@Override
public DvmObject<?> callObjectMethodV(BaseVM vm, DvmObject<?> dvmObject, String signature, VaList vaList) {
switch (signature){
case
"android/content/pm/PackageManager->getApplicationInfo(Ljava/lang/String;I)Landroid/content/pm/ApplicationInfo;"
:
return
vm.resolveClass(
"Landroid/content/pm/ApplicationInfo;"
).newObject(signature);
case
"android/content/pm/PackageManager->getApplicationLabel(Landroid/content/pm/ApplicationInfo;)Ljava/lang/CharSequence;"
:
return
new StringObject(vm,
"Ljava/lang/CharSequence;"
);
case
"android/app/Application->getFilesDir()Ljava/io/File;"
:
return
vm.resolveClass(
"Ljava/io/File;"
);
case
"java/lang/String->getAbsolutePath()Ljava/lang/String;"
:
return
new StringObject(vm,
"Ljava/lang/String;"
);
case
"android/app/Application->getSharedPreferences(Ljava/lang/String;I)Landroid/content/SharedPreferences;"
:
return
vm.resolveClass(
"Landroid/content/SharedPreferences;"
);
case
"java/lang/Class->getAbsolutePath()Ljava/lang/String;"
:
return
new StringObject(vm,
"Ljava/lang/String;"
);
}
return
super
.callObjectMethodV(vm, dvmObject, signature, vaList);
}
@Override
public DvmObject<?> getStaticObjectField(BaseVM vm, DvmClass dvmClass, String signature) {
switch (signature){
case
"android/os/Build->BRAND:Ljava/lang/String;"
:
return
new StringObject(vm,
"Ljava/lang/String;"
);
case
"android/os/Build->MODEL:Ljava/lang/String;"
:
return
new StringObject(vm,
"Ljava/lang/String;"
);
case
"android/os/Build$VERSION->RELEASE:Ljava/lang/String;"
:
return
new StringObject(vm,
"Ljava/lang/String;"
);
case
"android/os/Build->DEVICE:Ljava/lang/String;"
:
return
new StringObject(vm,
"Ljava/lang/String;"
);
}
return
super
.getStaticObjectField(vm,dvmClass,signature);
}
public void destroy() {
try
{
emulator.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public FileResult<AndroidFileIO> resolve(Emulator<AndroidFileIO> emulator, String pathname,
int
oflags) {
return
null;
}
}
public
class
iBox extends AbstractJni implements IOResolver<AndroidFileIO> {
private final AndroidEmulator emulator;
private final VM vm;
private final Module module;
iBox() {
emulator
=
AndroidEmulatorBuilder.for64Bit().build();
/
/
创建模拟器实例,要模拟
32
位或者
64
位,在这里区分
final Memory memory
=
emulator.getMemory();
/
/
模拟器的内存操作接口
memory.setLibraryResolver(new AndroidResolver(
23
));
/
/
设置系统类库解析
vm
=
emulator.createDalvikVM(new
File
(
"unidbg-android/src/test/resources/box.apk"
));
new AndroidModule(emulator, vm).register(memory);
vm.setVerbose(false);
DalvikModule dm
=
vm.loadLibrary(new
File
(
"unidbg-android/src/test/resources/libtiger_tally.so"
), true);
module
=
dm.getModule();
vm.setJni(this);
dm.callJNI_OnLoad(emulator);
DvmClass dvmClass
=
vm.resolveClass(
"com/aliyun/TigerTally/TigerTallyAPI"
);
dvmClass.callStaticJniMethodObject(emulator,
"_genericNt1(ILjava/lang/String;)I"
,
1
,vm.addLocalObject(new StringObject(vm,
"EWA40T3eMNVkLmj8Ur9CuQExbcOti8c3yd-I8xDkLhvphNMuRujkY7V6lKbvAtE2qXa4kTWSnXmo0HXfuUXRgyFNXYwhwvvf7yUYQ-DjWjAa34fjA9yJCam4Llddmcu3D8BQKw4gR-nkYzzOx0uGj9OkfgUHoFxF00akZNyeMrs="
)));
DvmObject<?> dvmObject
=
dvmClass.callStaticJniMethodObject(emulator,
"_genericNt3(I[B)Ljava/lang/String;"
,
2
,new ByteArray(vm,"".getBytes(StandardCharsets.UTF_8)));
System.out.println(dvmObject);
}
public static void main(String[] args) {
iBox test
=
new iBox();
}
@Override
public DvmObject<?> callStaticObjectMethodV(BaseVM vm, DvmClass dvmClass, String signature, VaList vaList) {
switch (signature){
case
"com/aliyun/TigerTally/A->ct()Landroid/content/Context;"
:
return
vm.resolveClass(
"android/app/Application"
,vm.resolveClass(
"android/content/ContextWrapper"
,vm.resolveClass(
"android/content/Context"
))).newObject(signature);
case
"com/aliyun/TigerTally/A->pb(Ljava/lang/String;[B)Ljava/lang/String;"
:
return
new StringObject(vm,
"NaNzfpjiUUl2gNOrCC7S4XS4SD0CH48UatD3GXb5Fh+NYB+0CenYh5nXysYWCfwd+sD4NbdYBDrlKPo5teC09A=="
);
}
return
super
.callStaticObjectMethodV(vm, dvmClass, signature, vaList);
}
@Override
public DvmObject<?> callObjectMethodV(BaseVM vm, DvmObject<?> dvmObject, String signature, VaList vaList) {
switch (signature){
case
"android/content/pm/PackageManager->getApplicationInfo(Ljava/lang/String;I)Landroid/content/pm/ApplicationInfo;"
:
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
最后于 2022-10-24 10:24
被wx_白熊编辑
,原因: 格式