debugserver 动态调试

栏目: IOS · 发布时间: 5年前

内容简介:动态调试是指将程序运行起来,通过下断点、打印等方式,查看参数、返回值、函数调用流程等。通过

动态调试是指将程序运行起来,通过下断点、打印等方式,查看参数、返回值、函数调用流程等。

一、Xcode动态调试原理

Xcode 内置调试器 lldb 将输入的指令通过 debugserver 传输给App,App执行指令后将反馈信息再通过 debugserver 传送给 lldb

debugserver 动态调试
  • 关于GCC、LLVM、GDB、LLDB

    Xcode
    Xcode
    
  • debugserver 一开始存放在电脑中的 Xcode 里面(注意版本号)

    • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/9.1/DeveloperDiskImage.dmg/usr/bin/debugserver
  • Xcode 识别到手机设备时,会将 debugserver 安装到手机上

    • /Developer/usr/bin/debugserver
  • Xcode 动态调试局限性

    • 一般情况下,只能调试通过 Xcode 安装的App

二、动态调试任意App

通过 Xcode 安装到手机上的 debugserver 缺少一定权限,只能调试通过 Xcode 安装的APP。若想调试任意APP,则需要对 debugserver 做一些改动。 手机上的 /Developer 目录是只读的,无法直接对 /Developer/usr/bin/debugserver 文件修改,需要先把其复制到电脑。

0x01 debugserver瘦身

  • 默认情况 debugserver 是支持全部 arm 架构

    $ lipo -info debugserver
    
    Architectures in the fat file: debugserver are: armv7 armv7s arm64 
    复制代码
  • 减小 debugserver 的大小,只支持当前手机架构

    $ lipo debugserver -thin arm64 -output debugserver_64
    $ lipo -info debugserver_64 
    
    Non-fat file: debugserver_64 is architecture: arm64
    复制代码

0x02 给debugserver新增权限

  • 获取 debugserver 初始权限

    $ codesign -d --entitlements - debugserver
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.backboardd.debugapplications</key>
        <true/>
        <key>com.apple.backboardd.launchapplications</key>
        <true/>
        <key>com.apple.diagnosticd.diagnostic</key>
        <true/>
        <key>com.apple.frontboard.debugapplications</key>
        <true/>
        <key>com.apple.frontboard.launchapplications</key>
        <true/>
        <key>com.apple.security.network.client</key>
        <true/>
        <key>com.apple.security.network.server</key>
        <true/>
        <key>com.apple.springboard.debugapplications</key>
        <true/>
        <key>run-unsigned-code</key>
        <true/>
        <key>seatbelt-profiles</key>
        <array>
    	    <string>debugserver</string>
        </array>
    </dict>
    </plist>
    复制代码
  • 将上面获取的原始权限保存到 debugserver.entitlements 中,并添加两个调试相关权限

debugserver 动态调试

0x03 对debugserver重签名

  • codesign

    # 签名权限
    $ codesign -f -s - --entitlements debugserver.entitlements debugserver_64
    
    debugserver_64: replacing existing signature
    
    # 或简写为
    $ codesign -fs- --entitlements debugserver.entitlements debugserver_64
    复制代码
  • ldid

    # 获取debugserver之前那的权限(可到当前目录下查看debugserver.entitlements内容)
    $ ldid -e debugserver > debugserver.entitlements
    
    # 添加两个权限
    
    # 重签名
    $ ldid -Sdebugserver.entitlements debugserver
    
    debugserver_64: replacing existing signature
    复制代码

任选上述两种方法的一种重签名方式,将签好权限的 debugsever_64 重命名为 debugserver ,复制到手机的 /usr/bin/debugserver ,便于找到 debugserver 指令。

  • ssh 登录到手机给 debugserver 执行权限

    iPhone:~ root# chmod +x /usr/bin/debugserver
    复制代码

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Build Your Own Web Site the Right Way Using HTML & CSS

Build Your Own Web Site the Right Way Using HTML & CSS

Ian Lloyd / SitePoint / 2006-05-02 / USD 29.95

Build Your Own Website The Right Way Using HTML & CSS teaches web development from scratch, without assuming any previous knowledge of HTML, CSS or web development techniques. This book introduces you......一起来看看 《Build Your Own Web Site the Right Way Using HTML & CSS》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

MD5 加密
MD5 加密

MD5 加密工具