alexk
alexk

Reputation: 131

Swift mangled function name mapping

How does the Hopper disassembler understand what is the function's name?

For example, I have a simple Swift function named function(), and after disassembling the executable with that function Hopper shows me that it's mangled name is __T04file8functionyy. I can find the location of these symbols in the executable file, but I can't find how does it map the address of the function with it's name.

Upvotes: 3

Views: 5304

Answers (2)

alexk
alexk

Reputation: 131

I found this Mach-O file format reference: https://github.com/aidansteele/osx-abi-macho-file-format-reference

So the answer to my question is that there is a special struct called nlist_64, which contains the address of the function in the executable and the index of the mangled name of that function in the symbol table.

Upvotes: 2

Code Different
Code Different

Reputation: 93191

You can read the name mangling specs straight from Apple.

If you only want a quick way to demangle the name, type the following in Terminal:

swift demangle __T04file8functionyy

Output:

_T04file8functionyy ---> filefunction empty-list  empty-list 

(I'm not sure if the mangled name you provided is valid)

Upvotes: 13

Related Questions