Delphi - unmangle names in BPL's

廉价感情. 提交于 2019-11-28 20:51:47
Rob Kennedy

There is no function provided with Delphi that will unmangle function names, and I'm not aware of it being documented anywhere. Delphi in a Nutshell mentions that the "tdump" utility has a -um switch to make it unmangle symbols it finds. I've never tried it.

tdump -um -e dbrtl100.bpl

If that doesn't work, then it doesn't look like a very complicated scheme to unmangle yourself. Evidently, the name starts with "@" and is followed by the unit name and function name, separated by another "@" sign. That function name is followed by "$qqrx" and then the parameter types.

The parameter types are encoded using the character count of the type name followed by the same "@"-delimited format from before.

The "$" is necessary to mark the end of the function name and the start of the parameter types. The remaining mystery is the "qqrx" part. That's revealed by the article Tondrej found. The "qqr" indicates the calling convention, which in this case is register, a.k.a. fastcall. The "x" applies to the parameter and means that it's constant.

The return type doesn't need to be encoded in the mangled function name because overloading doesn't consider return types anyway.

Also see this article (in German). I guess the mangling is probably backward-compatible, and new mangling schemes are introduced in later Delphi versions for new language features.

If you have C++Builder, check out $(BDS)\source\cpprtl\Source\misc\unmangle.c - it contains the source code for the unmangling mechanism used by TDUMP, the debugger and the linker. (C++Builder and Delphi use the same mangling scheme.)

From the Delphi 2007 source files:

function GetTableNameFromSQLEx(const SQL: WideString; IdOption: IDENTIFIEROption): WideString;

This seems to be the same version, since I also have the same .BPL in my Windows\System32 folder.

Source can be found in [Program Files folders]\CodeGear\RAD Studio\5.0\source\Win32\db

Borland/Codegear/Embarcadero has used this encoding for a while now and never gave many details about the .BPL format. I've never been very interested in them since I hate using runtime libraries in my projects. I prefer to compile them into my projects, although this will result in much bigger executables.

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