首页 > 基础资料 博客日记
unidbg-补环境访问文件及目录
2023-07-24 10:05:33基础资料围观590次
文章unidbg-补环境访问文件及目录分享给大家,欢迎收藏Java资料网,专注分享技术知识
1.可以采用重定向
2.采用虚拟目录
前两个文件不用补
package com.file;
import com.github.unidbg.AndroidEmulator;
import com.github.unidbg.Emulator;
import com.github.unidbg.file.FileResult;
import com.github.unidbg.file.IOResolver;
import com.github.unidbg.linux.android.AndroidEmulatorBuilder;
import com.github.unidbg.linux.android.AndroidResolver;
import com.github.unidbg.linux.android.dvm.DalvikModule;
import com.github.unidbg.linux.android.dvm.DvmClass;
import com.github.unidbg.linux.android.dvm.VM;
import com.github.unidbg.linux.file.SimpleFileIO;
import com.github.unidbg.memory.Memory;
import java.io.File;
import java.io.IOException;
public class FileDemo{
private final AndroidEmulator emulator;
private final DvmClass MainActivity;
private final VM vm;
public FileDemo() {
emulator = AndroidEmulatorBuilder
.for32Bit()
//虚拟目录
.setRootDir(new File("unidbg-android/src/test/resources/FileDemo/VFS"))
.build();
Memory memory = emulator.getMemory();
memory.setLibraryResolver(new AndroidResolver(23));
vm = emulator.createDalvikVM(new File("unidbg-android/src/test/resources/FileDemo/app-debug.apk"));
// 打开日志
vm.setVerbose(true);
// 在SO加载前添加文件重定位器
emulator.getSyscallHandler().addIOResolver(new MyIOResolver());
DalvikModule dm = vm.loadLibrary("fileinunidbg", true);
MainActivity = vm.resolveClass("com/example/fileinunidbg/MainActivity");
dm.callJNI_OnLoad(emulator);
}
public void destroy() throws IOException {
emulator.close();
}
public void call(String pathName) {
String methodSign = "stringFromJNI(Ljava/lang/String;)Ljava/lang/String;";
MainActivity.callStaticJniMethodObject(emulator, methodSign, pathName);
}
public static void main(String[] args) throws IOException {
FileDemo fileDemo = new FileDemo();
String arg = "/data/user/0/com.example.fileinunidbg/files";
fileDemo.call(arg);
// 运行结束后关闭
fileDemo.destroy();
}
}
package com.file;
import com.github.unidbg.Emulator;
import com.github.unidbg.file.FileResult;
import com.github.unidbg.file.IOResolver;
import com.github.unidbg.linux.file.ByteArrayFileIO;
import com.github.unidbg.linux.file.DirectoryFileIO;
import com.github.unidbg.linux.file.SimpleFileIO;
import java.io.File;
import java.nio.charset.StandardCharsets;
public class MyIOResolver implements IOResolver {
@Override
public FileResult resolve(Emulator emulator, String pathname, int oflags) {
System.out.println("lilac open file:"+pathname);
if(pathname.equals("/data/user/0/com.example.fileinunidbg/files/key.txt")){
return FileResult.success(new SimpleFileIO(oflags, new File("unidbg-android/src/test/resources/FileDemo/key.txt"), pathname));
// return FileResult.success(new ByteArrayFileIO(oflags, pathname, String.valueOf(System.currentTimeMillis()).getBytes(StandardCharsets.UTF_8)));
// return null;
// return FileResult.failed(13);
}
// // 返回对应的文件夹(目录文件)
// if(pathname.equals("/data/user/0/com.example.fileinunidbg/files/demo2")){
// return FileResult.success(new DirectoryFileIO(oflags, pathname,new File("unidbg-android/src/test/resources/FileDemo/demo2")))
// return FileResult.success(new DirectoryFileIO(oflags, pathname, new DirectoryFileIO.DirectoryEntry(true, String.valueOf(System.currentTimeMillis())), new DirectoryFileIO.DirectoryEntry(true, "1234")));
// }
// if(pathname.equals("/data/user/0/com.example.fileinunidbg/files/demo2/1.txt")){
// return FileResult.success(new SimpleFileIO(oflags, new File("unidbg-android/src/test/resources/FileDemo/demo2/1.txt"), pathname));
// }
// if(pathname.equals("/data/user/0/com.example.fileinunidbg/files/demo2/2.txt")){
// return FileResult.success(new SimpleFileIO(oflags, new File("unidbg-android/src/test/resources/FileDemo/demo2/2.txt"), pathname));
// }
// if(pathname.equals("/data/user/0/com.example.fileinunidbg/files/demo2/3.txt")){
// return FileResult.success(new SimpleFileIO(oflags, new File("unidbg-android/src/test/resources/FileDemo/demo2/3.txt"), pathname));
// }
return null;
}
}
文章来源:https://blog.csdn.net/weixin_38927522/article/details/128085091
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
标签: