[go: up one dir, main page]

Skip to content

An improved nm + Objective-C & Swift class-dump

Notifications You must be signed in to change notification settings

launchdaemon/dsdump

 
 

Repository files navigation

dsdump

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

Works great on Objective-C classes img

... and Swift types img

man

dsdump(1)                 BSD General Commands Manual                dsdump(1)

NAME
     dsdump -- An improved nm + objc/swift class-dump

SYNOPSIS
     dsdump [option...] <mach-o-file>

DESCRIPTION
     Provides an "nm-improved" experience when working with Mach-O executa-
     bles. dsdump has 3 "primary" modes: Symbol table (--sym), Objective-C
     (--objc), and Swift (--swift, -s). Omitting all of these options will
     default to the sym mode.

OPTIONS
     -c, --color
             Adds color to output

     -O, --opcs
             Dump the DYLD opcodes used to bind external symbols at load time

     -f, --filter FilterWord
             Specify classes to filter by (case insensitive, can be used mul-
             tiple times)

     -a, --arch architecture
             Specify the arichtecture if file is FAT. Understands x86_64h,
             x86_64, arm64, arm64e

     -u, --undefined
             Only display undefined (externally referenced) symbols or classes

     -U, --defined
             Only display defined (internally implemented) symbols or classes

     -v, --verbose
             Specifies the verbosity level. The -v option can be used multiple
             times, while the long argument sets the exact level 0-5. Kind of
             like codesign(1)'s verbosity that everyone complains about...

     --objc  Dump the Objective-C classes

     --swift
             Dump the Swift type descriptors (classes, structs, enums)

     -s      Sets mode to Swift mode and verbosity to level 4

     -h, --help
             Print out this beautiful, helpful document

EXAMPLES
     List ObjC internal/external classes referenced/implemented by vmmap:
           dsdump --objc $(which vmmap)

     List the Objective-C external classes called by vmmap:
           dsdump --objc $(which vmmap) -u

     List the Objective-C internal classes implemented by vmmap:
           dsdump --objc $(which vmmap) -U

     Perform an Objective-C "class-dump" in color of vmmap
           dsdump --objc $(which vmmap) -U -vvvc

     Thoroughly dump the Swift content in color in the Console app
           dsdump --swift
           /Applications/Utilities/Console.app/Contents/MacOS/Console -cvvvv

VERBOSITY
     dsdump can output a range of verbosity between the 3 different modes
     (--sym, --swift, --objc). The verbosity level can be set by the long form
     (--verbose=3) or by specifying a count via short form (-vvv). The break-
     down of these levels are shown below:

     --sym:
           0. Print symbol
           1. 0 + library path or Mach-O section
           2. 1 + fullpath to library
           3. 2 + nlist struct output
           4. Same as 3... for now
           5. Same as 3... for now

     --swift:
           0. List swift types
           1. 0 + Parent classes
           2. 1 + Protocols
           3. 2 + Swift type dump
           4. 3 + Extended type dump, ObjC bridge methods
           5. 4 + Commenting in methods

     --objc:
           0. List Objective-C classes
           1. 0 + Parent classes & library basename for external
           2. 1 + Fullpath to libraries for external + protocols
           3. 2 + Objective-C class dump
           4. 3 + Print properties
           5. 4 + Print ivars & offsets

ENVIRONMENT
     DSCOLOR Enables color. Alternatively, use -c

     ARCH <arch> Specify the architecture if inspecting a FAT executable,
     Alternatively use --arch

SEE ALSO
     nm(1), objdump(1), vmmap(1)

BUGS
     There's a situation where occassionally dsdump will think the parent
     class is a RO_ROOT where it will in fact won't be. I'll print this out
     for now so I can hunt it down

     ARM64e still needs some luv, especially on the Swift side, especially
     with Protocols... and not crashing

AUTHORS
     Derek Selander @LOLgrep

Darwin                         December 8, 2019                         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 :|

# cd into the dsdump repo
cd dsdump/

# make a directory called swift-source, yes, name it exactly that
mkdir swift-source

cd swift-source/

# clone the Swift repository into swift-source
git clone https://github.com/apple/swift.git

# checkout 
git checkout 75670c17272a993ed798cee7e31c20590e94118b

# Use the Swift update helper script to grab everything else 
./swift/utils/update-checkout --clone

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 SHA1 matches below if you're paranoid.

Compiled SHA1

SHA1: 17149fce3a73bd2614d21901ec791ef64815370a

Credits

About

An improved nm + Objective-C & Swift class-dump

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C++ 40.3%
  • C++ 22.9%
  • Objective-C 20.9%
  • C 14.0%
  • Roff 1.3%
  • Swift 0.6%