【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 逆向】整体加固脱壳 (