文章目录

  • 一、DexFile 对应的 dalvik_system_DexFile.cc 中的 Native 方法
    • 1、dalvik_system_DexFile.cc 的 DexFile_createCookieWithDirectBuffer 函数
    • 2、dalvik_system_DexFile.cc 的 DexFile_createCookieWithArray 函数
  • 二、dalvik_system_DexFile.cc 的 CreateSingleDexFileCookie 函数

一、DexFile 对应的 dalvik_system_DexFile.cc 中的 Native 方法


在上一篇博客 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | DexFile 构造函数及相关调用函数 | Android 源码中查找 native 函数 ) 中 , 分析了 DexFile 构造函数 , 以及 makeInMemoryDexElements 函数 ; 并查找了 DexFile 中的 native 函数 createCookieWithDirectBuffer 和 createCookieWithArray 函数定义在 /art/runtime/native/dalvik_system_DexFile.cc 中 ;

1、dalvik_system_DexFile.cc 的 DexFile_createCookieWithDirectBuffer 函数

在 DexFile_createCookieWithDirectBuffer 函数中 , 调用的 memcpy 方法中的 dex_mem_map->Begin() 就是 dex 文件的起始地址 , length 是 dex 文件的长度 , 这里可以将内存中的 dex 数据导出 ;

  // ★ 此处的 dex_mem_map->Begin() 就是 dex 文件的起始地址 , length 是 dex 文件的长度memcpy(dex_mem_map->Begin(), base_address, length);
// DexFile 中 createCookieWithDirectBuffer 函数对应的 C++ 函数
static jobject DexFile_createCookieWithDirectBuffer(JNIEnv* env,jclass,jobject buffer,jint start,jint end) {uint8_t* base_address = reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(buffer));if (base_address == nullptr) {ScopedObjectAccess soa(env);ThrowWrappedIOException("dexFileBuffer not direct");return 0;}std::unique_ptr<MemMap> dex_mem_map(AllocateDexMemoryMap(env, start, end));if (dex_mem_map == nullptr) {DCHECK(Thread::Current()->IsExceptionPending());return 0;}size_t length = static_cast<size_t>(end - start);// ★ 此处的 dex_mem_map->Begin() 就是 dex 文件的起始地址 , length 是 dex 文件的长度memcpy(dex_mem_map->Begin(), base_address, length);// ★ 核心跳转return CreateSingleDexFileCookie(env, std::move(dex_mem_map));
}

源码路径 : /art/runtime/native/dalvik_system_DexFile.cc

2、dalvik_system_DexFile.cc 的 DexFile_createCookieWithArray 函数

DexFile_createCookieWithDirectBuffer 和 DexFile_createCookieWithArray 222 个 native 方法 , 在最后返回时都调用了 CreateSingleDexFileCookie 方法 ;

// DexFile 中 createCookieWithArray 函数对应的 C++ 函数
static jobject DexFile_createCookieWithArray(JNIEnv* env,jclass,jbyteArray buffer,jint start,jint end) {std::unique_ptr<MemMap> dex_mem_map(AllocateDexMemoryMap(env, start, end));if (dex_mem_map == nullptr) {DCHECK(Thread::Current()->IsExceptionPending());return 0;}auto destination = reinterpret_cast<jbyte*>(dex_mem_map.get()->Begin());env->GetByteArrayRegion(buffer, start, end - start, destination);// ★ 核心跳转return CreateSingleDexFileCookie(env, std::move(dex_mem_map));
}

源码路径 : /art/runtime/native/dalvik_system_DexFile.cc

二、dalvik_system_DexFile.cc 的 CreateSingleDexFileCookie 函数


在该方法中 , 主要创建 dex_file 实例 , 然后将该实例对象返回到 Java 层 ; 传入的参数是 CreateDexFile(env, std::move(data)) , 下面开始分析该函数 ;

dalvik_system_DexFile.cc 的 CreateSingleDexFileCookie 函数源码 :

static jobject CreateSingleDexFileCookie(JNIEnv* env, std::unique_ptr<MemMap> data) {// ★ 创建 dex_file std::unique_ptr<const DexFile> dex_file(CreateDexFile(env, std::move(data)));if (dex_file.get() == nullptr) {DCHECK(env->ExceptionCheck());return nullptr;}std::vector<std::unique_ptr<const DexFile>> dex_files;dex_files.push_back(std::move(dex_file));return ConvertDexFilesToJavaArray(env, nullptr, dex_files);
}

源码路径 : /art/runtime/native/dalvik_system_DexFile.cc#CreateSingleDexFileCookie

