Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDoubleHook means the function already hooked, you cannot hook it again. ErrDoubleHook = errors.New("double hook") // ErrHookNotFound means the hook not found in the applied hooks, maybe you // are trying to restore a corrupted hook. ErrHookNotFound = errors.New("hook not found") // ErrDifferentType means "from" and "to" are of different types, you should // only replace a function with one of the same type. ErrDifferentType = errors.New("inputs are of different type") // ErrInputType means either "from" or "to" are not func type, cannot apply. ErrInputType = errors.New("inputs are not func type") // ErrRelativeAddr means you cannot call the origin function with the hook // applied, try disable the hook, pay special attention to the concurrency. ErrRelativeAddr = errors.New("relative address in instruction") )
Functions ¶
This section is empty.
Types ¶
type Enabler ¶
type Enabler interface {
Enable()
}
Enabler is the interface the wraps the Enable method.
Enable enables a hook which disabled by the Disable method of the Hook interface. This method will change the code in the text segment, so is not concurrent safe, need special attention.
type Hook ¶
type Hook interface { // Origin returns the original function, or an error if the original function // is not usable after the hook applied. Origin() interface{} // Disable temporarily disables the hook and restores the original function, the // hook can be enabled later using the returned Enabler. Disable() Enabler // Restore restores the original function permanently, if you want to enable the // hook again, you should use the Apply function later. Restore() error }
Hook represents an applied hook, it implements Origin, Disable and Restore. The Disable and Restore methods will change the code in the text segment, so are not concurrent safe, need special attention.
type HookCaller ¶ added in v0.1.3
type HookCaller interface { // Disable disables the hooks and restores the calls to the original function, // the hook can be enabled later using the returned Enabler. Disable() Enabler // Count returns the total number of modified call instructions. If the hooks // are disabled, it returns 0. Count() int }
HookCaller applies a group of hooks in the caller, by changing the relative address in some call instructions. It is not concurrent safe, need special attention.
func Replace ¶ added in v0.1.3
func Replace(caller, old, new interface{}, limit int) (h HookCaller, err error)
Replace the calls to "old" with "new" in caller, without modify any instructions in "old"