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| Name | Type | Description |
|---|---|---|
| addr | integer | Function address. |
| abi | string | "cdecl", "stdcall" or "thiscall". |
| ret | string | Type string or "void". |
| argtypesoptional | table | Max 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| Name | Type | Description |
|---|---|---|
| ... | any | Arguments 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| Name | Type | Description |
|---|---|---|
| addr | integer | |
| abi | string | "cdecl", "stdcall" or "thiscall". |
| ret | string | Return type string. |
| argtypes | table | nil | Type strings, or nil. |
| ...optional | any | Native arguments. |
One-shot call without a handle; same rules as ffi.bind.
Returns declared return type
ffi.export
ffi.export(module, name) -> integer | nil| Name | Type | Description |
|---|---|---|
| module | string | Loaded module, like "kernel32.dll". |
| name | string | Exported function or variable. |
Looks up an export; never loads the module.
Returns export address, or nil
ffi.vfunc
ffi.vfunc(object, index) -> integer | nil| Name | Type | Description |
|---|---|---|
| object | integer | Object address; vtable pointer first. |
| index | integer | 0-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| Name | Type | Description |
|---|---|---|
| fields | table | Max 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| Name | Type | Description |
|---|---|---|
| addr | integer | Instance 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> = valueReads 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
| Name | Value | Description |
|---|---|---|
| "void" | type string | No value; return type only. |
| "int" | type string | Signed 32-bit integer. |
| "uint" | type string | Unsigned 32-bit integer. |
| "bool" | type string | 32-bit in calls, 1 byte in structs. |
| "float" | type string | 32-bit float. |
| "double" | type string | 64-bit, two argument slots. |
| "ptr" | type string | 32-bit address integer; nil passes NULL. |
| "string" | type string | const char* in calls; inline array in structs. |
| "cdecl" | abi string | Caller cleans stack; C functions, most engine exports. |
| "stdcall" | abi string | Callee cleans stack; Windows API. |
| "thiscall" | abi string | C++ method: this in ECX, callee cleans. |