Chapters

Hide chapters

Advanced Apple Debugging & Reverse Engineering

Fourth Edition · iOS 16, macOS 13.3 · Swift 5.8, Python 3 · Xcode 14

Section I: Beginning LLDB Commands

Section 1: 10 chapters
Show chapters Hide chapters

Section IV: Custom LLDB Commands

Section 4: 8 chapters
Show chapters Hide chapters

B. Appendix B: Python Environment Setup
Written by Walter Tyree

Heads up... You're reading this book for free, with parts of this chapter shown beyond this point as scrambled text.

If you’re actively looking for a Python editor for the Python-related chapters, here are some recommendations.

Getting Python

MacOS no longer ships with Python installed. However, if you open a terminal window and attempt to launch Python, the system will offer to download and install Apple’s preferred version along with the other command line developer tools. In Terminal, type python3, and your computer will either launch the interactive Python shell or present a dialog like the one below:

If, for some reason, you like to rm random things in Terminal and you need to reinstall Python, you can download Python from the official download page or using the homebrew package manager. Make sure to download the version of Python that matches the version packaged with LLDB. If you’re not sure which version to get, you can get the LLDB Python version through Terminal:

% lldb
(lldb) script import sys; print(sys.version)

You’ll see something like this:

3.9.6 (default, Mar 10 2023, 20:16:38)
[Clang 14.0.3 (clang-1403.0.22.14.1)]

This is from Xcode version 14.3. Your output may vary if you have a newer Xcode installed. You can ignore the Clang version there, as that’s not relevant. What’s relevant is the 3.9.6.

Don’t worry about the final part of the version number. As long as you have some version of Python 3, you’ll be fine. There are many breaking changes between versions 2 and 3.

Python Text Editors

The official Python website maintains a list of Python editors. According to my daughter, who’s studying CS at university (Hi, Kitty!), the cool Python developers who want a free editor use either Visual Studio Code (VS Code) or Vim.

Working With the LLDB Python Module

When working with Python, you’ll often import modules to execute code or classes within that module. When working with LLDB’s Python module, you’ll sometimes come across an import lldb somewhere in the script, usually right at the top.

% echo $0
% touch ~/.bash_profile
% touch ~/.zshrc
export PYTHONPATH="/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python:$PYTHONPATH"
% echo $PYTHONPATH
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2024 Kodeco Inc.

You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a Kodeco Personal Plan.

Unlock now