Leanpub Header

Skip to main content

Practical Binary Analysis with Capstone & Keystone

The Complete Guide to Binary Analysis, Disassembly, and Assembly

This book is 100% completeLast updated on 2026-07-07

Master the art of binary analysis with Practical Binary Analysis with Capstone & Keystone. Learn how to disassemble, assemble, analyze, and rewrite machine code while building real-world tools for reverse engineering, security research, and automation.

Minimum price

$25.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

This is a comprehensive, production-quality guide to two of the most important tools in binary analysis: the Capstone disassembler engine and the Keystone assembler engine. Written for readers ranging from curious beginners to seasoned reverse engineers, it covers theoretical foundations, practical implementation, API usage across multiple programming languages, and real-world applications including malware analysis, exploit development, compiler tooling, and automated binary rewriting. Every chapter includes complete, executable source code examples in C, Python, Rust, Go, Java, and C#, along with case studies, architecture diagrams, comparison tables, best practices, and troubleshooting guidance. By the end of this book, you will be able to build your own disassemblers, assemblers, binary patchers, shellcode analyzers, and reverse engineering automation tools from scratch.

Share this book

Bundle

Bundles that include this book

Author

About the Author

Steve T. Publications

Steve T. is a cybersecurity leader, researcher, and engineer with more than 20 years of experience across application security, infrastructure security, vulnerability management, software development, and secure engineering practices. Having built his career alongside the growth of the modern internet, he has worked through multiple generations of technology, evolving security threats, and changing development methodologies.

He is currently part of the advanced research organization at a leading cybersecurity company, where he focuses on emerging threats, security innovation, and the practical application of research. His work involves investigating new attack techniques, evaluating emerging technologies, conducting deep technical analysis, and helping organizations better understand and manage complex security risks.

In addition to his research responsibilities, Steve leads a team of senior engineers and subject matter experts who create technical books, training programs, and educational resources for security professionals. Through this work, he helps engineers, developers, architects, and security practitioners strengthen their skills and build more secure systems.

Steve's technical expertise spans software development, reverse engineering, web application security, penetration testing, security architecture, incident response, vulnerability research, operating system internals, and secure software development. His ability to analyze systems at both the source code and binary levels enables him to bridge the worlds of software engineering, security research, and practical defense.

Over the course of his career, Steve has worked with organizations across a wide range of industries, helping them identify, assess, and remediate security weaknesses in critical applications and infrastructure. He is recognized for combining deep technical expertise with a pragmatic approach to security, focusing on solutions that are effective, sustainable, and aligned with business goals.

Through his work in research, engineering, leadership, and education, Steve continues to contribute to the advancement of cybersecurity and the development of secure, resilient technology systems.

Contents

Table of Contents

The Complete Guide to Binary Analysis, Disassembly, and Assembly

Introduction

  1. Why Binary Analysis Matters
  2. The Reversing Trilogy
  3. What Makes These Engines Special
  4. What You Will Learn
  5. Who This Book Is For
  6. How to Use This Book
  7. Conventions Used in This Book
  8. Prerequisites
  9. Getting Started

Chapter 1: The World of Machine Code

  1. What Is Machine Code?
  2. Instruction Set Architectures Explained
  3. From Source to Binary: The Compilation Pipeline
  4. The Role of Assemblers and Disassemblers
  5. Why Binary Analysis Matters Today
  6. The Gap That Capstone and Keystone Fill
  7. Exercises

Chapter 2: History and Ecosystem of Binary Analysis Tools

  1. The Evolution of Disassembly Tools
  2. IDA Pro, Ghidra, radare2, and Friends: A Comparison
  3. Enter Capstone: A New Approach to Disassembly
  4. Keystone and the Assembler Gap
  5. The Shared DNA: Design Philosophy and Architecture
  6. The Ecosystem Today
  7. Why This Book Focuses on These Two Engines
  8. Exercises

Chapter 3: Capstone Engine Deep Dive – Architecture and Design

  1. Capstone Internal Architecture
  2. Supported Architectures at a Glance
  3. The Disassembly Pipeline: From Bytes to Instructions
  4. Key Data Structures
  5. Configuration Options and Mode Flags
  6. Architecture-Specific Design Details
  7. The Auto-Sync System
  8. Exercises

