|
| 1 | +# insert-dylib (Rust) |
| 2 | + |
| 3 | +A Rust rewrite of `insert_dylib`: injects a new `LC_LOAD_DYLIB` (or `LC_LOAD_WEAK_DYLIB`) load command into Mach-O binaries. |
| 4 | + |
| 5 | +> This tool modifies binary files directly. Always keep backups and validate outputs before distribution. |
| 6 | +
|
| 7 | +## Platform Support |
| 8 | + |
| 9 | +- Supported platform: **macOS aarch64 (Apple Silicon)** |
| 10 | +- Unsupported targets fail at compile time by design. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- Inject `LC_LOAD_DYLIB` or `LC_LOAD_WEAK_DYLIB` |
| 15 | +- Works with thin Mach-O and fat binaries |
| 16 | +- Optional in-place patching or writing to a new output file |
| 17 | +- Optional code-signature load command stripping (with related `__LINKEDIT` adjustments) |
| 18 | +- Interactive safety prompts, with `--all-yes` for non-interactive runs |
| 19 | + |
| 20 | +## Build |
| 21 | + |
| 22 | +```bash |
| 23 | +cargo build --release --target aarch64-apple-darwin |
| 24 | +``` |
| 25 | + |
| 26 | +The binary will be at: |
| 27 | + |
| 28 | +- `target/aarch64-apple-darwin/release/insert-dylib` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +```bash |
| 33 | +insert-dylib [options] <dylib_path> <binary_path> [new_binary_path] |
| 34 | +``` |
| 35 | + |
| 36 | +If `new_binary_path` is omitted (and `--inplace` is not used), output defaults to: |
| 37 | + |
| 38 | +- `<binary_path>_patched` |
| 39 | + |
| 40 | +### Options |
| 41 | + |
| 42 | +- `--inplace` patch the input binary in place |
| 43 | +- `--weak` use `LC_LOAD_WEAK_DYLIB` instead of `LC_LOAD_DYLIB` |
| 44 | +- `--overwrite` allow overwriting output without prompt |
| 45 | +- `--strip-codesig` force removing `LC_CODE_SIGNATURE` when possible |
| 46 | +- `--no-strip-codesig` never remove `LC_CODE_SIGNATURE` |
| 47 | +- `--all-yes` auto-answer `yes` to all interactive prompts |
| 48 | + |
| 49 | +## Examples |
| 50 | + |
| 51 | +Inject a dylib and write to default output: |
| 52 | + |
| 53 | +```bash |
| 54 | +insert-dylib @executable_path/libHook.dylib MyApp |
| 55 | +``` |
| 56 | + |
| 57 | +Inject weak dylib in place: |
| 58 | + |
| 59 | +```bash |
| 60 | +insert-dylib --weak --inplace @rpath/libHook.dylib MyApp |
| 61 | +``` |
| 62 | + |
| 63 | +Force code-signature stripping and overwrite output: |
| 64 | + |
| 65 | +```bash |
| 66 | +insert-dylib --strip-codesig --overwrite @loader_path/libHook.dylib MyApp MyApp.patched |
| 67 | +``` |
| 68 | + |
| 69 | +## Code Signing Note |
| 70 | + |
| 71 | +If `LC_CODE_SIGNATURE` is removed, the binary's signature is invalidated. Re-sign the patched binary if needed: |
| 72 | + |
| 73 | +```bash |
| 74 | +codesign --force --sign - MyApp.patched |
| 75 | +``` |
| 76 | + |
| 77 | +## CI and Release |
| 78 | + |
| 79 | +- CI workflow: `.github/workflows/ci.yml` |
| 80 | + - Runs `fmt`, `check`, `clippy`, and `test` on **macOS aarch64**. |
| 81 | +- Release workflow: `.github/workflows/release.yml` |
| 82 | + - Triggered when pushing tags like `v1.0.0` |
| 83 | + - Builds **macOS aarch64** release binaries and publishes GitHub Release assets. |
| 84 | + |
| 85 | +Create a release tag: |
| 86 | + |
| 87 | +```bash |
| 88 | +git tag v0.1.0 |
| 89 | +git push origin v0.1.0 |
| 90 | +``` |
| 91 | + |
| 92 | +## Publish to crates.io |
| 93 | + |
| 94 | +Before publishing: |
| 95 | + |
| 96 | +```bash |
| 97 | +cargo package |
| 98 | +cargo publish |
| 99 | +``` |
| 100 | + |
| 101 | +## Legal / Safety |
| 102 | + |
| 103 | +Use this tool only on binaries you are authorized to modify. |
0 commit comments