avast / retdec

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

Error: Decompilation to LLVM IR failed #740

Open cmmpsantos opened 4 years ago

cmmpsantos commented 4 years ago

Hi there. I know that this error is there in more places. But I'm new to this tool and I wonder I can't decomplile a 875Kb file having 16Gig of RAM! I'm using Arch Linux, I installed retdec from the AUR using the git version. This is the output I get:

$ retdec-decompiler.py -a arm --no-memory-limit -o lib.c lib.so     
##### Checking if file is a Mach-O Universal static library...

##### Checking if file is an archive...
RUN: /usr/bin/retdec-ar-extractor /.../lib.so --arch-magic
Not an archive, going to the next step.

##### Gathering file information...
RUN: /usr/bin/retdec-fileinfo -c /.../lib.config.json --similarity /.../lib.so --no-hashes=all --crypto /usr/bin/../share/retdec/support/generic/yara_patterns/signsrch/signsrch.yara --crypto /usr/bin/../share/retdec/support/generic/yara_patterns/signsrch/signsrch.yarac
Input file               : /.../lib.so
File format              : ELF
File class               : 32-bit
File type                : DLL
Architecture             : ARM
Endianness               : Little endian
Detected tool            : gold (1.12) (linker), .note section heuristic
Detected tool            : GCC (4.9) (compiler), .comment section heuristic
Original language        : C++

##### Trying to unpack /.../lib.so into /.../li.tmp by using generic unpacker...
RUN: /usr/bin/retdec-unpacker /.../jni/armeabi-v7a/lib.so -o /.../jni/armeabi-v7a/lib-unpacked.tmp
No matching plugins found for 'gold 1.12'
No matching plugins found for 'GCC 4.9'
##### Unpacking by using generic unpacker: nothing to do

##### Trying to unpack /.../jni/armeabi-v7a/lib.so into /.../jni/armeabi-v7a/lib-unpacked.tmp by using UPX...
RUN: upx -d /.../jni/armeabi-v7a/lib.so -o /.../jni/armeabi-v7a/lib-unpacked.tmp
upx: /.../jni/armeabi-v7a/lib.so: NotPackedException: not packed by UPX
##### Unpacking by using UPX: nothing to do

##### Decompiling /.../jni/armeabi-v7a/lib.so into /.../jni/armeabi-v7a/lib.bc...
RUN: /usr/bin/retdec-bin2llvmir -provider-init -decoder -verify -x86-addr-spaces -x87-fpu -main-detection -idioms-libgcc -inst-opt -cond-branch-opt -syscalls -stack -constants -param-return -inst-opt-rda -inst-opt -simple-types -generate-dsm -remove-asm-instrs -class-hierarchy -select-fncs -unreachable-funcs -inst-opt -register-localization -value-protect -instcombine -tbaa -basicaa -simplifycfg -early-cse -tbaa -basicaa -globalopt -mem2reg -instcombine -simplifycfg -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -instcombine -simplifycfg -reassociate -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -instcombine -loop-simplifycfg -loop-simplify -aa -loop-accesses -loop-load-elim -lcssa -indvars -loop-idiom -loop-deletion -gvn -sccp -instcombine -lazy-value-info -jump-threading -correlated-propagation -dse -bdce -adce -simplifycfg -instcombine -strip-dead-prototypes -globaldce -constmerge -constprop -instcombine -instcombine -tbaa -basicaa -simplifycfg -early-cse -tbaa -basicaa -globalopt -mem2reg -instcombine -simplifycfg -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -instcombine -simplifycfg -reassociate -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -instcombine -loop-simplifycfg -loop-simplify -aa -loop-accesses -loop-load-elim -lcssa -indvars -loop-idiom -loop-deletion -gvn -sccp -instcombine -lazy-value-info -jump-threading -correlated-propagation -dse -bdce -adce -simplifycfg -instcombine -strip-dead-prototypes -globaldce -constmerge -constprop -instcombine -inst-opt -simple-types -stack-ptr-op-remove -idioms -instcombine -inst-opt -idioms -remove-phi -value-protect -sink -config-path /.../jni/armeabi-v7a/lib.config.json -o /.../jni/armeabi-v7a/lib.bc
Running phase: Initialization ( 0.01s )
Running phase: LLVM ( 0.01s )
Running phase: Providers initialization ( 0.01s )
Running phase: Input binary to LLVM IR decoding ( 0.08s )
Running phase: LLVM ( 61.50s )
Running phase: x86 address spaces optimization ( 61.68s )
Running phase: x87 fpu register analysis ( 61.68s )
Running phase: Main function identification optimization ( 61.68s )
Running phase: Libgcc idioms optimization ( 61.68s )
Running phase: LLVM instruction optimization ( 61.73s )
Running phase: Conditional branch optimization ( 61.81s )
Error: Decompilation to LLVM IR failed

Is there any option to make retdec to use less memory, even losing some readability? Why does it takes so much memory? It stopped when my system was already using around 15Gib of RAM...

Thanks Carlos

PeterMatula commented 4 years ago

Is there any option to make retdec to use less memory, even losing some readability?

Not in this phase (retdec-bin2llvmir). Only in the backend (retdec-llvmir2hll). This phase should not be that slow and memory consuming, unless the input is truly huge. Something probably went wrong. Can you share the input library? I would try to debug it.

cmmpsantos commented 4 years ago

Sure... libnexgo_gencode.zip

Thank you.