Advanced Apple Debugging & Reverse Engineering
Derek Selander
Copyright ©2017 Razeware LLC.
Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without
prior written permission of the copyright owner.
Notice of Liability
This book and all corresponding materials (such as source code) are provided on an
“as is” basis, without warranty of any kind, express of implied, including but not
limited to the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in
the software.
Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.
Advanced Apple Debugging
raywenderlich.com 2
Dedications
"I would like to thank my wife, Brittany, for all her love and
support while I silently wept in the fetal position trying to get this
book out the door"
— Derek Selander
Advanced Apple Debugging
raywenderlich.com 3
About the author
Derek Selander is the author of this book. His interest with
debugging grew when he started exploring how to make (the now
somewhat obsolete) Xcode plugins and iOS tweaks on his
jailbroken phone, both of which required exploring and
augmenting programs with no source available. In his free time,
he enjoys pickup soccer, guitar, and playing with his two doggies,
Jake & Squid.
About the editors
Chris Belanger is the editor of this book. Chris Belanger is the
Book Team Lead and Lead Editor for raywenderlich.com. If there
are words to wrangle or a paragraph to ponder, he‘s on the case.
When he kicks back, you can usually find Chris with guitar in hand,
looking for the nearest beach, or exploring the lakes and rivers in
his part of the world in a canoe.
Matt Galloway is a software engineer with a passion for
excellence. He stumbled into iOS programming when it first was a
thing, and has never looked back. When not coding, he likes to
brew his own beer.
Darren Ferguson is the final pass editor of this book. He is a
Software Developer, with a passion for mobile development, for a
leading systems integration provider based out of Northern
Virginia in the D.C. metro area. When he's not coding, you can find
him enjoying life with his wife and daughter trying to travel as
much as possible.
Advanced Apple Debugging
raywenderlich.com 4
Table of Contents: Overview
Introduction 14................................................................................
Section I: Beginning LLDB Commands 19.........................
Chapter 1: Getting Started 20...........................................
Chapter 2: Help & Apropos 32..........................................
Chapter 3: Attaching with LLDB 36....................................
Chapter 4: Stopping in Code 42........................................
Chapter 5: Expression 55....................................................
Chapter 6: Thread, Frame & Stepping Around 68.........
Chapter 7: Image 78............................................................
Chapter 8: Persisting & Customizing Commands 92.......
Chapter 9: Regex Commands 97.......................................
Section II: Understanding Assembly 104..........................
Chapter 10: Assembly Register Calling
Convention 105......................................................................
Chapter 11: Assembly & Memory 122.............................
Chapter 12: Assembly and the Stack 136.......................
Section III: Low Level 156.................................................
Chapter 13: Hello, Ptrace 157...........................................
Chapter 14: Dynamic Frameworks 166............................
Chapter 15: Hooking & Executing Code with
dlopen & dlsym 180.............................................................
Advanced Apple Debugging
raywenderlich.com 5