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.
func Apply ¶
Apply the hook, replace "from" with "to". This function will change the code in the text segment, so is not concurrent safe, need special attention. Some other goroutines may executing the code when you replacing it.