Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - unmangle names in BPL's

Is it possible to unmangle names like these in Delphi? If so, where do I get more information?

Example of an error message where it cannot find a certain entry in the dbrtl100.bpl I want to know which exact function it cannot find (unit, class, name, parameters, etc).

---------------------------
myApp.exe - Entry Point Not Found
---------------------------
The procedure entry point @Dbcommon@GetTableNameFromSQLEx$qqrx17System@WideString25Dbcommon@IDENTIFIEROption could not be located in the dynamic link library dbrtl100.bpl. 
---------------------------
OK   
---------------------------

I know it is the method GetTableNameFromSQLEx in the Dbcommon unit (I have Delphi with the RTL/VCL sources), but sometimes I bump into apps where not all code is available for (yes, clients should always buy all the source code for 3rd party stuff, but sometimes they don't).

But say this is an example for which I do not have the code, or only the interface files (BDE.INT anyone?) What parameters does it have (i.e. which potential overload)? What return type does it have?

Is this mangling the same for any Delphi version?

--jeroen

Edit 1:

Thanks to Rob Kennedy: tdump -e dbrtl100.bpl does the trick. No need for -um at all:

C:\WINDOWS\system32>tdump -e dbrtl100.bpl | grep GetTableNameFromSQLEx
File STDIN:
00026050 1385 04AC __fastcall Dbcommon::GetTableNameFromSQLEx(const System::WideString, Dbcommon::IDENTIFIEROption)

Edit 2:

Thanks to TOndrej who found this German EDN article (English Google Translation). That article describes the format pretty accurately, and it should be possible to create some Delphi code to unmangle this.

Pitty that the website the author mentions (and the email) are now dead, but good to know this info.

--jeroen

like image 901
Jeroen Wiert Pluimers Avatar asked Oct 19 '09 20:10

Jeroen Wiert Pluimers


1 Answers

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.

like image 118
Rob Kennedy Avatar answered Nov 04 '22 07:11

Rob Kennedy