【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | DexPathList 中根据 File 加载 DexFile | loadDexFile 分析 )
文章目录
- 前言
- 一、根据 File 加载 DexFile
- 二、DexPathList.loadDexFile 函数分析
前言
上一篇博客 【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | DexPathList 构造函数分析 | makeDexElements 函数分析 ) 中 , 介绍了在 DexPathList 构造函数中调用了 makeDexElements 方法 , 在 makeDexElements 方法中执行了加载 dex 文件的操作 , 将加载后的 dex 文件封装在了 Element 实例对象中 , 并生成了 Element[] 数组 , 每个 dex 文件都对应 Element[] 数组 中的一个元素 ;
本篇博客中重点介绍 dex 文件加载的细节 ;
一、根据 File 加载 DexFile
在 DexPathList 中的 makeDexElements 方法中 , 调用了 loadDexFile 方法 , 根据 Dex 文件的 File 对象 , 创建了 DexFile 对象 ;
在 文件名称 以 .dex 后缀时 与 .apk / .jar / .zip 后缀进行不同的处理 ;
/*package*/ final class DexPathList {private static Element[] makeDexElements(ArrayList<File> files, File optimizedDirectory,ArrayList<IOException> suppressedExceptions) {ArrayList<Element> elements = new ArrayList<Element>();for (File file : files) {File zip = null;DexFile dex = null;String name = file.getName();if (name.endsWith(DEX_SUFFIX)) {// Raw dex file (not inside a zip/jar).try {dex = loadDexFile(file, optimizedDirectory);} catch (IOException ex) {}} else if (name.endsWith(APK_SUFFIX) || name.endsWith(JAR_SUFFIX)|| name.endsWith(ZIP_SUFFIX)) {zip = file;try {dex = loadDexFile(file, optimizedDirectory);} catch (IOException suppressed) {}}}} }
源码路径 : /libcore/dalvik/src/main/java/dalvik/system/DexPathList.java
二、DexPathList.loadDexFile 函数分析
在 DexPathList. loadDexFile 方法中 , 主要是调用了 DexFile.loadDex 方法 生成 DexFile 实例对象 ;
执行 DexFile.loadDex , 先调用了 optimizedPathFor 方法 , 根据 dex 文件路径 和 优化目录 生成一个相关的 优化 dex 文件路径 ;
/*package*/ final class DexPathList {/*** Constructs a {@code DexFile} instance, as appropriate depending* on whether {@code optimizedDirectory} is {@code null}.*/private static DexFile loadDexFile(File file, File optimizedDirectory)throws IOException {if (optimizedDirectory == null) {return new DexFile(file);} else {String optimizedPath = optimizedPathFor(file, optimizedDirectory);return DexFile.loadDex(file.getPath(), optimizedPath, 0);}} }源码路径 : /libcore/dalvik/src/main/java/dalvik/system/DexPathList.java
总结
以上是生活随笔为你收集整理的【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | DexPathList 中根据 File 加载 DexFile | loadDexFile 分析 )的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【Android 逆向】整体加固脱壳 (
- 下一篇: 【Android 逆向】整体加固脱壳 (