Giter VIP home page Giter VIP logo

ddisasm's Introduction

Datalog Disassembly

A fast disassembler which is accurate enough for the resulting assembly code to be reassembled. The disassembler implemented using the datalog (souffle) declarative logic programming language to compile disassembly rules and heuristics. The disassembler first parses ELF file information and decodes a superset of possible instructions to create an initial set of datalog facts. These facts are analyzed to identify code location, symbolization, and function boundaries. The results of this analysis, a refined set of datalog facts, are then translated to the GTIRB intermediate representation for binary analysis and reverse engineering. The GTIRB pretty printer may then be used to pretty print the GTIRB to reassemblable assembly code.

Introduction

The analysis contains two parts:

  • The C++ files take care of reading an elf file and generating facts that represent all the information contained in the binary.

  • src/datalog/*.dl contains the specification of the analyses in datalog. It takes the basic facts and computes likely EAs, chunks of code, etc. The results are represented in GTIRB or can be printed to assembler code using the gtirb-pprinter.

Dependencies

  • GTIRB

  • The analysis depends on souffle being installed. Configure souffle with --enable-64bit-domain --disable-provenance.

  • For printing assembler code the datalog disassembler requires the gtirb-pprinter

Building ddisasm

A C++17 compiler such as gcc 7 or clang 6 is required.

Boost (1.59 or later) and GTIRB are required.

Use the following options to configure cmake:

  • You can tell CMake which compiler to use with -DCMAKE_CXX_COMPILER=<compiler>.

  • Normally CMake will find GTIRB automatically, but if it does not you can pass -Dgtirb_DIR=<path-to-gtirb-build>.

Once the dependencies are installed, you can configure and build as follows:

$ cmake ./ -Bbuild
$ cd build
$ make

Running the analysis

Once ddisasm is built, we can run complete analysis on a file by calling /bin/ddisasm'. For example, we can run the analysis on one of the examples as follows:

cd build/bin ./ddisasm ../../examples/ex1/ex --asm ex.s

The script accepts the following parameters:

--help : produce help message

--sect arg (=.plt.got,.fini,.init,.plt,.text,) : code sections to decode

--data_sect arg (=.data,.rodata,.fini_array,.init_array,.data.rel.ro,.got.plt,.got,) : data sections to consider

--ir arg : GTIRB output file

--asm arg : ASM output file

--debug-dir arg : location to write CSV files for debugging

Rewriting a project

The directory bin/ contains several scripts to rewrite and test complete projects:

  • reassemble_and_test.sh rebuilds a project using the compiler and compiler flags specified in the enviroment variables CC and CFLAGS, rewrites the binary and run the project tests on the new binary.

  • CGC_reassemble_and_test.sh does the analogous process but with CGC projects. However, it receives the compiler and compiler flags as arguments

  • reassemble_no_rebuild.sh rewrites a binary without trying to rebuild the project before and without running tests later.

Testing

The directory tests/ also contains script for running extensive tests:

  • test_coreutils.sh test coreutils with different compilers and optimization flags.

  • test_real_examples.sh test a list of real world applications with different compilers and optimization flags.

  • test_CGC.sh test a subset of the CGC programs with different compilers and optimization flags.

References

  1. Souffle: "On fast large-scale program analysis in Datalog" CC2016

  2. Porting Doop from LogicBlox to souffle

  3. Control Flow Integrity for COTS Binaries

  4. Alias analysis for Assembly by Brumley at CMU: http://reports-archive.adm.cs.cmu.edu/anon/anon/usr/ftp/2006/CMU-CS-06-180R.pdf

  5. Reassembleable Disassembling

  6. Ramblr: Making disassembly great again

  7. An In-Depth Analysis of Disassembly on Full-Scale x86/x64 Binaries

  8. Binary Code is Not Easy

ddisasm's People

Contributors

aeflores avatar eschulte avatar jdorn-gt avatar

Watchers

Anton Kochkov avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.