Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get swift mangled object name

Tags:

swift

I've learned that swift actually creates a naming method called "mangling" used internally for all objects.

All threads talk about demangling, but how to actually get the mangled name?

i've tried
1- object_getClass(self)
2- NSStringFromClass(MyClass.self)
but they return the normal class name.

I've found this demangle project.. https://github.com/mattgallagher/CwlDemangle/blob/master/CwlDemangle/CwlDemangle.swift
is there a mangling project maybe?

Note: Im using swift 3.0.1

like image 741
Esam Sherif Avatar asked Nov 25 '25 10:11

Esam Sherif


1 Answers

xcode ships with a command line tool to de-mangle names.

Type in: swift demangle

Then find your mangled class name.. __TMaC17find_the_treasure15YD_Secret_Class

Then watch it spit out the name.. find_the_treasure.YD_Secret_Class

If you want to observe the mangled names, as you asked, you can put the produced Swift iOS or macOS binary into a dissassembler like Hopper, iDAPro or radare2.

The tools to automatically de-mangle names are already here (refer to Hopper v4.0 Dissassembler).

like image 184
rustyMagnet Avatar answered Nov 27 '25 23:11

rustyMagnet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!