Skip to content

hookforge/insert-dylib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

insert-dylib (Rust)

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.

Platform Support

  • Host platforms: macOS, Linux, and Windows
  • Supported inputs: Mach-O thin and fat binaries
  • The implementation uses portable std file I/O only; no host-OS-specific APIs are required.

Features

  • Inject LC_LOAD_DYLIB or LC_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 __LINKEDIT adjustments)
  • Interactive safety prompts, with --all-yes for non-interactive runs

Build

cargo build --release

The binary will be at:

  • macOS / Linux: target/release/insert-dylib
  • Windows: target/release/insert-dylib.exe

Usage

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

Options

  • --inplace patch the input binary in place
  • --weak use LC_LOAD_WEAK_DYLIB instead of LC_LOAD_DYLIB
  • --overwrite allow overwriting output without prompt
  • --strip-codesig force removing LC_CODE_SIGNATURE when possible
  • --no-strip-codesig never remove LC_CODE_SIGNATURE
  • --all-yes auto-answer yes to all interactive prompts
  • --ios rewrite dylib Mach-O platform markers from macOS to iOS (requires --dylib-path)
  • --dylib-path <path> local dylib file path used by --ios for Mach-O platform rewrite

Examples

More case studies are in examples/.

Inject a dylib and write to default output:

insert-dylib @executable_path/libHook.dylib MyApp

Inject weak dylib in place:

insert-dylib --weak --inplace @rpath/libHook.dylib MyApp

Force code-signature stripping and overwrite output:

insert-dylib --strip-codesig --overwrite @loader_path/libHook.dylib MyApp MyApp.patched

Inject 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-mobile

Code Signing Note

If 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.patched

Legal / Safety

Use this tool only on binaries you are authorized to modify.

About

Mach-O insert dylib

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages