RetDec: An Open-Source Machine-Code Decompiler
Jakub Kˇ roustek Peter Matula Petr Zemek Threat Labs
Botconf 2017 1 / 51
RetDec: An Open-Source Machine-Code Decompiler Jakub K roustek - - PowerPoint PPT Presentation
RetDec: An Open-Source Machine-Code Decompiler Jakub K roustek Peter Matula Petr Zemek Threat Labs Botconf 2017 1 / 51 > whoarewe Jakub K roustek founder of RetDec Threat Labs lead @Avast (previously @AVG) reverse
Jakub Kˇ roustek Peter Matula Petr Zemek Threat Labs
Botconf 2017 1 / 51
♂ Jakub Kˇ roustek
Botconf 2017 2 / 51
♂ Jakub Kˇ roustek
♂ Peter Matula
Botconf 2017 2 / 51
Botconf 2017 3 / 51
Botconf 2017 4 / 51
Botconf 2017 5 / 51
Botconf 2017 6 / 51
Botconf 2017 7 / 51
Botconf 2017 8 / 51
Binary analysis
Botconf 2017 9 / 51
Binary analysis
Binary recompilation (yeah, like that’s ever gonna work)
Botconf 2017 9 / 51
Botconf 2017 10 / 51
Botconf 2017 10 / 51
Botconf 2017 10 / 51
Botconf 2017 10 / 51
Botconf 2017 10 / 51
Botconf 2017 10 / 51
Botconf 2017 11 / 51
Botconf 2017 11 / 51
, PE, Mach-O, . . .
Botconf 2017 11 / 51
, PE, Mach-O, . . .
Botconf 2017 11 / 51
, PE, Mach-O, . . .
Botconf 2017 11 / 51
, PE, Mach-O, . . .
Botconf 2017 11 / 51
, PE, Mach-O, . . .
Botconf 2017 11 / 51
◎ Goal
Botconf 2017 12 / 51
◎ Goal
History
(AVG + BUT FIT via TA ˇ CR TA01010667 grant)
(AVG + BUT FIT students via diploma theses)
(Avast + BUT FIT students)
Botconf 2017 12 / 51
◎ Goal
History
(AVG + BUT FIT via TA ˇ CR TA01010667 grant)
(AVG + BUT FIT students via diploma theses)
(Avast + BUT FIT students)
People
3-4 core developers ≈ 20 BSc/MSc/PhD students
Botconf 2017 12 / 51
◎ Goal
History
(AVG + BUT FIT via TA ˇ CR TA01010667 grant)
(AVG + BUT FIT students via diploma theses)
(Avast + BUT FIT students)
People
3-4 core developers ≈ 20 BSc/MSc/PhD students
Lines of code
419,451 code 205,222 comments, etc. + 624,673 total
Botconf 2017 12 / 51
Supports
, PE, COFF , Mach-O, Intel HEX, AR, raw
Botconf 2017 13 / 51
Supports
, PE, COFF , Mach-O, Intel HEX, AR, raw
Does
Botconf 2017 13 / 51
Supports
, PE, COFF , Mach-O, Intel HEX, AR, raw
Does
Runs on (hopefully)
Botconf 2017 13 / 51
RetDec goes open-source under the MIT license
Botconf 2017 14 / 51
RetDec goes open-source under the MIT license
Repositories
11 core 6 support 8 third party
Contacts
https://retdec.com/ https://github.com/avast-tl https://twitter.com/retdec https://retdec.com/rss/ info@retdec.com
Botconf 2017 14 / 51
Botconf 2017 15 / 51
Botconf 2017 16 / 51
Botconf 2017 17 / 51
Botconf 2017 18 / 51
Botconf 2017 19 / 51
Botconf 2017 19 / 51
Botconf 2017 19 / 51
Botconf 2017 19 / 51
Botconf 2017 19 / 51
Botconf 2017 19 / 51
Botconf 2017 19 / 51
Botconf 2017 19 / 51
Botconf 2017 20 / 51
Botconf 2017 20 / 51
Fileformat
Botconf 2017 21 / 51
Fileformat
PeLib
Botconf 2017 21 / 51
Fileformat
PeLib
ELFIO
Botconf 2017 21 / 51
Fileformat
PeLib
ELFIO
PDBparser
Botconf 2017 21 / 51
Fileformat
PeLib
ELFIO
PDBparser
Yaracpp
Botconf 2017 21 / 51
Botconf 2017 22 / 51
Botconf 2017 22 / 51
Botconf 2017 22 / 51
Botconf 2017 22 / 51
loop optimization, memory promotion, dead store elimination, . . .
Botconf 2017 23 / 51
loop optimization, memory promotion, dead store elimination, . . .
Botconf 2017 23 / 51
@global = global i32 define i32 @fnc(i32 %arg) { %x = load i32, i32* @global %y = add i32 %x, %arg store i32 %y, @global return i32 %y }
Botconf 2017 24 / 51
@global = global i32 define i32 @fnc(i32 %arg) { %x = load i32, i32* @global %y = add i32 %x, %arg store i32 %y, @global return i32 %y }
Botconf 2017 24 / 51
@global = global i32 define i32 @fnc(i32 %arg) { %x = load i32, i32* @global %y = add i32 %x, %arg store i32 %y, @global return i32 %y }
Botconf 2017 24 / 51
Botconf 2017 25 / 51
Botconf 2017 25 / 51
Botconf 2017 25 / 51
Botconf 2017 25 / 51
Botconf 2017 25 / 51
Botconf 2017 25 / 51
Botconf 2017 25 / 51
Botconf 2017 25 / 51
Botconf 2017 26 / 51
Botconf 2017 26 / 51
Botconf 2017 26 / 51
if (OperandSize == 64) { //PMULHUW instruction with 64-bit operands: Tmp0[0..31] = Dst[0..15] * Src[0..15]; Tmp1[0..31] = Dst[16..31] * Src[16..31]; Tmp2[0..31] = Dst[32..47] * Src[32..47]; Tmp3[0..31] = Dst[48..63] * Src[48..63]; Dst[0..15] = Tmp0[16..31]; Dst[16..31] = Tmp1[16..31]; Dst[32..47] = Tmp2[16..31]; Dst[48..63] = Tmp3[16..31]; } else { //PMULHUW instruction with 128-bit operands: // Even longer ... }
__asm_PMULHUW(mm1, mm2);
Botconf 2017 25 / 51
Botconf 2017 26 / 51
Botconf 2017 26 / 51
emulator), keeping LLVM IR ↔ ASM mapping, . . .
Botconf 2017 26 / 51
emulator), keeping LLVM IR ↔ ASM mapping, . . .
Botconf 2017 26 / 51
Botconf 2017 27 / 51
Botconf 2017 27 / 51
Botconf 2017 28 / 51
Botconf 2017 29 / 51
RetDec
Botconf 2017 30 / 51
RetDec
Capstone2LlvmIR
Botconf 2017 30 / 51
RetDec
Capstone2LlvmIR
Capstone-dumper
Botconf 2017 30 / 51
RetDec
Capstone2LlvmIR
Capstone-dumper
Fnc-patterns
Botconf 2017 30 / 51
RetDec
Capstone2LlvmIR
Capstone-dumper
Fnc-patterns
Yaramod
Botconf 2017 30 / 51
RetDec
Capstone2LlvmIR
Capstone-dumper
Fnc-patterns
Yaramod
Ctypes
Botconf 2017 30 / 51
RetDec
Capstone2LlvmIR
Capstone-dumper
Fnc-patterns
Yaramod
Ctypes
Demangler
Botconf 2017 30 / 51
Botconf 2017 31 / 51
Botconf 2017 31 / 51
Botconf 2017 31 / 51
Botconf 2017 32 / 51
Botconf 2017 33 / 51
Botconf 2017 33 / 51
Botconf 2017 33 / 51
Botconf 2017 33 / 51
Botconf 2017 33 / 51
Botconf 2017 33 / 51
Botconf 2017 33 / 51
Botconf 2017 34 / 51
⇒ a + 3
Botconf 2017 34 / 51
⇒ a + 3
⇒ if (a != b)
Botconf 2017 34 / 51
⇒ a + 3
⇒ if (a != b)
⇒ a[4]
Botconf 2017 34 / 51
⇒ a + 3
⇒ if (a != b)
⇒ a[4]
Botconf 2017 34 / 51
⇒ a + 3
⇒ if (a != b)
⇒ a[4]
Botconf 2017 34 / 51
⇒ a + 3
⇒ if (a != b)
⇒ a[4]
Botconf 2017 34 / 51
Botconf 2017 35 / 51
Botconf 2017 35 / 51
sock_id = socket(PF_INET, SOCK_RAW, IPPROTO_RAW)
Botconf 2017 35 / 51
sock_id = socket(PF_INET, SOCK_RAW, IPPROTO_RAW)
flock(sock_id, LOCK_SH | LOCK_EX | LOCK_NB)
Botconf 2017 35 / 51
sock_id = socket(PF_INET, SOCK_RAW, IPPROTO_RAW)
flock(sock_id, LOCK_SH | LOCK_EX | LOCK_NB)
Botconf 2017 35 / 51
RetDec
Botconf 2017 36 / 51
Online decompilation service
https://retdec.com/decompilation/
Botconf 2017 37 / 51
Online decompilation service
https://retdec.com/decompilation/
REST API
https://retdec.com/api/
Botconf 2017 37 / 51
Online decompilation service
https://retdec.com/decompilation/
REST API
https://retdec.com/api/
Build it yourself
CMake, gcc/Clang, Visual Studio 2015 Update 2 Perl, GNU Bison, Flex, GNU Tar, scp, GNU bash, UPX, dot Recursively clone the main RetDec repository mkdir build && cd build cmake .. make && make install
Botconf 2017 37 / 51
Online decompilation service
https://retdec.com/decompilation/
REST API
https://retdec.com/api/
Build it yourself
CMake, gcc/Clang, Visual Studio 2015 Update 2 Perl, GNU Bison, Flex, GNU Tar, scp, GNU bash, UPX, dot Recursively clone the main RetDec repository mkdir build && cd build cmake .. make && make install
Run it yourself
decompile.sh binary.exe
Botconf 2017 37 / 51
Online decompilation service
https://retdec.com/decompilation/
REST API
https://retdec.com/api/
Build it yourself
CMake, gcc/Clang, Visual Studio 2015 Update 2 Perl, GNU Bison, Flex, GNU Tar, scp, GNU bash, UPX, dot Recursively clone the main RetDec repository mkdir build && cd build cmake .. make && make install
Run it yourself
decompile.sh binary.exe
Get RetDec IDA plugin
Botconf 2017 37 / 51
Botconf 2017 38 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
◎ Goals
look & feel native same object names as IDA interactive
Botconf 2017 39 / 51
Botconf 2017 40 / 51
retdec.com launched on 2015-02-05
Botconf 2017 41 / 51
retdec.com launched on 2015-02-05 12,000 registered users
Botconf 2017 41 / 51
retdec.com launched on 2015-02-05 12,000 registered users 423,000 decompilations
350,000 Web 73,000 API
| 410 decompilations daily
Botconf 2017 41 / 51
Botconf 2017 42 / 51
Botconf 2017 43 / 51
Botconf 2017 44 / 51
Botconf 2017 45 / 51
system sleep flock fork fread gettimeofday fopen srand fclose strcmp exit fileno function_404810 xDec function_404b1c main backup Daemonize RSeed getip ip2c fetch snprintf strncmp strncpy strlen parse
Botconf 2017 46 / 51
Botconf 2017 47 / 51
interactive seamlessly integrated mature many plugins
Botconf 2017 47 / 51
interactive seamlessly integrated mature many plugins
not free proprietary big monolithic GUI app
Botconf 2017 47 / 51
it is free + MIPS architecture MIT license you can play with the sources
Botconf 2017 48 / 51
it is free + MIPS architecture MIT license you can play with the sources
LLVM is awesome
Botconf 2017 48 / 51
it is free + MIPS architecture MIT license you can play with the sources
LLVM is awesome different basic designs: interactive GUI vs. pipeline
Botconf 2017 48 / 51
it is free + MIPS architecture MIT license you can play with the sources
LLVM is awesome different basic designs: interactive GUI vs. pipeline LLVM is OP (don’t worry, it won’t be nerfed)
Botconf 2017 48 / 51
RetDec – the decompiler RetDec IDA plugin – Hex-Rays impersonation
Botconf 2017 49 / 51
RetDec – the decompiler RetDec IDA plugin – Hex-Rays impersonation Fileformat – generic OFF parsing and analysis Capstone2LlvmIR – binary to LLVM translation Fnc-patterns – statically linked code detection in YARA (IDA F .L.I.R.T.) Yaramod – hack YARA rules in C++ Yaracpp – YARA C++ wrapper Ctypes – info on function types
Botconf 2017 49 / 51
Botconf 2017 50 / 51
Botconf 2017 50 / 51
Botconf 2017 50 / 51
Botconf 2017 50 / 51
Botconf 2017 50 / 51
Botconf 2017 50 / 51
Botconf 2017 50 / 51
Contacts
https://retdec.com/ https://github.com/avast-tl https://twitter.com/retdec https://retdec.com/rss/ info@retdec.com
Botconf 2017 51 / 51