How would you turn a function address into a source?

So I wanted to know like this for example function: 0xe59cdfe707cd724a to a code that has that function inside
Example:

local function assert() -- function: 0xe59cdfe707cd724a
-- I have no idea what this code part will look like
end

I wanted to do this for scripting and the purpose was I want to expierence test and how cool it would be like

I donā€™t really understand what you fully mean, maybe this?

local function assert()
    local function printStr(m: string)
        print(m)
    end

    while #game.Players:GetPlayers() > 0 do
        printStr("Welcome")
        break
    end
end

Possibly that?

local function returnName(p)
    return p.Name
end

local function assert(name)
    return name
end

game.Players.PlayerAdded:Connect(function(player)
    assert(returnName(player))
end

That could also work. If you need anything else, or this wasnā€™t what you were looking for, let me know! (You can always hit me up in DMs! :wink:)

I want get function: 0xsomething here and turn it to code

local function action()
	local _1 = 'A'
	local _2 = 'B'
	print('There are 2 arguments')
end

print(action)

This will be function: 0x25d6ac48c6c9d29a
But how would I turn function: 0x25d6ac48c6c9d29a to a code

You cant access memory in a script. So thats impossible I think. But you could use getfenv(function) to get the variables in the function.

Well from what I believe I know, it would just be a cleaner way of displaying the code. A function would be the same as adding the code directly to that line, but just represented by a function instead. (Basically, whatever is in the function will run as the function on that line.)

If none of that made sense, hereā€™s a visual:

local function PrintHelloWorld()
    print("Hello world!")
end

game.Players.PlayerAdded:Connect(PrintHelloWorld)

-- Would be the same as

game.Players.PlayerAdded:Connect(function(player)
    print("Hello world!")
end)

(It would be the same.)

So like

local function tostring()
-- https://create.roblox.com/docs/reference/engine/globals/LuaGlobals#tostring
end

Somewhat, yes. This would error, because itā€™s not hooked to HttpService, and not wrapped in quotes, but yes. If you returned it, it would look like this:

local function tostringl()
    return "https://create.roblox.com/docs/reference/engine/globals/LuaGlobals#tostring"
end

print(tostringl())

-- Would be like doing this:

print("https://create.roblox.com/docs/reference/engine/globals/LuaGlobals#tostring")

A function is basically a way to run code on a single line, making the code cleaner, and more efficient. Itā€™s better to have a single line, rather than multiple lines, with the same code.

A function is a cleaner way to run code. Nothing that special, lol.

local function tostring1(obj)
	local str = Instance.new('StringValue')
	str.Value = obj
	return str.Value
end

This function does what tostring does, Right?
I want to know source of a global function.
Example:

tostring1(11) -- return string

I think you want to do something like this:

function someFunction()
     ā€”code here
end

print(someFunction) ā€”will print the address
print(someFunction()) ā€”actually calls the function and prints whatever it returns.

0xe59cdfe707cd724a is not the binary that is the address in memory

-- save this function into myFunction variable
-- myFunction points to a location in memory
local myFunction = function()
	print("This is my function")
end

-- this will print the location of the function in memory
print(myFunction)

-- and we can call that location in memory like this
myFunction()
1 Like

How would you make the address of function saved in data store and how will it be ran in there?

As far as I know, there is no way to get the raw bytecode of a function. What are you trying to achieve?

But save the address in data store like a string

But how would you convert it to real function?

You donā€™t. Again, what are you trying to achieve?

Iā€™m trying to achieve to know how to convert function address like to

local function work()
print('working')
end

What I want to know is why are you trying to do this? This is a case of the XY problem.

You simply cannot convert it into a function. Think of a memory address as a table and an index, with the address being an index and the function being the value. You canā€™t ā€œconvertā€ the address into the value, you first have to index the hypothetical table with the address to get the function. Obviously Iā€™m oversimplifying it incredibly, thatā€™s not actually how memory is stored.

2 Likes

I think I found a way to turn function address to source but
ā€¦


There are three functions that have same name and I donā€™t know how I would use ā€˜info(function: function, options: string): Tupleā€™