Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

debug.getconstants

The debug.getconstants function will retrive the constants of a Lua Closure

function getconstants(func: (...any) -> (...any)): {[number]: any}
local function test_func(): ()
    local h: string = "Hello";
    return;
end;
print(debug.getconstants(test_func)[1]); -- "Hello"

This function is useful for retriving constants to help with reverse engineering

debug.setconstant

The debug.setconstant function will set the constant of func at index with value

function setconstant(func: (...any) -> (...any), index: number, value: any): ()
local function test_func(): ()
    local h: string = "Hello";
    print(h);
    return;
end;
test_func(); --> prints "Hello"
debug.setconstant(test_func, 1, "Bye");
test_func(); --> prints "Bye"

This function is useful for modifying internals of a function

debug.getconstant

The debug.getconstant function will retrive the constants of a Lua Closure at index

function getconstant(func: (...any) -> (...any), index: number): any
local function test_func(): ()
    local h: string = "Hello";
    return;
end;
print(debug.getconstant(test_func, 1)); -- "Hello"

debug.getupvalues

The debug.getupvalues function will retrive the upvalues of a Lua Closure

function getupvalues(func: (...any) -> (...any)): {[number]: any}
local tbl: {[number]: string} = {"hi"};
local function test_func(): ()
    print(tbl); --> 'tbl' is now an 'upvalue' of function 'test_func'
    return;
end;
print(debug.getupvalues(tbl)[1] == tbl); --> true

This function is useful for retriving and modifying upvalues to help with reverse engineering

debug.getupvalue

The debug.getupvalue function will retrive the upvalue of a Lua Closure at index

function getupvalue(func: (...any) -> (...any), index: number): any
local tbl: {[number]: string} = {"hi"};
local function test_func(): ()
    print(tbl); --> 'tbl' is now an 'upvalue' of function 'test_func'
    return;
end;
print(debug.getupvalue(tbl, 1) == tbl); --> true

debug.setupvalue

The debug.setupvalue function will set the upvalue of a Lua Closure at index with value

function getupvalue(func: (...any) -> (...any), index: number, value: any): ()
local tbl: {[number]: string} = {"hi"};
local function test_func(): ()
    print(tbl); --> 'tbl' is now an 'upvalue' of function 'test_func'
    return;
end;
debug.setupvalue(test_func, 1, {});
print(debug.getupvalue(test_func, 1) == tbl); --> false

This function is useful for modifying internals of a function

debug.getprotos

The debug.getprotos function will retrive protos (functions inside the functions) of the provided functions.

function debug.getprotos(func: (...any) -> (...any)): {[number]: (...any) -> (...any)}
local function test_func()
    local function hi() --> function 'hi' is a proto of 'test_func'
        return;
    end;
    return;
end;
print(debug.getprotos(test_func)[1]) --> function: 0x..;

This function is useful for retriving and modifying upvalues to help with reverse engineering

debug.getproto

The debug.getproto function will retrive the proto (functions inside the functions) at index of the specified function

function debug.getproto(func: (...any) -> (...any), index: number): (...any) -> (...any)
local function test_func()
    local function hi() --> function 'hi' is a proto of 'test_func'
        return;
    end;
    return;
end;
print(debug.getupvalue(test_func, 1)); --> function: 0x..

debug.setproto

The debug.setproto function will set the proto (functions inside the functions) at index of the specified function

function debug.getproto(func: (...any) -> (...any), index: number, func: (...any) -> (...any)): ()
local function test_func()
    local function hi() --> function 'hi' is a proto of 'test_func'
        return;
    end;
    return;
end;
debug.setproto(test_func, 1, function(): ()
    return;
end);

This function is useful for modifying internals of a function

debug.getstack

The debug.getstack function will all values or values specified by an index of the level

function getstack(level: number, index: number?): {[number]: any}
local function test_function(): ()
    local workspace: Workspace = workspace;
    local game: DataModel = game;
    local hi: string = "wow";
    print(debug.getstack(1, 1)) --> Workspace
    return;
end;
test_function();

This function is useful for retriving values from the stack to help with reverse engineering

debug.setstack

The debug.setstack function sets values onto the stack with the specified index and value

function setstack(level: number, index: number, value: any): ()
local outer_value = 10
local function inner_function()
    outer_value += 9
    debug.setstack(2, 1, 100)
end
inner_function()
print(outer_value) -- Output: 100

This function is useful for modifying internals of a function

debug.setname

The debug.setname (or setname) function set the debug name of the func with name_str

function setname(func: (...any) -> (...any), name_str: string): ()
local hi = function() -- created a new function with NO debug name
    return;
end;
print(debug.info(hi, "n")); --> ""
debug.setname(hi, "gay");
print(debug.info(hi, "n")) --> "hi"

This function is useful for modifying internals of a function

debug.setinfo

The debug.setinfo function sets the provided debug fields of func

function setinfo(func: (...any) -> (...any), options: {[string]: any})

This function is useful for modifying internals of a function

debug.getcode

The debug.getcode function retrives instructions from func or the instruction at index

function getcode(func: (...any) -> (...any), index: number?): {[number]: any} | {[string]: any}
local function add(a: number, b: number): number
    return (a+b);
end;
for _: unknown, v: {[string]: any} in debug.getcode(add) do
    if (v.opname == "ADD") then
        print(v);
        break;
    end;
end;

debug.setcode

The debug.setcode function is used to swap the instruction at index with the user-provided instruction

function setcode(func: (...any) -> (...any), index: number, instruction: {[string]: any}): ()

debug.getinstance

The debug.getinstance function is used to retrive the real instance of proxy all Instances in the VM are emulated

function getinstance(proxy: any): Instance