Skip to content

nzaar9/magiskboot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

magiskboot — Cross-Platform Android Boot Image Tool

A pure Rust reimplementation of magiskboot from Magisk by topjohnwu.

Runs natively on macOS, Linux, and Windows — no Android emulator or ADB required.

Why?

The original magiskboot is built for Android (ARM/x86) and requires pushing files to a running AVD to patch ramdisks. This fork lets you do all the patching directly on your host machine, which is faster and simpler for AVD rooting workflows.

Building

# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Build
cd magiskboot
cargo build --release

# Binary is at target/release/magiskboot

Usage

magiskboot <action> [args...]

Commands

Command Description
unpack [-n] [-h] <bootimg> Unpack boot image to components. -n skips decompression, -h dumps header file
repack [-n] <bootimg> [outimg] Repack components into boot image. -n skips recompression
verify <bootimg> Verify AVB 1.0 signature
sign <bootimg> [name] [cert] [key] Sign with AVB 1.0 signature (embedded verity keys used by default)
extract <payload.bin> [partition] [outfile] Extract partition from OTA payload
hexpatch <file> <from> <to> Search and replace hex patterns
cpio <archive> [commands...] Manipulate CPIO archives in-place
dtb <file> <print|test|patch> Operate on device tree blobs
split [-n] <file> Split kernel+dtb image
sha1 <file> Print SHA1 checksum
compress[=format] <infile> [outfile] Compress file (gzip, xz, lzma, bzip2, lz4, lz4_legacy, lz4_lg)
decompress <infile> [outfile] Auto-detect format and decompress
cleanup Remove unpacked boot image files

CPIO subcommands

test                       Return Magisk patching status flags
exists <entry>             Return 0 if entry exists
ls [-r] [path]             List entries
add <mode> <entry> <file>  Add file to archive
mkdir <mode> <dir>         Create directory
ln <entry> <target>        Create symlink
rm [-r] <entry>            Remove entry
mv <from> <to>             Rename entry
extract [entry] [dest]     Extract entry or all entries
patch                      Remove verity/encryption from fstab entries
backup <orig>              Create backup of original ramdisk
restore                    Restore ramdisk from backup

Example: Patch an AVD Ramdisk on Your Host

# 1. Decompress the ramdisk
magiskboot decompress ramdisk.img ramdisk.cpio

# 2. Compress magisk binaries with XZ
magiskboot compress=xz magisk32 magisk32.xz
magiskboot compress=xz magisk64 magisk64.xz

# 3. Patch the CPIO archive
magiskboot cpio ramdisk.cpio \
  "mkdir 0750 overlay.d" \
  "mkdir 0750 overlay.d/sbin" \
  "add 0750 init magiskinit" \
  "add 0644 overlay.d/sbin/magisk32.xz magisk32.xz" \
  "add 0644 overlay.d/sbin/magisk64.xz magisk64.xz" \
  "patch" \
  "backup ramdisk.cpio.orig" \
  "mkdir 000 .backup" \
  "add 000 .backup/.magisk config"

# 4. Recompress with original format
magiskboot compress=lz4_legacy ramdisk.cpio ramdiskpatched4AVD.img

# 5. Replace the original ramdisk with the patched one
cp ramdiskpatched4AVD.img /path/to/avd/ramdisk.img

Modules

All functionality is ported from the upstream Magisk source:

Module Source Description
format.rs magiskboot.hpp, bootimg.cpp Magic byte detection for all boot/compression formats
compress.rs compress.rs Encode/decode: gzip, xz, lzma, bzip2, lz4 frame, lz4 legacy, lz4 lg
cpio.rs cpio.rs CPIO newc archive manipulation with all Magisk subcommands
patch.rs patch.rs Verity/encryption pattern removal, hex patching
bootimg.rs bootimg.cpp, bootimg.hpp Boot image parsing/repacking (v0–v4, vendor v3/v4, MTK, DHTB, ChromeOS)
sign.rs sign.rs AVB 1.0 signing/verification (RSA, ECDSA P-256/P-384)
dtb.rs dtb.rs Device tree blob print/test/patch
payload.rs payload.rs OTA payload.bin partition extraction

License

GPL-3.0 — same as Magisk.

Credits

About

Cross-platform magiskboot in pure Rust — Android boot image and ramdisk manipulation tool

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages