4.4 Dex 加载流程Native层分析
Java层 Dex加载流程 网上 有很多帖子 都写得很不错 如果感兴趣的话 可以 找几篇看看
大概描述:
DexClassLoader ->
父类BaseDexClassLoader的构造->
new DexPaseList->
makeDexElements->将dex分割 可能有多个Dex(返回一个 Elements[]),赋值给成员变量
LoadDexFile->
DexFile->
OpenDexFile->返回mCookie(DexOrJar)
OpenDexFileNative->
最终调用 OpenDexFileNative-> 进行dex解析
下面一起分析一下 4.4 Dvm虚拟机中 openDexFileNativie
到底做了什么
路径/aosp/dalvik/vm/mk文件/编译 最终 生成 libdvm.so
找到 OpenDexFileNative-> 函数

先判断是否有无文件 没有 进行 加载 调用 dvmRawDexFileOpen







继续跟进dexFileParse-> 三个参数
1,odex的地址
2,文件长度
3,flag




具体函数 如下




读取成功 以后 将 pDexOrJar->fileName 进行赋值
将加载以后的mCookie通过调用 addToDexFileTable 添加到 Table中


到这openDexFileNative 函数 跑完了
最后 返回的就是mCookie
其实返回是一个 DexOrJar

如果 java层 用到某一个类的话 会调用findClass
从mCookie 进行加载
在代码中 有一个 *gDvm变量,简单说明一下
* gDvm(主要保存了 程序 在 dvm虚拟机的一些数据,
是全局变量,每一个 dvm上面的程序 创建的时候 必须初始化的变量
,也会存放 dex的一些数据 进行缓存 来达到 优化的作用 )
如果对 逆向,脱壳,新技术 感兴趣的 同学 可以加 我Q群 欢迎各位能人志士 一起讨论
欢迎加入故事,群聊号码:773642813
珍惜
2018年10月08日10:32:45
-----------------------------------------------------------------------------------------------------------------------------------------