class-dump

  • class-dump
    • 一句话描述:用于处理Objective-CMach-O文件信息的命令行工具,可以导出类的定义、分组和协议。
      • command-line utility for examining the Objective-C segment of Mach-O files
    • 说明
      • otool -ov导出的信息是一样的
        • 但是显示为Objective-C定义,更易读
    • 原理
      • 利用了Objective-C语言的运行时的特性
        • 将存储在Mach-O文件中的头文件信息提取出来,并生成对应的.h文件
    • 用途
      • 查看闭源的应用frameworksbundles
        • 查看其中的头文件信息
      • 对比一个 APP 不同版本之间的接口变化
        • 通过导出不同版本的库的头文件的对比看出来
      • 对一些私有frameworks做些有趣的试验
    • 资料

下载

用法举例

  • class-dump AppKit
    • class-dump /System/Library/Frameworks/AppKit.framework
  • class-dump UIKit
    • class-dump /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/UIKit.framework
  • class-dump UIKit and all the frameworks it uses
    • class-dump /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/UIKit.framework -r --sdk-ios 4.3
  • class-dump UIKit (and all the frameworks it uses) from developer tools that have been installed in /Dev42 instead of /Developer
    • class-dump /Dev42/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/UIKit.framework -r --sdk-root /Dev42/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk

实际使用举例

之前从WebDriverAgent的源码中看到很多头文件的头部都有:Generated by class-dump

举例:

refer/WebDriverAgent/PrivateHeaders/XCTest/XCTestDriver.h

//
//     Generated by class-dump 3.5 (64 bit).
//
//     class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard.
//

-》说明这些文件都是通过class-dump从库文件中导出生成的。

help帮助语法

class-dump 3.5 (64 bit)
Usage: class-dump [options] <mach-o-file>

  where options are:
    -a             show instance variable offsets
    -A             show implementation addresses
    --arch <arch>  choose a specific architecture from a universal binary (ppc, ppc64, i386, x86_64)
    -C <regex>     only display classes matching regular expression
    -f <str>       find string in method name
    -H             generate header files in current directory, or directory specified with -o
    -I             sort classes, categories, and protocols by inheritance (overrides -s)
    -o <dir>       output directory used for -H
    -r             recursively expand frameworks and fixed VM shared libraries
    -s             sort classes and categories by name
    -S             sort methods by name
    -t             suppress header in output, for testing
    --list-arches  list the arches in the file, then exit
    --sdk-ios      specify iOS SDK version (will look in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS<version>.sdk
    --sdk-mac      specify Mac OS X version (will look in /Developer/SDKs/MacOSX<version>.sdk
    --sdk-root     specify the full SDK root path (or use --sdk-ios/--sdk-mac for a shortcut)

results matching ""

    No results matching ""