gdylib

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 7 Imported by: 1

README

gdylib

Module providing adding following load commands:

  • LC_LOAD_DYLIB
  • LC_LOAD_WEAK_DYLIB
  • LC_RPATH

Adding loads can be accomplished with keeping the old signature or removal of it. Module will check whether there is enough space for the new load and return ErrNotEnoughSpace if there is not enough.

This module is heavily inspired/guided by insert_dylib, install_name_tool projects.

It supports 32bit and 64bit architectures with assumed little endian. FAT binaries are not yet supported.

Usage

package main

import (
	"github.com/lateralusd/gdylib"
	"io"
	"os"
)

func main() {
	r, err := gdylib.Run(os.Args[1], os.Args[2],
		gdylib.WithLoadType(gdylib.WEAK),
		gdylib.WithRemoveCodeSig(true))
	if err != nil {
		panic(err)
	}

	nf, err := os.Create(os.Args[3])
	if err != nil {
		panic(err)
	}
	defer nf.Close()

	io.Copy(nf, r)
}
$ go run main.go a.out @executable_path/FridaGadget.dylib new_file
$ otool -l new_file | tail
 datasize 0
Load command 16
          cmd LC_LOAD_WEAK_DYLIB
      cmdsize 64
         name @executable_path/FridaGadget.dylib (offset 24)
   time stamp 0 Thu Jan  1 01:00:00 1970
      current version 0.0.0
compatibility version 0.0.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotSupported = errors.New("file not supported")
	ErrNotExecute       = errors.New("not executable (MH_EXECUTE)")
	ErrNotLastCommand   = errors.New("cmd LC_CODE_SIGNATURE not last")
	ErrTypeNotSupported = errors.New("unsupported load type")
	ErrNotEnoughSpace   = errors.New("not enough space for new command")
)

Functions

func Run

func Run(binaryPath, dylibPath string, opts ...Option) (io.Reader, error)

Types

type LoadType

type LoadType uint32
const (
	WEAK LoadType = iota
	DYLIB
	RPATH
)

type Option

type Option = func(c *config)

func WithLoadType

func WithLoadType(t LoadType) Option

func WithRemoveCodeSig

func WithRemoveCodeSig(remove bool) Option

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL