radareorg / r2retdec

RetDec plugin for Radare2
https://retdec.com/
MIT License
124 stars 24 forks source link

pdz crashes r2 #12

Closed bannsec closed 4 years ago

bannsec commented 4 years ago

When I attempt to use pdz to decompile a function, it immediately crashes radare2.

r2 -A ./challenge 
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls (aac)
[x] Analyze len bytes of instructions for references (aar)
[x] Check for objc references
[x] Check for vtables
[x] Type matching analysis for all functions (aaft)
[x] Propagate noreturn information
[x] Use -AA or aaaa to perform additional experimental analysis.
 -- Press 'c' in visual mode to toggle the cursor mode
[0x00400700]> pdz
radare2: symbol lookup error: /home/angr/.local/share/radare2/plugins/core_retdec.so: undefined symbol: _ZNSt12experimental10filesystem2v119temp_directory_pathB5cxx11ERSt10error_code

Here's the bin:

challenge.zip

xkubov commented 4 years ago

As you use GCC 7 (mentioned in #11) the reason why you are getting runtime error is that the filesystem library was not linked during compilation (-lstdc++fs) and therefore standard function was not found. I dug into the changes between the GCC versions and found out that the requirement to explicitly link the stdc++fs library was removed only last year since version 9 (link to changes). This, however, means that anyone with GCC 8 (with support for C++17/filesystem) will get the same error as mentioned in here and this is surely not wanted. I think that the solution will be to link the library in the CMakeLists.txt anyway so that it won't cause the problem.

The reason why it crashed the r2 is that this is not a runtime treatable error and because this plugin is natively included in r2 it crashes the whole r2.

xkubov commented 4 years ago

I was able to test and fix this issue with GCC 8. Can you please rebase onto the latest master and test whether you are able to use pdz command successfully?

bannsec commented 4 years ago

It compiles and runs now. Thanks!

xkubov commented 4 years ago

Great! So as this is solved in https://github.com/avast/retdec-r2plugin/commit/4219cd5526b830b6c1698335fce84f10472a3832 I am closing this issue.

xkubov commented 4 years ago

I provided an addition for the commit https://github.com/avast/retdec-r2plugin/commit/4219cd5526b830b6c1698335fce84f10472a3832 (https://github.com/avast/retdec-r2plugin/commit/58a5389985391474f1c5eff90431301db66b62ba) because I have found out that the existence of the library (stdc++fs) is not enforced by the standard and newer clang/GCC might not have such library.

The result is that the cmake will try to locate the library and if found then link it to the resulting binary.