Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
U

unpacker

> 编程语言
Open source

基于ART主动调用的脱壳机

800 stars0 likes0 views
WebsiteGitHub

About

基于ART主动调用的脱壳机

Youpk

又一款基于ART的主动调用的脱壳机

原理

Youpk是一款针对Dex整体加固+各式各样的Dex抽取的脱壳机

基本流程如下:

  1. 从内存中dump DEX
  2. 构造完整调用链, 主动调用所有方法并dump CodeItem
  3. 合并 DEX, CodeItem

从内存中dump DEX

DEX文件在art虚拟机中使用DexFile对象表示, 而ClassLinker中引用了这些对象, 因此可以采用从ClassLinker中遍历DexFile对象并dump的方式来获取.

//unpacker.cc
std::list Unpacker::getDexFiles() {
  std::list dex_files;
  Thread* const self = Thread::Current();
  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
  ReaderMutexLock mu(self, *class_linker->DexLock());
  const std::list& dex_caches = class_linker->GetDexCachesData();
  for (auto it = dex_caches.begin(); it != dex_caches.end(); ++it) {
    ClassLinker::DexCacheData data = *it;
    const DexFile* dex_file = data.dex_file;
    dex_files.push_back(dex_file);
  }
  return dex_files;
}

另外, 为了避免dex做任何形式的优化影响dump下来的dex文件, 在dex2oat中设置 CompilerFilter 为仅验证

//dex2oat.cc
compiler_options_->SetCompilerFilter(CompilerFilter::kVerifyAtRuntime);

构造完整调用链, 主动调用所有方法

  1. 创建脱壳线程
…
  1. 在脱壳线程中遍历DexFile的所有ClassDef

    //unpacker.cc
    for (; class_idx NumClassDefs(); class_idx++) {
    
  2. 解析并初始化Class

    //unpacker.cc
    mirror::Class* klass = class_linker->ResolveType(*dex_file, dex_file->GetClassDef(class_idx).class_idx_, h_dex_cache, h_class_loader);
    StackHandleScope hs2(self);
    Handle h_class(hs2.NewHandle(klass));
    bool suc = class_linker->EnsureInitialized(self, h_class, true, true);
    
  3. 主动调用Class的所有Method, 并修改ArtMethod::Invoke使其强制走switch型解释器

…
  1. 在解释器中插桩, 在每条指令执行前设置回调
…
  1. 在回调中做针对性的CodeItem的dump, 这里仅仅是简单的示例了直接dump, 实际上, 针对某些厂商的抽取, 可以真正的执行几条指令等待CodeItem解密后再dump

    //unpacker.cc
    bool Unpacker::beforeInstructionExecute(Thread *self, ArtMethod *method, uint32_t dex_pc, int inst_count) {
      if (Unpacker::isFakeInvoke(self, method)) {
          Unpacker::dumpMethod(method);
        return true;
      }
      return false;
    }
    

合并 DEX, CodeItem

将dump下来的CodeItem填充到DEX的相应位置中即可. 主要是基于google dx工具修改.

参考链接

FUPK3: https://bbs.pediy.com/thread-246117.htm

FART: https://bbs.pediy.com/thread-252630.htm

刷机

  1. 仅支持pixel 1代
  2. 重启至bootloader: adb reboot bootloader
  3. 解压 Youpk_sailfish.zip 并双击 flash-all.bat

编译

脱壳机源码编译

  1. 下载android-7.1.2_r33完整源码
  2. 替换unpacker/android-7.1.2_r33
  3. 编译

修复工具编译

  1. IDEA导入dexfixer项目
  2. main class为 com.android.dx.unpacker.DexFixer

使用方法

  1. 该工具仅仅用来学习交流, 请勿用于非法用途, 否则后果自付!

  2. 配置待脱壳的app包名, 准确来讲是进程名称

    adb shell "echo cn.youlor.mydemo >> /data/local/tmp/unpacker.config"
    
  3. 如果apk没有整体加固, 未避免installd调用dex2oat优化, 需要在安装之前执行第2步

  4. 启动apk等待脱壳 每隔10秒将自动重新脱壳(已完全dump的dex将被忽略), 当日志打印unpack end时脱壳完成

  5. pull出dump文件, dump文件路径为 /data/data/包名/unpacker

    adb pull /data/data/cn.youlor.mydemo/unpacker
    
  6. 调用修复工具 dexfixer.jar, 两个参数, 第一个为dump文件目录(必须为有效路径), 第二个为重组后的DEX目录(不存在将会创建)

    java -jar dexfixer.jar /path/to/unpacker /path/to/output
    

适用场景

  1. 整体加固
  2. 抽取:
    • nop占坑型(类似某加密)
    • naitve化, 在 `` 中解密(类似早期阿里)
    • goto解密型(类似新版某加密, najia): https://bbs.pediy.com/thread-259448.htm

常见问题

  1. dump中途退出或卡死,重新启动进程,再次等待脱壳即可
  2. 当前仅支持被壳保护的dex, 不支持App动态加载的dex/jar

Issues· 1 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++unpacker

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言