Substrate - Powerful Code Injection Platform
Note
Version 0.1.5 is the official stable release; earlier versions are not stable.
A complete Rust rewrite of Cydia Substrate and And64InlineHook, providing powerful function hooking capabilities for Android and Linux platforms across multiple architectures.
Features
-
✅ Multi-Architecture Support
- x86/x86-64 (Intel/AMD 32-bit and 64-bit)
- ARMv7 (32-bit ARM with Thumb/Thumb-2)
- ARM64/AArch64 (64-bit ARM)
-
✅ Complete Function Hooking
- Inline function hooking with automatic trampoline generation
- PC-relative instruction relocation
- Symbol resolution from ELF binaries
- Library base address lookup
-
✅ Dual API
- C-compatible FFI for use in C/C++ projects
- Safe, idiomatic Rust API
- Drop-in replacement for Cydia Substrate
-
✅ Production Ready
- Zero unsafe behavior leaks
- Comprehensive error handling
- Memory-safe by default
- Thoroughly tested across architectures
Installation
Add this to your Cargo.toml:
[]
= "0.1.5"
Or for C/C++ projects, download the prebuilt library from releases.
Quick Start
Rust Usage
use c_void;
use ;
static mut LEVEL_BONUS: bool = false;
static mut ORIG_RACE_UPDATE: *mut c_void = null_mut;
unsafe extern "C"
C/C++ Usage
bool levelbonus = false;
void ;
void
void ;
void* ;
void
static void
Complete Examples
Example 1: Hooking with Symbol Name
use c_void;
use ;
static mut ORIG_MALLOC: *mut c_void = null_mut;
unsafe extern "C"
Example 2: Hooking Game Functions (Android/IL2CPP)
use ;
use MSHookFunction;
use c_void;
static mut OLD_UPDATE: *mut c_void = null_mut;
unsafe extern "C"
Example 3: Using Helper Macros (C-style)
use *;
// Convert hex string to offset
Example 4: Architecture-Specific Hooking
use substrate;
API Reference
Core Functions
MSHookFunction
void ;
Hook a function at the given address. Compatible with original Cydia Substrate.
Parameters:
symbol: Target function address to hookreplace: Your hook function addressresult: Pointer to store original function (trampoline), can be NULL
A64HookFunction
void ;
ARM64-specific hook function (alias to MSHookFunction on ARM64).
Utility Functions
findLibrary
uintptr_t ;
Find the base address of a loaded library.
Example:
uintptr_t base = ;
getAbsoluteAddress
uintptr_t ;
Calculate absolute address from library name and offset.
Example:
uintptr_t addr = ;
isLibraryLoaded
bool ;
Check if a library is currently loaded.
Example:
if
string2Offset
uintptr_t ;
Convert hex string (e.g., "0x123456") to numeric offset.
Example:
uintptr_t offset = ;
hook
void ;
Universal hook function that dispatches to the correct implementation.
Rust API
// Safe wrapper for hooking
pub unsafe
Platform Support
| Platform | x86 | x86-64 | ARMv7 | ARM64 | Status |
|---|---|---|---|---|---|
| Linux | ✅ | ✅ | ✅ | ✅ | Full |
| Android | ✅ | ✅ | ✅ | ✅ | Full |
| macOS | ❌ | ⚠️ | ❌ | ⚠️ | Untested |
Building
# Debug build
# Release build (optimized)
# With debug logging
# Cross-compile for Android ARM64
# Cross-compile for Android ARMv7
Advanced Usage
Custom Error Handling
use SubstrateError;
match hook_function
Enable Debug Logging
use ;
// Enable debug output
set_debug;
// Check if debug is enabled
if is_debug
Memory Safety
The library uses RAII and safe abstractions internally, but the public API requires unsafe due to the nature of function hooking:
unsafe
Technical Details
Architecture-Specific Implementation
- x86/x86-64: Full instruction decoder (HDE64), handles RIP-relative addressing
- ARMv7: Separate ARM and Thumb mode handlers, PC-relative instruction relocation
- ARM64: Complete instruction fixing for all PC-relative types (B, BL, CBZ, LDR, ADR, ADRP, etc.)
Trampoline Generation
The library automatically:
- Disassembles instructions at the target
- Relocates PC-relative instructions
- Creates a trampoline with original code
- Installs jump to hook function
- Returns pointer to trampoline (original function)
Memory Protection
Automatically handles:
- Memory page protection (mprotect)
- Instruction cache clearing
- Alignment requirements
- Permission restoration
License
This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0).
Original Cydia Substrate: Copyright (C) 2008-2011 Jay Freeman (saurik) And64InlineHook: Copyright (C) 2018 Rprop (MIT License) Rust Implementation: 2024
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- Jay Freeman (saurik) - Original Cydia Substrate
- Rprop - And64InlineHook implementation
- Rodroid Mods
FAQ
Q: Is this compatible with the original Cydia Substrate? A: Yes! It's a drop-in replacement with the same C API.
Q: Can I use this for game modding? A: Yes, it's commonly used for Android game modding (IL2CPP, Unity, Unreal Engine).
Q: Does it work on rooted devices only? A: No, it works on non-rooted devices within your own app's process.
Q: What about anti-cheat detection? A: This is a hooking library. Detection avoidance is your responsibility.
Q: Performance impact? A: Minimal - only affects hooked functions, optimized trampolines.