xhookLua
Game

ffinative tier

Call native functions by address and read structs by name; native tier, x86, wrong signatures corrupt the stack.

Functions

ffi.bind

ffi.bind(addr, abi, ret [, argtypes]) -> fn
NameTypeDescription
addrintegerFunction address.
abistring"cdecl", "stdcall" or "thiscall".
retstringType string or "void".
argtypesoptionaltableMax 16; thiscall starts with "ptr". Default {}.

Binds an address to a signature; call the result like a function.

Returns callable handle

  • Raises on a bad abi, type, over 16 args, or thiscall without this.
  • Calls raise on non-executable addr or a fault; 64-bit returns truncate to 32.

fn(...)

fn(...) -> value
NameTypeDescription
...anyArguments as declared in ffi.bind.

Calls a bound handle; hook handle:call works the same.

Returns declared type; nothing for void

Missing int or float arguments raise; missing ptr or string pass NULL.

ffi.call

ffi.call(addr, abi, ret, argtypes, ...) -> value
NameTypeDescription
addrinteger
abistring"cdecl", "stdcall" or "thiscall".
retstringReturn type string.
argtypestable | nilType strings, or nil.
...optionalanyNative arguments.

One-shot call without a handle; same rules as ffi.bind.

Returns declared return type

ffi.export

ffi.export(module, name) -> integer | nil
NameTypeDescription
modulestringLoaded module, like "kernel32.dll".
namestringExported function or variable.

Looks up an export; never loads the module.

Returns export address, or nil

ffi.vfunc

ffi.vfunc(object, index) -> integer | nil
NameTypeDescription
objectintegerObject address; vtable pointer first.
indexinteger0-based slot, 0 to 1023.

Reads one vtable entry; bind it as thiscall with "ptr" first.

Returns slot's function address, or nil

ffi.struct

ffi.struct(fields) -> Layout
NameTypeDescription
fieldstableMax 64 fields.

Describes a struct: name = { type, offset } per field.

Returns Layout, called with an address

  • "string" is an inline char array; use "ptr" plus memory.read_string for char*.
  • Raises on non-string keys, void or negative offsets, or over 64 fields.

Layout(addr)

Layout(addr) -> obj
NameTypeDescription
addrintegerInstance address.

Binds the layout to an address; cheap, make one per instance.

Returns struct object at that address

obj.<field>

obj.<field> -> value | nil ; obj.<field> = value

Reads or writes a field by name; obj.address holds the address.

Returns field value, or nil

  • Unknown fields raise on write and read nil; string fields can't be written.
  • Writes to non-writable memory silently do nothing; unreadable reads return nil.

Constants

NameValueDescription
"void"type stringNo value; return type only.
"int"type stringSigned 32-bit integer.
"uint"type stringUnsigned 32-bit integer.
"bool"type string32-bit in calls, 1 byte in structs.
"float"type string32-bit float.
"double"type string64-bit, two argument slots.
"ptr"type string32-bit address integer; nil passes NULL.
"string"type stringconst char* in calls; inline array in structs.
"cdecl"abi stringCaller cleans stack; C functions, most engine exports.
"stdcall"abi stringCallee cleans stack; Windows API.
"thiscall"abi stringC++ method: this in ECX, callee cleans.
ffi ยท Lua API ยท xhook