项目作者: DerekSelander

项目描述 :
An improved nm + Objective-C & Swift class-dump
高级语言: Objective-C++
项目地址: git://github.com/DerekSelander/dsdump.git
创建时间: 2019-03-10T03:10:41Z
项目社区:https://github.com/DerekSelander/dsdump

开源协议:

下载


NOTE: around ~2021 Apple introduced new binding opcodes which I haven’t gotten around to updating yet for dsdump. This results in bad output for objc class dumps.
I recommend you check out @blacktop‘s ipsw instead

dsdump

An improved nm + objc/swift class-dump (writeup)

Works great on Objective-C classes
img

… and Swift types
img

man

  1. dsdump(1) BSD General Commands Manual dsdump(1)
  2. NAME
  3. dsdump -- An improved nm + objc/swift class-dump
  4. SYNOPSIS
  5. dsdump [option...] <mach-o-file>
  6. DESCRIPTION
  7. Provides an "nm-improved" experience when working with Mach-O executa-
  8. bles. dsdump has 3 "primary" modes: Symbol table (--sym), Objective-C
  9. (--objc), and Swift (--swift, -s). Omitting all of these options will
  10. default to the Swift mode.
  11. OPTIONS
  12. -c, --color
  13. Adds color to output
  14. -d, --demangle
  15. Demangle Swift and C++ symbols in print symbol mode
  16. -l, --library
  17. Instead of dumping symbols, search all procs for library
  18. -O, --opcs
  19. Dump the DYLD opcodes used to bind external symbols at load time
  20. -f, --filter FilterWord
  21. Specify classes to filter by (case insensitive, can be used mul-
  22. tiple times)
  23. -a, --arch architecture
  24. Specify the arichtecture if file is FAT. Understands x86_64h,
  25. x86_64, arm64, arm64e
  26. -u, --undefined
  27. Only display undefined (externally referenced) symbols or classes
  28. -U, --defined
  29. Only display defined (internally implemented) symbols or classes
  30. -v, --verbose
  31. Specifies the verbosity level. The -v option can be used multiple
  32. times, while the long argument sets the exact level 0-5. Kind of
  33. like codesign(1)'s verbosity that everyone complains about...
  34. --objc Dump the Objective-C classes
  35. -o Sets mode to Objective-C mode and verbosity to level 4
  36. --swift
  37. Dump the Swift type descriptors (classes, structs, enums)
  38. -s Sets mode to Swift mode and verbosity to level 4
  39. -h, --help
  40. Print out this beautiful, helpful document
  41. EXAMPLES
  42. List ObjC internal/external classes referenced/implemented by vmmap:
  43. dsdump --objc $(which vmmap)
  44. List all alive processes that have the MobileDevice loaded
  45. sudo dsdump -l /S*/L*/P*/MobileDevice.framework/MobileDevice
  46. List the Objective-C external classes called by vmmap:
  47. dsdump --objc $(which vmmap) -u
  48. List the Objective-C internal classes implemented by vmmap:
  49. dsdump --objc $(which vmmap) -U
  50. Perform an Objective-C "class-dump" in color of vmmap
  51. dsdump --objc $(which vmmap) -U -vvvc
  52. Thoroughly dump the Swift content in color in the Console app
  53. dsdump --swift
  54. /Applications/Utilities/Console.app/Contents/MacOS/Console -cvvvv
  55. VERBOSITY
  56. dsdump can output a range of verbosity between the 3 different modes
  57. (--sym, --swift, --objc). The verbosity level can be set by the long form
  58. (--verbose=3) or by specifying a count via short form (-vvv). The break-
  59. down of these levels are shown below:
  60. --sym:
  61. 0. Print symbol
  62. 1. 0 + library path or Mach-O section
  63. 2. 1 + fullpath to library
  64. 3. 2 + nlist struct output
  65. 4. Same as 3... for now
  66. 5. Same as 3... for now
  67. --swift:
  68. 0. List swift types
  69. 1. 0 + Parent classes
  70. 2. 1 + Protocols
  71. 3. 2 + Swift type dump
  72. 4. 3 + Extended type dump, ObjC bridge methods
  73. 5. 4 + Commenting in methods
  74. --objc:
  75. 0. List Objective-C classes
  76. 1. 0 + Parent classes & library basename for external
  77. 2. 1 + Fullpath to libraries for external + protocols
  78. 3. 2 + Objective-C class dump
  79. 4. 3 + Print properties
  80. 5. 4 + Print ivars & offsets
  81. ENVIRONMENT
  82. DSCOLOR Enables color. Alternatively, use -c
  83. ARCH <arch> Specify the architecture if inspecting a FAT executable,
  84. Alternatively use --arch
  85. SEE ALSO
  86. nm(1), objdump(1), vmmap(1)
  87. BUGS
  88. There's a situation where occassionally dsdump will think the parent
  89. class is a RO_ROOT where it will in fact won't be. I'll print this out
  90. for now so I can hunt it down
  91. ARM64e still needs some luv, especially on the Swift side, especially
  92. with Protocols... and not crashing
  93. AUTHORS
  94. Derek Selander @LOLgrep
  95. Darwin March 26, 2020 Darwin

Compiling

Compiling this will be a bit of a pain in the butt on your end. You’ll need to clone the Swift language in the same directory. Swift can’t be a submodule to this repo since some of their git cloning scripts won’t work :|

  1. # cd into the dsdump repo
  2. cd dsdump/
  3. # make a directory called swift-source, yes, name it exactly that
  4. mkdir swift-source
  5. cd swift-source/
  6. # clone the Swift repository into swift-source
  7. git clone https://github.com/apple/swift.git
  8. # checkout
  9. cd swift
  10. git checkout 75670c17272a993ed798cee7e31c20590e94118b
  11. # Use the Swift update helper script to grab everything else
  12. ./swift/utils/update-checkout --clone-with-ssh --tag swift-5.1.4-RELEASE

Comment out any remaining problematic code after a build, remove methods in Metadata.h as needed (i.e. problematic ARC bridging code on line 700)

I’ve included the libSwiftDemangling.a static lib that I built into dsdump/dsdump. If you want to build entirely from Swift source, you’ll need to build this yourself. Otherwise you should be good to go to build dsdump via Xcode.

Alternatively, you can skip all of this by simply grabbing the compiled dsdump version in the compiled directory found here. Make sure the SHA256 matches below if you’re paranoid.

Compiled SHA256

  1. SHA256: 83eebd025b43b58a486235e1bec70a3239995be409605e3ff19bdae07adff917

Credits

TODO list for v1

  • Full ARM64e support
  • M1 support
  • Crashes
  • iOS 15/Monterey support
  • In process support (TODO TODO guess that means a libdsdump.a)
    • Basic dsc listing with options to dlopen from cmdline
  • header files