Documentation
¶
Overview ¶
Package patchlib provides common functions related to patching binaries.
Index ¶
- func AsmBLX(pc, target uint32) []byte
- func AsmBW(pc, target uint32) []byte
- func IsCSS(r io.Reader) (bool, error)
- type Patcher
- func (p *Patcher) BaseAddress(offset int32) error
- func (p *Patcher) ExtractDynsyms(needPLTGOT bool) ([]*dynsym, error)
- func (p *Patcher) ExtractZlib() ([]ZlibItem, error)
- func (p *Patcher) FindBaseAddress(find []byte) error
- func (p *Patcher) FindBaseAddressString(find string) error
- func (p *Patcher) FindBaseAddressSymbol(find string) errordeprecated
- func (p *Patcher) FindZlib(find string) error
- func (p *Patcher) FindZlibHash(hash string) error
- func (p *Patcher) GetBytes() []byte
- func (p *Patcher) GetCur() int32
- func (p *Patcher) Hook(fn func(offset int32, find, replace []byte) error)
- func (p *Patcher) ReplaceBLX(offset int32, find, replace uint32) errordeprecated
- func (p *Patcher) ReplaceBytes(offset int32, find, replace []byte) error
- func (p *Patcher) ReplaceBytesNOP(offset int32, find []byte) errordeprecated
- func (p *Patcher) ReplaceFloat(offset int32, find, replace float64) error
- func (p *Patcher) ReplaceInt(offset int32, find, replace uint8) error
- func (p *Patcher) ReplaceString(offset int32, find, replace string) error
- func (p *Patcher) ReplaceZlib(offset int32, find, replace string) error
- func (p *Patcher) ReplaceZlibGroup(offset int32, repl []Replacement) error
- func (p *Patcher) ResetBaseAddress()
- func (p *Patcher) ResolveSym(name string) (int32, error)
- func (p *Patcher) ResolveSymPLT(name string) (int32, error)
- func (p *Patcher) ResolveSymPLTTail(name string) (int32, error)
- type Replacement
- type ZlibItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsmBLX ¶ added in v0.15.1
AsmBLX assembles a BLX instruction and returns a byte slice which can be patched directly into a binary.
func AsmBW ¶ added in v0.15.1
AsmBW assembles a B.W instruction and returns a byte slice which can be patched directly into a binary.
func IsCSS ¶ added in v0.15.1
IsCSS uses a heuristic to check if the input is likely to be CSS. There may be false negatives for invalid CSS or for CSS documents with more rules than properties, and false positives for CSS-like languages. An error is returned if and only if the io.Reader returns an error.
Types ¶
type Patcher ¶
type Patcher struct {
// contains filtered or unexported fields
}
Patcher applies patches to a byte array. All operations are done starting from cur.
func (*Patcher) BaseAddress ¶
BaseAddress moves cur to an offset. The offset starts at 0.
func (*Patcher) ExtractDynsyms ¶ added in v0.15.1
func (*Patcher) ExtractZlib ¶ added in v0.7.0
ExtractZlib extracts all CSS zlib streams. It returns it as a map of offsets and strings.
func (*Patcher) FindBaseAddress ¶
FindBaseAddress moves cur to the offset of a sequence of bytes.
func (*Patcher) FindBaseAddressString ¶
FindBaseAddressString moves cur to the offset of a string.
func (*Patcher) FindBaseAddressSymbol
deprecated
added in
v0.13.0
func (*Patcher) FindZlib ¶ added in v0.7.0
FindZlib finds the base address of a zlib css stream based on a substring (not sensitive to whitespace).
func (*Patcher) FindZlibHash ¶ added in v0.7.0
FindZlibHash finds the base address of a zlib css stream based on it's SHA1 hash (can be found using the cssextract tool).
func (*Patcher) Hook ¶ added in v0.15.1
Hook sets a hook to be called right before every change. If it returns an error, it will be passed on. If nil (the default), the hook will be removed. The find and replace arguments MUST NOT be modified by the hook.
func (*Patcher) ReplaceBLX
deprecated
added in
v0.12.0
func (*Patcher) ReplaceBytes ¶
ReplaceBytes replaces the first occurrence of a sequence of bytes with another of the same length.
func (*Patcher) ReplaceBytesNOP
deprecated
added in
v0.12.0
func (*Patcher) ReplaceFloat ¶
ReplaceFloat replaces the first occurrence of a float.
func (*Patcher) ReplaceInt ¶
ReplaceInt replaces the first occurrence of an integer between 0 and 255 inclusively.
func (*Patcher) ReplaceString ¶
ReplaceString replaces the first occurrence of a string with another of the same length.
func (*Patcher) ReplaceZlib ¶ added in v0.7.0
ReplaceZlib replaces a part of a zlib css stream at the current offset.
func (*Patcher) ReplaceZlibGroup ¶ added in v0.11.0
func (p *Patcher) ReplaceZlibGroup(offset int32, repl []Replacement) error
ReplaceZlibGroup is the same as ReplaceZlib, but it replaces all at once.
func (*Patcher) ResetBaseAddress ¶
func (p *Patcher) ResetBaseAddress()
ResetBaseAddress moves cur to 0.
func (*Patcher) ResolveSym ¶ added in v0.15.1
ResolveSym resolves a mangled (fallback to unmangled) symbol name and returns its base address (error if not found). The symbol table will be loaded if not already done.
func (*Patcher) ResolveSymPLT ¶ added in v0.15.1
ResolveSymPLT resolves a mangled (fallback to unmangled) symbol name and returns its PLT address (error if it doesn't have one). The symbol table will be loaded if not already done.
func (*Patcher) ResolveSymPLTTail ¶ added in v0.15.1
ResolveSymPLTTail resolves a mangled (fallback to unmangled) symbol name and returns its PLT tail call address (error if it doesn't have one). The symbol table will be loaded if not already done.
type Replacement ¶ added in v0.11.0
type Replacement struct {
Find, Replace string
}
Replacement is a replacement for ReplaceZlibGroup.