文章

尝试学习frida

尝试学习frida

尝试直接用frida看看能不能调试

1
frida -U -f com.leleketang.SchoolFantasy

预想之中, 所以得先反调试…啊, 好难啊,,360加固框架到底怎么反调试的??查看了一篇360加固分析的博客, 望而却步.. #2026年4月21日 先玩会儿吧.. 还是先弄懂frida对native层的调试接口吧. Interceptor是拦截器, 引出的问题是:

  • 插哪儿
  • 插完要做什么 学习这个博客的一个脚本
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    function hook_dlopen(soName = '') {
      Interceptor.attach(Module.findExportByName(null, "android_dlopen_ext"), {
          onEnter: function(args) {
              var pathptr = args[0];
              if (pathptr) {
                  var path = ptr(pathptr).readCString();
                  console.log("Loading: " + path);
                  if (path.indexOf(soName) >= 0) {
                      console.log("Already loading: " + soName);
                      // hook_system_property_get();
                  }
              }
          }
      });
    }
    setImmediate(hook_dlopen, "libmsaoaidsec.so");
    

    一看这是老版本的frida, 这个坑我踩过. 最新版api应该如下写:Module.getGlobalExportByName(“android_dlopen_ext”)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    function hook_dlopen(soName = '') {
      Interceptor.attach(Module.getGlobalExportByName("android_dlopen_ext"), {
          onEnter: function(args) {
              var pathptr = args[0];
              if (pathptr) {
                  var path = ptr(pathptr).readCString();
                  console.log("Loading: " + path);
                  if (path.indexOf(soName) >= 0) {
                      console.log("Already loading: " + soName);
                      // hook_system_property_get();
                  }
              }
          }
      });
    }
    setImmediate(hook_dlopen, "libmsaoaidsec.so");
    

    真的看着好陌生的知识啊, 但是当初自学java也是这样一路摸索过来的, 我相信我自己能掌握这门技术. 我想看看android_dlopen_ext函数参数, 去看看对应的源码.

    1
    2
    3
    4
    5
    
    __attribute__((__weak__))
    void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo) {
    const void* caller_addr = __builtin_return_address(0);
    return __loader_android_dlopen_ext(filename, flag, extinfo, caller_addr);
    }
    

    问一下AI吧 https://www.qianwen.com/share/chat/a27f1b7eb6aa4dbea72d3c1b832e4d26 所以, 联系上面的脚本, 可以得知: attach只能是附加到对应的函数, 而onEnter里就取用了第一个参数args[0]: 加载路径. Module.getGlobalExportByName("android_dlopen_ext")的作用是找到这个函数在内存中的具体位置? 问AI核对一下.. 确实如此.. 接着的参数就是hook后的回调函数.好多未知的知识啊,疑问太多了.. 去看具体的Frida文档吧. 一句一句学! 不然学得模模糊糊的, 没有一点进展..

To be more productive, we highly recommend using our TypeScript bindings. This means you get code completion, type checking, inline docs, refactoring tools, etc.

  • 为了更高效, 我们强烈推荐使用我们的TypeScript配套. 这意味着你获得了代码补全, 类型检查, 内联文档, 重构工具等.

原来我一开始就错了, 对js有着偏爱情怀, 但是我决定改变, 我接受不了一点js的无类型判定! 我先去试试ts咋用的. 查看到一篇博客, 感觉像是打开了新大陆.. 确实, 自己的脚本对于大部分app应该是通用的, 重复编写浪费事件, 确实应该变成ide中可调用的模块.. 并且我电脑上也安装了node.js, 配置起来环境应该不是问题. visual studio code 的 自动补全就像糊弄鬼一样, 补全了, 但没有完全补全.. 博客里的ide是pycharm, 我不太熟悉, damn!! 才发现后面几句话就说了, 有模板库..

Clone this repo to get started.

那还说啥了, Git 启动!!

1
git clone https://github.com/oleavr/frida-agent-example.git

然后我尝试用IDEA打开..打开后, idea会自动提示: 发现package.json, 是否需要npm安装. 然后就没有报错了..随便一写, 嘿, 还真能主动提示了.. 真棒, 今天又学了新东西, 还可以利用ts的模块功能, 不用重复写脚本咯..接着看文档吧.

Table of contents

  1. Runtime information运行时信息
    1. FridaFrida
    2. Script脚本
  2. Process, Thread, Module and Memory进程, 线程, 模块, 内存
    1. Thread线程
    2. Process进程
    3. Module模块
    4. ModuleMap模块映射
    5. Memory内存
    6. MemoryAccessMonitor内存访问监控器
    7. CModuleC模块
    8. RustModuleRust模块
    9. ApiResolverAPI解释器
    10. DebugSymbol调试符号
    11. Kernel内核
  3. Data Types, Function and Callback数据类型, 函数, 回调
    1. Int6464位整型
    2. UInt64无符号64位整型
    3. NativePointerNative层指针
    4. ArrayBuffer队列缓冲
    5. NativeFunctionNative函数
    6. NativeCallbackNative回调
    7. SystemFunction符号函数
  4. Network网络
    1. Socket套接字
    2. SocketListener套接字监听器
    3. SocketConnection套接字连接
  5. File and Stream文件和流
    1. File文件
    2. IOStream输入输入流
    3. InputStream输入流
    4. OutputStream输出流
    5. UnixInputStreamUnix系统的输入流
    6. UnixOutputStreamUnix系统的输出流
    7. Win32InputStreamWin32系统的输入流
    8. Win32OutputStreamWin32系统的输出流
  6. Database数据库
    1. SqliteStatement数据库状态
  7. Instrumentation工具
    1. Interceptor拦截器
    2. Stalker追踪器
    3. ObjC对象C
    4. Java对象Java
  8. CPU InstructionCPU工具
    1. X86Writerx86写入器
    2. X86Relocatorx86重定位器
    3. x86 enum typesx86枚举类型
    4. ArmWriterArm写入器
    5. ArmRelocatorArm重定位器
    6. ThumbWriter小写入器
    7. ThumbRelocator小重定位器
    8. ARM enum typesArm枚举类型
  9. Other其他
本文由作者按照 CC BY 4.0 进行授权