【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | DexFile.java 对应的 dalvik_system_DexFile.cc 本地函数分析 )相关推荐

  1. 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | dex_file.cc 中创建 DexFile 实例对象的相关函数分析 )

    文章目录 前言 一.dalvik_system_DexFile.cc#CreateDexFile 函数分析 二.dex_file.cc#DexFile::Open 函数分析 三.dex_file.cc ...

  2. 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | DexFile 构造函数及相关调用函数 | Android 源码中查找 native 函数 )

    文章目录 一.DexFile 构造函数 二.DexFile.openInMemoryDexFile 函数 三.Android 源码中查找 native 函数 一.DexFile 构造函数 上一篇博客 ...

  3. 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | BaseDexClassLoader 构造函数 | DexPathList 构造函数及后续调用 )

    文章目录 一.BaseDexClassLoader 构造函数 二.DexPathList 构造函数 三.DexPathList.makeInMemoryDexElements 函数 一.BaseDex ...

  4. 【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | 查找 DexFile 对应的C代码 | dalvik_system_DexFile.cpp 分析 )

    文章目录 前言 一.查找 DexFile 对应的 C++ 代码 1.根据 Native 文件命名惯例查找 C++ 代码 2.根据方法名查找 二.dalvik_system_DexFile.cpp 源码 ...

  5. 【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | DexFile loadDexFile 函数 | 构造函数 | openDexFile 函数 )

    文章目录 前言 一.DexFile.loadDexFile 函数分析 二.DexFile 构造函数分析 三.DexFile.openDexFile 函数分析 前言 上一篇博客 [Android 逆向] ...

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

    文章目录 前言 一.根据 File 加载 DexFile 二.DexPathList.loadDexFile 函数分析 前言 上一篇博客 [Android 逆向]整体加固脱壳 ( DexClassLo ...

  7. 【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | DexPathList 构造函数分析 | makeDexElements 函数分析 )

    文章目录 前言 一.DexPathList 构造函数分析 二.DexPathList.makeDexElements 函数分析 三.Element 类分析 前言 上一篇博客 [Android 逆向]整 ...

  8. 【Android 逆向】整体加固脱壳 ( 脱壳点简介 | 修改系统源码进行脱壳 )

    文章目录 一.脱壳点简介 二.修改系统源码进行脱壳 一.脱壳点简介 在上一篇博客 [Android 逆向]整体加固脱壳 ( DEX 优化流程分析 | DexPrepare.cpp 中 rewriteD ...

  9. 【Android 逆向】整体加固脱壳 ( DEX 优化流程分析 | dvmDexFileOpenPartial | dexFileParse | 脱壳点 | 获取 dex 文件在内存中的首地址 )

    文章目录 前言 一.DexPrepare.cpp 中 rewriteDex() 方法分析 二.DvmDex.cpp 中 dvmDexFileOpenPartial() 方法分析 ( 脱壳点 ) 三.D ...

最新文章

  1. 济南python工资一般多少钱-济南Python+人工智能
  2. 27.4. /etc/bandwidthd.conf
  3. canvas--初级
  4. idea如何把包变为模块_让我们将包变成模块系统!
  5. [Axis2与Eclipse整合开发Web Service系列之一] 生成Web Service Client(将WSDl 转化成 Java代码)
  6. Atitit 软件程序的定义 软件广义定义 程序代码,文档 ,数据 方法,规则, 狭义定义 软件=程序+数据+文档 软件(英文:Software)是一系列按照特定顺序组织的计算机数据和指
  7. 让Excel 只显示有限行和列
  8. python方法怎么调用_python函数怎么调用自身?
  9. “烧”不起原创欲减少成本投入,奈飞还能稳坐流媒体龙头宝座么?
  10. 【设计模式】适配器模式:如何巧妙地过滤游戏中的敏感词
  11. QT作为设备接入阿里云平台
  12. Python基础(六):字符串、元组、列表习题
  13. Android 方向感应器实现指南针
  14. 神经科学探索脑第二十二章
  15. 前端使用xlsx、file-saver实现自定义excel格式导出(列宽、字体、边框、行高)
  16. ios 计算两个时间相差秒数_iOS NSDate时间换算
  17. 欧标IEC62056 兰吉尔关口电表无线抄表数据采集方案
  18. 2022年全球市场机器视觉频闪仪总体规模、主要生产商、主要地区、产品和应用细分研究报告
  19. android 获取当前位置
  20. 【ArcGIS自定义脚本工具】利用聚合方法批量生成分辨率降低版本的栅格

热门文章

  1. pl/sql command window 初步接触
  2. 通过checkbox选择以逗号拼接删除字符串
  3. Unity3d Http Get请求
  4. 开启Windows8里面的Hyper-V虚拟机功能
  5. legend3---3、lavarel页面post请求错误之后跳转
  6. Android Service学习之本地服务
  7. win10+ubuntu14.04双系统硬盘安装教程
  8. 【BZOJ1123】 [POI2008]BLO (tarjan)
  9. 【原】高清显示屏原理及设计方案
  10. 线段树、二叉堆以及离散化入门