Skip to main content

lje.func

Function inspection, spoofing, and stealth utilities.

Functions

lje.func.spoof(spoof_fn, target_fn)

Makes target_fn appear as spoof_fn in debug introspection (e.g. debug.getinfo).

The spoof is recorded globally. Each function can only participate in one spoof relationship at a time.

Parameters

NameTypeDescription
spoof_fnfunction

The Lua function whose debug info will be reported. Must be a Lua function, not a C function.

target_fnfunction

The function that will appear as spoof_fn when inspected.

Errors

  • Argument 1 must be a Lua function (not a C function).

lje.func.is_spoofed(fn)

Checks whether fn is currently being used as a spoof target.

Parameters

NameTypeDescription
fnfunction

The function to check.

Returns

TypeDescription
boolean

true if the function is a spoof target, false otherwise.

function?

If spoofed, the original function is also returned as a second value.

lje.func.mark_special(fn)

Note: You shouldn't need to use this unless you know what you are doing!

Marks a Lua function as a special (internal) frame.

Special frames are hidden from stack introspection unless lje.env.show_special_frames is enabled. Automatically applied to callbacks registered with LJE (e.g. lje.util.set_push_string_callback).

Parameters

NameTypeDescription
fnfunction

Must be a Lua function, not a C function.

Errors

  • Argument 1 must be a Lua function (not a C function).

lje.func.compile(source)

Compiles a Lua string into a function without executing it. If a global environment is set via lje.env.set, it is applied to the compiled function automatically. Returns nil on compilation failure.

Parameters

NameTypeDescription
sourcestring

Lua source code to compile.

Returns

TypeDescription
function | nil

The compiled function, or nil if compilation failed.

lje.func.hide_caller(fn)

Hides fn from appearing as a caller in stack traces.

Parameters

NameTypeDescription
fnfunction

The function to hide from stack traces.

lje.func.type(fn)

Returns the internal LuaJIT fast function ID (ffid) of a function.

  • 0 means a Lua function
  • 1 means a C function
  • Anything else is the unique ID of a fast function.

Parameters

NameTypeDescription
fnfunction

The function to inspect.

Returns

TypeDescription
number

The ffid value. 0 for regular Lua functions.