欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | DexPathList 中根据 File 加载 DexFile | loadDexFile 分析 )

发布时间:2025/6/17 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【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 分析 )的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。