Chapter 4: Installing and Configuring Capstone

  1. Building from Source on Linux, macOS, and Windows
  2. Package Manager Installation Paths
  3. Language Bindings: Python, Rust, Go, Java, C#
  4. Configuration and Build Flags
  5. Verifying Your Installation
  6. Common Installation Issues and Solutions
  7. Exercises

Chapter 5: Capstone API – From Basics to Advanced Usage

  1. Initializing and Shutting Down the Engine
  2. Simple Disassembly in Every Language
  3. Extracting Detailed Instruction Information
  4. Iterative vs. Block-Based Disassembly
  5. Error Handling and Edge Cases
  6. Performance Tips
  7. Exercises

Chapter 6: Keystone Engine Deep Dive – Architecture and Design

  1. Keystone Internal Architecture
  2. The Assembly Pipeline: From Mnemonics to Bytes
  3. Supported Architectures and Modes
  4. Instruction Encoding Strategies
  5. Configuration Options and Constraints
  6. Comparison: Capstone vs. Keystone Design
  7. Exercises

Chapter 7: Installing and Configuring Keystone

  1. Building Keystone from Source
  2. Package Manager Paths
  3. Language Bindings Setup
  4. Configuration and Build Flags
  5. Verifying Your Installation
  6. Common Installation Issues and Solutions
  7. Exercises

Chapter 8: Keystone API – From Basics to Advanced Usage

  1. Initializing and Shutting Down the Engine
  2. Simple Assembly in Every Language
  3. Handling Errors and Invalid Instructions
  4. Advanced Encoding Options
  5. Error Handling Strategies
  6. Exercises

Chapter 9: Capstone and Keystone Together – Round-Trip Analysis

  1. The Power of Combined Disassembly and Assembly
  2. Building a Round-Trip Verification Tool
  3. Detecting Semantic Differences After Round-Trip
  4. Cross-Reference Analysis Patterns
  5. Practical Examples in Multiple Languages
  6. Exercises

Chapter 10: Reverse Engineering Workflows

  1. Static Binary Analysis Pipelines
  2. Integrating with Dynamic Analysis Tools
  3. Supporting Decompilation Efforts
  4. Control Flow Graph Construction
  5. Automating Reverse Engineering Tasks
  6. Exercises

Chapter 11: Malware Analysis and Threat Intelligence

  1. Analyzing Malicious Binaries at the Instruction Level
  2. Shellcode Detection and Analysis
  3. Obfuscation and Anti-Analysis Techniques
  4. Building Automated Triage Tools
  5. Case Study: Real-World Malware Sample
  6. Exercises

Chapter 12: Exploit Development and Binary Patching

  1. Shellcode Analysis with Capstone
  2. ROP Chain Construction and Validation
  3. Binary Patching Fundamentals
  4. Instruction Replacement and Size-Neutral Patches
  5. Hot-Patching in Production
  6. Exercises

Chapter 13: Compiler Tooling, Emulation, and Debugging

  1. Compiler Backend Integration
  2. Just-In-Time Compilation Support
  3. Binary Instrumentation Frameworks
  4. Emulation and Simulation
  5. Debugging Tool Integration
  6. Exercises

Chapter 14: Advanced Topics – Performance, Security, and Automation

  1. Performance Benchmarking and Optimization
  2. Memory Safety and Security Considerations
  3. Testing Strategies for Binary Analysis Code
  4. CI/CD Integration and Automation
  5. Future Directions and Emerging Trends
  6. Exercises

Conclusion

  1. What You Have Gained
  2. The Bigger Picture
  3. What Comes Next
  4. A Final Thought

References

Appendix A: Complete API Reference

  1. Capstone C API
  2. Keystone C API

Appendix B: Supported Architectures and Modes

  1. Capstone Architectures
  2. Keystone Architectures

Appendix C: Instruction Encoding Examples

  1. x86-64 Common Instructions
  2. ARM Common Instructions

Appendix D: Glossary

Appendix E: Further Learning Resources

  1. Official Documentation
  2. Source Code Repositories
  3. Community Resources
  4. Recommended Books
  5. Conference Presentations
  6. Online Tools

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub