日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發布時間:2025/6/17 Android 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | DexFile.java 对应的 dalvik_system_DexFile.cc 本地函数分析 ) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 一、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 函數 createCookieWithDirectBuffercreateCookieWithArray 函數定義在 /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_createCookieWithDirectBufferDexFile_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 本地函数分析 )的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。