avast / retdec

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

retdec-llvmir2hll fails with "terminate called after throwing an instance of 'std::bad_alloc'" #232

Open Laerte opened 6 years ago

Laerte commented 6 years ago

I'm trying to decompile a file with 3.2MB size.

I closed all my applications and use: ulimit -Sv 9863168 to limit memory (i also try with 4GB), but everytime i get this error below, to run properly i need to get more ram or is there any way i optimize this to get the final C source?

Running phase: removing functions prefixed with [__decompiler_undefined_function_] ( 168.85s )
Running phase: removing functions from standard libraries ( 194.89s )
Running phase: removing code that is not reachable in a CFG ( 194.96s )
Warning: [NonRecursiveCFGBuilder] there is no node for an edge to `v5_405ddf = *(IntToPtrCastExpr<ptr>((v0_405e01 + 1)))` -> skipping this edge
Running phase: signed/unsigned types fixing ( 199.13s )
Running phase: converting LLVM intrinsic functions to standard functions ( 237.54s )
Running phase: obtaining debug information ( 240.46s )
Running phase: alias analysis [simple] ( 240.61s )
Running phase: optimizations [normal] ( 242.87s )
 -> running RemoveUselessCastsOptimizer ( 242.87s )
 -> running UnusedGlobalVarOptimizer ( 244.68s )
 -> running DeadLocalAssignOptimizer ( 247.27s )
Warning: out of memory; trying to recover
 -> running SimpleCopyPropagationOptimizer ( 281.59s )
Warning: [NonRecursiveCFGBuilder] there is no node for an edge to `v5_405ddf = *(IntToPtrCastExpr<ptr>((v0_405e01 + 1)))` -> skipping this edge
Warning: out of memory; trying to recover
 -> running CopyPropagationOptimizer ( 366.28s )
Warning: out of memory; trying to recover
 -> running AuxiliaryVariablesOptimizer ( 375.55s )
Warning: out of memory; trying to recover
 -> running SimplifyArithmExprOptimizer ( 378.81s )
Warning: out of memory; trying to recover
 -> running IfStructureOptimizer ( 379.43s )
Warning: out of memory; trying to recover
 -> running LoopLastContinueOptimizer ( 379.63s )
Warning: out of memory; trying to recover
 -> running PreWhileTrueLoopConvOptimizer ( 379.75s )
Warning: out of memory; trying to recover
 -> running WhileTrueToForLoopOptimizer ( 381.69s )
Warning: out of memory; trying to recover
 -> running WhileTrueToWhileCondOptimizer ( 381.69s )
Warning: out of memory; trying to recover
 -> running IfBeforeLoopOptimizer ( 381.70s )
Warning: out of memory; trying to recover
 -> running LLVMIntrinsicsOptimizer ( 381.70s )
Warning: out of memory; trying to recover
 -> running VoidReturnOptimizer ( 381.72s )
Warning: out of memory; trying to recover
 -> running BreakContinueReturnOptimizer ( 381.73s )
Warning: out of memory; trying to recover
 -> running BitShiftOptimizer ( 381.73s )
Warning: out of memory; trying to recover
 -> running DerefAddressOptimizer ( 381.74s )
Warning: out of memory; trying to recover
 -> running EmptyArrayToStringOptimizer ( 381.74s )
 -> running BitOpToLogOpOptimizer ( 381.74s )
Warning: out of memory; trying to recover
 -> running SimplifyArithmExprOptimizer ( 381.75s )
Warning: out of memory; trying to recover
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
0  retdec-llvmir2hll 0x000000000095a6ce
1  retdec-llvmir2hll 0x000000000095a81c
2  libpthread.so.0   0x00007fda3feaf390
3  libc.so.6         0x00007fda3ee3b428 gsignal + 56
4  libc.so.6         0x00007fda3ee3d02a abort + 362
5  libstdc++.so.6    0x00007fda3f77e84d _ZN9__gnu_cxx27__verbose_terminate_handlerEv + 365
6  libstdc++.so.6    0x00007fda3f77c6b6
7  libstdc++.so.6    0x00007fda3f77c701
8  libstdc++.so.6    0x00007fda3f77c919
9  libstdc++.so.6    0x00007fda3f77cebc
10 retdec-llvmir2hll 0x00000000005cc26f
11 retdec-llvmir2hll 0x00000000006f7ff6
12 retdec-llvmir2hll 0x0000000000680329
13 retdec-llvmir2hll 0x000000000067dfef
14 retdec-llvmir2hll 0x0000000000486b83
15 retdec-llvmir2hll 0x00000000004887ba
16 retdec-llvmir2hll 0x0000000000b46514
17 retdec-llvmir2hll 0x0000000000487c53
18 retdec-llvmir2hll 0x0000000000410691
19 libc.so.6         0x00007fda3ee26830 __libc_start_main + 240
20 retdec-llvmir2hll 0x00000000004805b9
Stack dump:
0.  Program arguments: /home/laerte/reverse/retdec-tool/bin/retdec-llvmir2hll -target-hll=c -var-renamer=readable -var-name-gen=fruit -var-name-gen-prefix= -call-info-obtainer=optim -arithm-expr-evaluator=c -validate-module -llvmir2bir-converter=orig -o /home/laerte/reverse/retdec-tool/bin/thor.c /home/laerte/reverse/retdec-tool/bin/thor.c.backend.bc -enable-debug -emit-debug-comments -config-path=/home/laerte/reverse/retdec-tool/bin/thor.c.json 
1.  Running pass 'Decompiler' on module '/home/laerte/reverse/retdec-tool/bin/thor.c.backend.bc'.
./retdec-decompiler.sh: linha 922:  6253 Abortado                "$LLVMIR2HLL" "${LLVMIR2HLL_PARAMS[@]}"
Error: Decompilation of file '/home/laerte/reverse/retdec-tool/bin/thor.c.backend.bc' failed

Setup:

Ubuntu 16.04.3 LTS Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz (4th Gen) 8GB ram

s3rvac commented 6 years ago

Hi. Would you be able to share with us the input binary? Otherwise, we can only point you to #13 and #16, which deal with insufficient-memory errors. You can also try selective decompilation to decompile only parts of the binary.

Laerte commented 6 years ago

@s3rvac I can share, but not into public, can i email directly to you?

s3rvac commented 6 years ago

Sure.

Laerte commented 6 years ago

The email from your user Github page?

s3rvac commented 6 years ago

Either that or the one I use for commits into this repo.

Laerte commented 6 years ago

Done, thanks! :)

Laerte commented 6 years ago

@s3rvac You got any update on this? Tks.

s3rvac commented 6 years ago

Unfortunately, no. We are dealing with other issues right now, and I am not sure when we get to this particular one.

kingpin22 commented 6 years ago

same problem. I have yet to decompile one reasonably sized program. Until this issue is fixed retdec is next to useless.

MerovingianByte commented 6 years ago

That was harsh. They have the best free decompiler, and their output is better than hex rays' when it works. Just be patient, you're not paying them you know.

kingpin22 commented 6 years ago

Who would pay for software that doesn't work.-

s3rvac commented 6 years ago

As I already wrote here, mindless RetDec bashing is not going to help anyone. What could help:

Anyway, if you do not like RetDec, just do not use it. It is that simple.