文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

unidbg-ZipFile补环境

2023-08-16 18:21

关注
package com.dta.lesson32;import com.github.unidbg.AndroidEmulator;import com.github.unidbg.Module;import com.github.unidbg.linux.AndroidElfLoader;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.linux.android.dvm.array.ByteArray;import com.github.unidbg.memory.Memory;import org.apache.log4j.Level;import org.apache.log4j.Logger;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.security.MessageDigest;import java.util.ArrayList;import java.util.Enumeration;import java.util.List;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;public class MainActivity extends AbstractJni {    private final AndroidEmulator emulator;    private final VM vm;    private final Memory memory;    private final Module module;    public MainActivity(){        emulator = AndroidEmulatorBuilder                .for32Bit()                //.setRootDir(new File("target/rootfs/default"))                //.addBackendFactory(new DynarmicFactory(true))                .build();        memory = emulator.getMemory();        memory.setLibraryResolver(new AndroidResolver(23));        vm = emulator.createDalvikVM();        vm.setVerbose(true);        vm.setJni(this);        DalvikModule dalvikModule = vm.loadLibrary(new File("unidbg-android/src/test/java/com/dta/lesson32/libdogpro.so"), false);        module = dalvikModule.getModule();        vm.callJNI_OnLoad(emulator,module);    }    public static void main(String[] args) {        long start = System.currentTimeMillis();        MainActivity mainActivity = new MainActivity();        System.out.println("load the vm "+( System.currentTimeMillis() - start )+ "ms");        mainActivity.getHash();    }    private void getHash() {        DvmObject dvmObject = vm.resolveClass("com/example/dogpro/MainActivity").newObject(null);        //public native String getHash(String str);        ///data/app/com.example.dogpro-pnF2J3-qBi8ei74vXTNXmQ==/base.apk        String input = "/data/app/com.example.dogpro-pnF2J3-qBi8ei74vXTNXmQ==/base.apk";        DvmObject ret = dvmObject.callJniMethodObject(emulator, "getHash(Ljava/lang/String;)Ljava/lang/String;", input);        System.out.println("result ==> "+ret.getValue());    }    @Override    public DvmObject newObjectV(BaseVM vm, DvmClass dvmClass, String signature, VaList vaList) {        if (signature.equals("java/util/zip/ZipFile->(Ljava/lang/String;)V")){            String name = (String) vaList.getObjectArg(0).getValue();            try {                if (name.equals("/data/app/com.example.dogpro-pnF2J3-qBi8ei74vXTNXmQ==/base.apk")){                    ZipFile zipFile = new ZipFile("unidbg-android/src/test/java/com/dta/lesson32/app-debug.apk");                    return vm.resolveClass("java/util/zip/ZipFile").newObject(zipFile);                }                return null;            } catch (IOException e) {                e.printStackTrace();                return null;            }        }        return super.newObjectV(vm, dvmClass, signature, vaList);    }    @Override    public DvmObject callObjectMethodV(BaseVM vm, DvmObject dvmObject, String signature, VaList vaList) {//        if (signature.equals("java/util/zip/ZipFile->entries()Ljava/util/Enumeration;")){//            ZipFile zipFile = (ZipFile) dvmObject.getValue();//            Enumeration entries = zipFile.entries();//            DvmClass ZipEntryClass = vm.resolveClass("java/util/zip/ZipEntry");//            List> objs = new ArrayList<>();//            while (entries.hasMoreElements()){//                ZipEntry zipEntry = entries.nextElement();//                objs.add(ZipEntryClass.newObject(zipEntry));//            }//            return new com.github.unidbg.linux.android.dvm.Enumeration(vm,objs);//        }        if (signature.equals("java/util/zip/ZipEntry->getName()Ljava/lang/String;")){            ZipEntry zipEntry = (ZipEntry) dvmObject.getValue();            String name = zipEntry.getName();            return new  StringObject(vm,name);        }        if (signature.equals("java/lang/String->toLowerCase()Ljava/lang/String;")){            String s = (String) dvmObject.getValue();            String s1 = s.toLowerCase();            return new StringObject(vm,s1);        }        if (signature.equals("java/util/zip/ZipFile->getInputStream(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream;")){            ZipFile zipFile = (ZipFile) dvmObject.getValue();            ZipEntry zipEntry = (ZipEntry) vaList.getObjectArg(0).getValue();            try {                InputStream inputStream = zipFile.getInputStream(zipEntry);                return vm.resolveClass("java/io/InputStream").newObject(inputStream);            } catch (IOException e) {                e.printStackTrace();                return null;            }        }        if (signature.equals("java/security/MessageDigest->digest()[B")){            MessageDigest md = (MessageDigest) dvmObject.getValue();            byte[] digest = md.digest();            return new ByteArray(vm, digest);        }        return super.callObjectMethodV(vm, dvmObject, signature, vaList);    }    @Override    public boolean callBooleanMethodV(BaseVM vm, DvmObject dvmObject, String signature, VaList vaList) {        if (signature.equals("java/lang/String->endsWith(Ljava/lang/String;)Z")){            String value = (String) dvmObject.getValue();            String suffix = (String) vaList.getObjectArg(0).getValue();            return value.endsWith(suffix);        }        return super.callBooleanMethodV(vm, dvmObject, signature, vaList);    }    @Override    public int callIntMethodV(BaseVM vm, DvmObject dvmObject, String signature, VaList vaList) {        if (signature.equals("java/io/InputStream->read([B)I")){            InputStream inputStream = (InputStream) dvmObject.getValue();            byte[] bytes = (byte[]) vaList.getObjectArg(0).getValue();            try {                int read = inputStream.read(bytes);                return read;            } catch (IOException e) {                e.printStackTrace();                return -1;            }        }        return super.callIntMethodV(vm, dvmObject, signature, vaList);    }    @Override    public void callVoidMethodV(BaseVM vm, DvmObject dvmObject, String signature, VaList vaList) {        if (signature.equals("java/security/MessageDigest->update([B)V")){            MessageDigest md = (MessageDigest) dvmObject.getValue();            byte[] bytes = (byte[]) vaList.getObjectArg(0).getValue();            md.update(bytes);            return;        }        super.callVoidMethodV(vm, dvmObject, signature, vaList);    }}

来源地址:https://blog.csdn.net/weixin_38927522/article/details/127892332

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