T247 : Type-Directed Decompilation of Disjoint Unions

Supervision:
Contact person: Tom Schrijvers
Supervisor(s): Tom Schrijvers
Daily advisor(s): Tom Schrijvers
Research group:
Declarative Languages and Artificial Intelligence
Context:

Reconstructing the meaning of a program from its binary executable is known as reverse engineering (or reversing for short); it has a wide range of applications in software security, exposing piracy, legacy systems, etc. Since reversing is ultimately a search for meaning, there is much interest in inferring a type (a meaning) for the elements of a binary in a consistent way. Unfortunately existing approaches do not guarantee any semantic relevance for their reconstructed types.

Together with partners at the University of Kent (UK) we have recently developed a new and semantically-founded approach that provides strong guarantees about the reconstructed types. Key to our approach is the derivation of a witness program in a high-level language alongside the reconstructed types. This witness has the same semantics as the binary, is type correct by construction, and it induces a (justifiable) type assignment on the binary. Moreover, the approach effectively yields a type-directed decompiler. We formalise and implement the approach for reversing MinX, an abstraction of x86, to MinC, a type-safe dialect of C with recursive datatypes. Our evaluation compiles a range of textbook C algorithms to MinX and then recovers the original structures.

For example, the following MinX program:

iterative_sum {
  mov4 r0, 0 ;
  goto .BB1 
.BB0: 
  mov4 r2, [r1] ; 
  add4 r0, r2 ;
  mov4 r1, [r1 + 4] ;
.BB1:
  if4 r1 goto .BB0 ;
  ret
} <(r1), r0, (r2)>

is decompiled to:

struct struct1 {
   long;
   struct1*; 
}; 

iterative_sum(struct1* x) {
  long y1, y2
0:
  y1 = 0;
  goto 2
1:
  y2 = x->0;
  y1 = y1 + y2;
  x = x->1;
2:
  if x goto 1;
  return y1
}

Our approach is currently restricted to primitive types, pointer types and C-style structs.

Aim:

Extend our approach with support for decompiling disjoint union types.

Disjoint union types bring together different alternative data representations under one type. In C they are known as tagged unions. E.g.,

enum ShapeKind { Square, Rectangle, Circle };
struct Shape {
   enum ShapeKind kind;
   union {
      struct { int side; }; /* Square */
      struct { int length, height; }; /* Rectangle */
      struct { int radius; }; /* Circle */
   };
};
 

In high-level functional languages like Haskell, they are known as algebraic data types. E.g.,

data Shape = Square Int | Rectangle Int Int | Circle Int

Possible research questions:
  • How to decompile disjoint union types?
Approach:
  • Study relevant literature.
  • Devise a decompilation approach.
  • Formalise the approach and implement it.
  • Evaluate the effectiveness of the approach.
Relevant literature:
Student profile:
  • Convinced that theory and practice should go hand-in-hand.
  • Strong penchant for compilers and programming languages.
  • Possibly interested in a PhD.

This topic is for 1 student(s).

This topic can be selected by

  • all Master in de Ingenieurswetenschappen: Computerwetenschappen (ir) students
  • all Master of Engineering: Computer Science students

Clusters, in which this topic appears:
  • Secure Software
  • Programming Languages
18-07-2008