avast / retdec

RetDec is a retargetable machine-code decompiler based on LLVM.
https://retdec.com/
MIT License
7.97k stars 942 forks source link

Demangler: Incorrect demangling #96

Open PeterMatula opened 6 years ago

PeterMatula commented 6 years ago

Originally reported by @q1o1p in https://github.com/avast-tl/demangler/issues/1.

elliptic function like ?debugf@@YAXPB_WZZ demangling wrong. now: void __cdecl debugf(wchar_t const *) must be: void __cdecl debugf(wchar_t const *,...) lose ...

PeterMatula commented 6 years ago

Thank you for the report.

However, we will not be able to fix this in the current implementation. See #95.

Sorry we did not make this clear from the start.

PeterMatula commented 6 years ago

Another problem: Input: demangler _ZL21size_of_encoded_valueh Output:

gcc: cGram::subanalyze: Syntax error: No rule for NT encoding and T L.
ms: cGram::analyze: Syntax error: No rule for NT mangled-name and T _.
borland: cGram::analyze: Syntax error: No rule for NT mangled-name and T _.

Expected output (https://demangler.com/): size_of_encoded_value(unsigned char)

PeterMatula commented 6 years ago

More examples to analyze:

gcc:

_ZStmiISt6vectorIN5cName6type_tESaIS2_EERS4_PS4_ENSt15_Deque_iteratorIT_T0_T1_E15difference_typeERKSB_SE_
_ZTI5cName
_ZTS5cName
_ZTVN10__cxxabiv117__class_type_infoE
_ZdlPvS_

ms:

?_Left@?$_Tree@V?$_Tmap_traits@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@DU?$pair@IW4semact@cGram@@@std@@U?$less@D@2@V?$allocator@U?$pair@$$CBDU?$pair@IW4semact@cGram@@@std@@@std@@@2@@2@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@DU?$pair@IW4semact@cGram@@@std@@U?$less@D@2@V?$allocator@U?$pair@$$CBDU?$pair@IW4semact@cGram@@@std@@@std@@@2@@2@@std@@@2@$0A@@std@@@std@@KAAAPAU_Node@?$_Tree_nod@V?$_Tmap_traits@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@DU?$pair@IW4semact@cGram@@@std@@U?$less@D@2@V?$allocator@U?$pair@$$CBDU?$pair@IW4semact@cGram@@@std@@@std@@@2@@2@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@DU?$pair@IW4semact@cGram@@@std@@U?$less@D@2@V?$allocator@U?$pair@$$CBDU?$pair@IW4semact@cGram@@@std@@@std@@@2@@2@@std@@@2@$0A@@std@@@2@PAU342@@Z

borland:

@$xt$p19Comobj@EOleSysError
PeterMatula commented 6 years ago

This is being worked on by one student as his bachelor thesis - see milestone and the referenced forked repository.

PeterMatula commented 5 years ago

With the new demangler (#95):

So the only one to look at is ?debugf@@YAXPB_WZZ.