suzuke / Il2CppHookScripts

基于 frida 的 libil2cpp.so 运行时解析脚本

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Il2cppHook

基于 frida 的 libil2cpp.so 运行时解析脚本

Features

  • 解析 Unity 的方法 / 类 / 字段
  • 解析 运行时 方法参数
  • 常用函数的 (批量)断点(参数值 / 返回值 查看)
  • 更方便的查看以及调用函数

Usage

$ git clone https://github.com/axhlzy/Il2CppHookScripts.git
$ cd Il2cppHook/
$ npm install

$ frida -U --no-pause -f com.xxx.xxx -l ../_Ufunc.js
OR
$ frida -FU -l ../_Ufunc.js

API

Contents
  1. 基础函数
  2. 断点函数
  3. 常用函数Hook的封装
  4. Module/Thread相关
  5. lf 系列 (list fields ... )
  6. 其他

Examples

  • i() == list_images 不带参数即列出所有的 Images

    list_images

  • c() == list_classes 列出所有的 Classes list_classes(ptr/strFilter)

    list_classes

  • m() == list_methods 列出所有的 Methods

    list_methods

  • f() == list_fields 列出所有的 Fields

    list_fields

  • findClass(className) 查找类,一般配合 m() 使用 , m(findClass('className')) === m('className')

    findClass

  • findMethod 新版 / find_method 旧版

    findMethod

  • printExp 作为findMethod的补充版,方便查找函数

    • 第一个参数是查找的函数名 findMethod
    • 第二个参数标识是否全局查找(默认在常用的函数中查找,因为是遍历嘛,这样可以有效提高查找速度) findMethod
  • getApkInfo 获取 apk 信息

    getApkInfo

  • callFunction 函数调用

    callFunction

  • showAsm 基于frida.Instruction结合unity函数信息的反汇编

    showAsm

    showAsmSP

  • showMethodInfo / MethodToShow 查看MethodInfo信息(后者多用在findMethod)showAddressInfo alias showMethodInfo(addressToMethod)

    showMethodInfo

  • B breakPoint 断点函数类

    • B ('ClassName') === B(findClass('ClassName')),不会重复添加已添加的Method,不带参数即断点所有常用的方法

      breakPoint_B

    • BF 等价于原来的 B("filterStr") ,断点包含指定字符串的方法

      breakPoint_BF

    • b ('Method_Pointer') / b('MethodInfo_Pointer')

      breakPoint_b

    • d / D : d === detachAll and d(ptr) === detach(ptr) / D() === detachAll + clear list cache

    • bp('filterMethodName') 断点包含 指定的函数名(filterMethodName) 的所有函数

  • n/nn nop Function

    • n / nn : n(ptr) === nop function and nn() === cancel nop function

      nop

  • breakInline InlineHook

    breakInline

  • breakWithArgs 带参数断点

    breakWithArgs

  • breakWithStack 带堆栈断点

    breakWithStack

  • dlopen : 提供一个早期的函数hook点

    dlopen

  • watch/watchDisabled MemoryAccessMonitor的简单封装(arm32易崩)

    watch

  • StalkerTracePath StalkerTrace封装,分析调用顺序

    StalkerTracePath

  • StalkerTraceEvent StalkerTraceEvent,分析事件

    StalkerTraceEvent

  • HookOnPointerClick :Hook 点击事件

    HookOnPointerClick

  • HookDebugLog : Hook Debug.Log

    HookDebugLog

  • HookSetActive : Hook SetActive

    HookSetActive

  • HookPlayerPrefs : Hook PlayerPrefs

    HookPlayerPrefs

  • B_Button : Hook Button

    B_Button

    B_Button

  • PrintHierarchy : 打印当前场景的层级结构

    • 注意:arm64的地址用双引号包裹起来,arm32直接传递即可 PrintHierarchy
  • listModule (filterName: string) => void

    listModule

  • listModules (moduleName: string, printItems?: number) => void

    listModules

  • listThreads (maxCountThreads?: number) => void

    listThreads

  • findExport (exportName: string, moduleName?: string, callback?: (exp: ModuleExportDetails) => void) => void

    findExport

  • findImport (moduleName: string, importName?: string) => void

    findImport

  • lfs 详见 Il2cppHook\agent\bridge\fix\parseFields.ts,需要一个参数实例地址,B()中有

    lfs

  • HttpGet

    httpGet

...

Commit

  • 文件结构按照Unity类继承关系实现
  • 文件命名规则以及结构
    • 一个类文件夹下一个include.ts包含当前类文件以及该类子类文件夹的include
    • api.ts
      • 用作解析常用函数 (exp: ptr(Il2Cpp.Api.Application._Quit) )
      • 函数的命名使用 '_' + 具体的函数名,多参数使用后缀 '_x' 结尾i (exp: Il2Cpp.Api.Application._Quit_1)
      • api class 命名为 类名 + 'API' (exp: System_ValueType_API)
    • class.ts
      • NativePointer转换为Class的实现 (把ptr当成class来解析)
      • 包含一些(静态)字段,(静态)方法,以及方便调用的一些函数封装
      • this.handle 存贮当前 ptr,可以是 实例指针也可以是类指针 (多数情况使用实例指针)
    • export.ts
      • 主要用作拓展类的一些导出方法
  • TODO 按照这个文件结构可以拓展到整个UnityAPI (提供了 generateApi / generateClass / generateFieldEnum 方便的拓展类,生成的东西不太准,需要稍微修改点点)

Tips

  • 由于JS特性的问题,再arm64下的指针大小是8字节,所以arm64下控制台传参指针值的时候建议使用string类型 存在计算精度的问题(js命令行传参最大值为Number.MAX_SAFE_INTEGER = 9007199254740991,直接给值超出范围导致精度丢失) use ptr("0x12345678") instead of ptr(0x12345678) 这部分发现的比较晚后续很多东西都没有做好优化
  • 我这里用的环境: frida==15.2.2 | frida-tools==10.5.4 , 测试机 :piex 4 原生android 11
    1. 确认手机端server与电脑端frida版本一致,如果你的版本不一致概率性出问题
    2. 已确认高版本的 frida-tools 在使用老版 Ufunc.js (ts版不受影响)会出问题,所以建议直接使用 10.5.4 版本
  • 建议使用真机,尽量不在x86模拟器中使用,x86中找不到对应so,其次frida对于模拟器的兼容性也并不好

About

基于 frida 的 libil2cpp.so 运行时解析脚本

License:MIT License


Languages

Language:JavaScript 68.7%Language:TypeScript 31.3%