Backend
public protocol Backend
The type that handles hooking of methods and functions.
Unless you have specific requirements, you should be able to use one
of the pre-defined backends declared on Backends
.
If you are creating a custom Backend
implementation which is intended
for distribution, declare it as a nested type in an extension on the
Backends
enumeration. The backend’s name (which is understood by the
Orion CLI) is then the type name minus the Backends.
prefix.
If a custom backend name is specified via the Orion CLI, Orion will
automatically attempt to import a module named OrionBackend_<backend name>
if it exists, so it is recommended that you follow this nomenclature while
naming your framework. Note that when determining the framework name, any
generic arguments are stripped from the type name, and only the first
component of the name is used.
For example, a backend with the type Backends.Foo.Bar<Int>
will be referred
to by the name Foo.Bar<Int>
, and Orion will attempt to auto-import a module
named OrionBackend_Foo
.
-
Hooks the provided functions and methods.
Declaration
Swift
func apply(descriptors: [HookDescriptor])
Parameters
descriptors
The descriptors for the hooks to be applied.
-
hookFunction(_:
Extension methodreplacement: ) Performs a one-off function hook.
Prefer batching with
apply(hooks:)
if you have multiple hooks, as backends may be able to optimize batch hooking.Declaration
Swift
public func hookFunction(_ function: Function, replacement: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer
Parameters
function
The function which is to be hooked.
replacement
The replacement function implementation. See
HookDescriptor.function(function:replacement:completion:)
for details.Return Value
The original function implementation.
-
hookMethod(cls:
Extension methodsel: replacement: ) Performs a one-off method hook.
Prefer batching with
apply(hooks:)
if you have multiple hooks, as backends may be able to optimize batch hooking.Declaration
Swift
public func hookMethod(cls: AnyClass, sel: Selector, replacement: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer
Parameters
cls
The class which contains the method to be hooked.
sel
The selector of the method to be hooked.
replacement
The replacement method implementation. See
HookDescriptor.method(cls:sel:replacement:completion:)
for details.Return Value
The original method implementation.