Swift Objective-C runtime class naming

梦想与她 提交于 2019-12-06 10:50:26

They're not random. They're the length of the following value. This is similar to common C++ name mangling and supports identifiers that may have fairly arbitrary characters in them without needing some new separator character. It also can make them easier to parse, especially in C.

In this particular case, it's _TtC then "an eleven character module name" then the module name and then "a fourteen character class name" and the class name. I assume C is class. Not sure about Tt (maybe "type").

The description is build up in the following 3 sections

  1. The description starts with _Tt which stands for target (bundle / app name)
  2. After that you will have one or more letters like C P F which stands for Class, Protocol or Function. These are in reverse order according to the nesting
  3. Then you will get series of numbers plus a name where the number is the length of the name. each of these are for the target, Class, Protocol or Function as specified in the beginning of the description.

Functions are a special case here. The description will also has some information about the function signature.

For example you could have a _TtCFCC5MyApp7MyClass10MySubClass6myFuncFS0_FT_T_L_11MySubSubClass

This would be the description of the MySubSubClass in the following code:

class MyClass {
   class MySubClass {
     func myFunc() {
       class MySubSubClass {
       }
     }
   }
}

Here you can find some sample code that will parse that description into easy to use properties and arrays.

Update: Demangle is now converted to swift. You can find it here: https://github.com/mattgallagher/CwlDemangle/blob/master/CwlDemangle/CwlDemangle.swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!