Hooking APIs
Functions
setstackhidden
void setstackhidden(closure: function, hidden?: bool = True)
Hides or unhides a function from the callstack.
void setstackhidden(level: int, hidden?: bool = True)
Hides or unhides a function (indicated by level
) in the callstack.
newcclosure
function newcclosure(closure: function, name?: string)
Creates a C wrapper around closure
with function name name
if provided.
clonefunction
function clonefunction(to_clone: function)
Clones a function. Note that if the function passed is a C closure, is_synapse_function
will return true
on the returned closure.
hookfunction
function hookfunction(to_hook: function, hook: function, filter?: Filter = nil)
Hooks a Lua or C function in-place. Returns a copy of the original function. Can optionally specify a filter to use.
hookproto
void hookproto(to_hook: ProtoProxy, hook: function)
Hooks a Lua function prototype. Prototypes can only be hooked once!
hookmetamethod
void hookmetamethod(to_hook: userdata, metamethod: string, hook: function, arg_guard?: bool = True, filter?: Filter = nil)
TODO
restorefunction
void restorefunction(to_restore: closure)
Un-hooks a function hooked with hookfunction.
isfunctionhooked
bool isfunctionhooked(f: function)
Returns true if f
is hooked by hookfunction
, hookmetamethod
, or syn.oth.hook
.
restoreproto
void restoreproto(to_restore: ProtoProxy)
Removes a Proto hook created via hookproto
.
hooksignal
void hooksignal(signal: ScriptSignal, callback: function)
Enables the interception of signal invocations. When signal
is fired, callback
is called for every Lua connection in signal
with an info table and the invocation arguments. Returning true from this callback fires the original connection.
For now, the callback should not yield.
hooksignal
cannot be used to intercept C (engine) connections or Lua connections belonging to CoreScripts.
Example code:
local part = Instance.new("Part")
part.Changed:Connect(function(prop)
print(prop .. " changed?")
end)
hooksignal(part.Changed, function(info, prop)
print(info.Connection) -- the connection object.
print(info.Function) -- the original function. Not available for waiting connections.
print(info.Index) -- the position of this connection in part.Changed at the time this callback is executed. Not available for waiting connections.
print(prop)
return true, "Hooked"
end)
part.Name = "NewName"
Output:
Connection
function: <etc>
0
Name
Hooked changed?
restoresignal
void restoresignal(signal: ScriptSignal)
Unhooks a signal hooked with hooksignal.
issignalhooked
void issignalhooked(signal: ScriptSignal)
Returns true if signal
is hooked.
syn.oth.hook
function syn.oth.hook(target: function, hook: function)
A secure version of hookfunction
for C functions that works by running hook code on separate threads. When a hooked function is called,
a new or cached hook thread is resumed with the hook
and any passed arguments. The returned callback can be used to execute the original function on the original, calling thread.
In the context of a hook thread, the following functions behave as though being called under the original thread:
- getnamecallmethod
- setnamecallmethod
- checkcaller
- checkcallstack
- getcallingscript
- the debug library (debug.*)
- TODO
syn.oth.unhook
bool syn.oth.unhook(target: function, hook_or_callback?: function)
Un-hooks a function hooked with syn.oth.hook
. The second parameter is not required if the function has only been hooked once. Returns true upon success.
syn.oth.get_root_callback
function syn.oth.get_root_callback()
Returns a function that can be used to call the original function in the context of a hook thread. Useful for when a function is hooked multiple times and the callback you receive from syn.oth.hook
executes the next hook in the chain, not the original function.
syn.oth.is_hook_thread
bool syn.oth.is_hook_thread()
Returns true if this thread is a hook thread.
syn.oth.get_original_thread
thread syn.oth.get_original_thread()
Return the original thread this hook comes from, or nil if the current thread is not a hook.