Xiangxiang's Personal Site

Machine Learning & Security Engineer
生命不息,折腾不止,留下一点活着的记录.

View on GitHub
5 October 2023

Android Packer & Dex Dumper

by xiangxiang

How Android packer works & Dump dex with custom Android rom

0 参考材料

1 Android Packer

Anti-Debugging

  1. Debug.isDebuggerConnected
  2. fork and ptrace
  3. process status /proc/{pid}/status
  4. hook system functions releted to debugging

Anti-Emulator

  1. inspecting specific system files (/proc/tty/drivers)
  2. checking the existence or values of particular system properties (init.svc.qemud)
  3. checking the existenc of hardware sensors

Anti-DBI

  1. /proc/{pid}/maps

Time Checking

  1. Calculating the time consumed for executing a specical task

System Library Hooking

  1. GOT/PLT hooking
  2. inline hooking
    • libart.so
    • libc.so
    • loblog.so

Dynamic Dex File Loading

  1. class loader
  2. DexFile class
  3. call methods in the DexPathList

Dynamic Dex Data Modification

  1. JNI_OnLoad
  2. ClassLinker::LoadClass

Dynamic Runtime Object Modification

  1. hook ClassLinker::LoadMethod to modify ArtMethod objects
  2. static initialization method of each app class to modify the relevant mirror:Class object

Dex Data Fragmentation

  1. release the protected Dex file’s class_data_items or code_items to separated memory regions

JNI Transformation

  1. VMP
  2. DEX2C

动态环境检测

System Property Checked,Value that Causes Exit
init.svc.gce_fs_monitor,running
init.svc.dempeventlog,running
init.svc.dumpipclog,running
init.svc.dumplogcat,running
init.svc.dumplogcat-efs,running
init.svc.filemon,running
ro.hardware.virtual_device,gce_x86
ro.kernel.androidboot.hardware,gce_x86
ro.hardware.virtual_device,gce_x86
ro.boot.hardware,gce_x86
ro.boot.selinux,disable
ro.factorytest,true OR 1 OR y
ro.kernel.android.checkjni,true OR 1 OR y
ro.hardware.virtual_device,vbox86
ro.kernel.androidboot.hardware,vbox86
ro.hardware,vbox86
ro.boot.hardware,vbox86
ro.build.product,google_sdk
ro.build.product,Droid4x
ro.build.product,sdk_x86
ro.build.product,sdk_google
ro.build.product,vbox86p
ro.product.manufacturer,Genymotion
ro.product.brand,generic
ro.product.brand,generic_x86
ro.product.device,generic
ro.product.device,generic_x86
ro.product.device,generic_x86_x64
ro.product.device,Droid4x
ro.product.device,vbox86p
ro.kernel.androidboot.hardware,goldfish
ro.hardware,goldfish
ro.boot.hardware,goldfish
ro.hardware.audio.primary,goldfish
ro.kernel.androidboot.hardware,ranchu
ro.hardware,ranchu
ro.boot.hardware,ranchu


# If any of these System Properties exist, the application exits
init.svc.vbox86-setup
qemu.sf.fake_camera
init.svc.goldfish-logcat
init.svc.goldfish-logcat
init.svc.qemud

Xposed检测

Checks if LIBXPOSED_ART.SO or XPOSEDBRIDGE.JAR exist in
/proc/self/maps

Tries to find either of the following two classes using the JNI
FindClass() method
○ XC_MethodHook: de/robv/android/xposed/XC_MethodHook
○ XposedBridge: de/robv/android/xposed/XposedBridge

2 源资源加密壳的原理(非VMP)

3 APP脱壳整体思路

4 APP脱壳具体实现

  1. 参考FartExt在ActivityThread中的handleBindApplication启动dump线程 -> 参考FartExt
  2. dump线程通过反射获取mCookie, 根据classLoader->pathList->dexElements->dexFile->mCookie -> 参考RDex
  3. 在framework层的DexFile类中添加Native函数dump供调用, dump作用就是将dex保存下来, 具体实现需要修改art/runtime/native/dalvik_system_DexFile.cc -> 参考Fart
tags: android packer dex