A Rust rewrite of insert_dylib: injects a new LC_LOAD_DYLIB (or LC_LOAD_WEAK_DYLIB) load command into Mach-O binaries.
This tool modifies binary files directly. Always keep backups and validate outputs before distribution.
- Host platforms: macOS, Linux, and Windows
- Supported inputs: Mach-O thin and fat binaries
- The implementation uses portable
stdfile I/O only; no host-OS-specific APIs are required.
- Inject
LC_LOAD_DYLIBorLC_LOAD_WEAK_DYLIB - Works with thin Mach-O and fat binaries
- Optional in-place patching or writing to a new output file
- Optional code-signature load command stripping (with related
__LINKEDITadjustments) - Interactive safety prompts, with
--all-yesfor non-interactive runs
cargo build --releaseThe binary will be at:
- macOS / Linux:
target/release/insert-dylib - Windows:
target/release/insert-dylib.exe
insert-dylib [options] <dylib_path> <binary_path> [new_binary_path]If new_binary_path is omitted (and --inplace is not used), output defaults to:
<binary_path>_patched
--inplacepatch the input binary in place--weakuseLC_LOAD_WEAK_DYLIBinstead ofLC_LOAD_DYLIB--overwriteallow overwriting output without prompt--strip-codesigforce removingLC_CODE_SIGNATUREwhen possible--no-strip-codesignever removeLC_CODE_SIGNATURE--all-yesauto-answeryesto all interactive prompts--iosrewrite dylib Mach-O platform markers frommacOStoiOS(requires--dylib-path)--dylib-path <path>local dylib file path used by--iosfor Mach-O platform rewrite
More case studies are in examples/.
Inject a dylib and write to default output:
insert-dylib @executable_path/libHook.dylib MyAppInject weak dylib in place:
insert-dylib --weak --inplace @rpath/libHook.dylib MyAppForce code-signature stripping and overwrite output:
insert-dylib --strip-codesig --overwrite @loader_path/libHook.dylib MyApp MyApp.patchedInject iOS install name while rewriting a local dylib file to iOS platform metadata:
insert-dylib --ios --dylib-path libarcaea_function.dylib @executable_path/Frameworks/libarcaea_function.dylib Arc-mobileIf LC_CODE_SIGNATURE is removed, the binary's signature is invalidated. Re-sign the patched binary if needed. The codesign command itself is only available on macOS:
codesign --force --sign - MyApp.patchedUse this tool only on binaries you are authorized to modify.