Function Hooking
-
The base function hook type. All function hooks must subclass this.
In order to make a function hook, create a class which conforms to this type. Satisfy the protocol requirement by providing a static
targetproperty, and declare a function namedfunctionwith the signature of the function that is being hooked.The original function implementation can be accessed via
orig.function.Example
The following example hooks the C standard library function
atoisuch thatatoi("1234")returns4321and all other calls behave normally.class AtoiHook: FunctionHook { static let target = Function.symbol("atoi", image: nil) func function(_ string: UnsafePointer<Int8>) -> Int32 { if String(cString: string) == "1234" { return 4321 } else { return orig.function(string) } } }Declaration
Swift
public typealias FunctionHook = FunctionHookClass & FunctionHookProtocol -
The protocol to which function hooks conform. Do not conform to this directly; use
See moreFunctionHook.Declaration
Swift
public protocol FunctionHookProtocol : AnyObject, AnyHook -
An enumeration describing a function.
See moreDeclaration
Swift
public enum Function : CustomStringConvertible
View on GitHub
Install in Dash
Function Hooking Reference