Post

Decompiler Construction: Chapter 18 - Practical Decompilation Results and Pipeline Evaluation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdint.h>
volatile int32_t sink;
typedef struct {
    int32_t a; int32_t b; int32_t c;
} Node;
int32_t func(int32_t *arr, const Node *n, const int32_t x) {
	
    int32_t acc = 0;
    int32_t i = 0;
    int32_t state = (x ^ 0x5A) + (n->a << 1);
    while (i < 10) {
        state = state ^ (i * 3);
        if ((state & 1) == 0) { acc += arr[i] + n->b; } else { acc += arr[i] ^ n->c; }
        if (acc > 100) { break; }
        ++i;
        if (!(i % 3)) { continue; }
        state = (state << 1) | (state >> 31);
    }
    int32_t tmp = acc * 2;
    tmp = tmp - acc;
    if (x < 0) { tmp = tmp ^ 0xDEADBEEF; }
    sink = tmp;
    return acc + state;
}
int32_t main(void) {
    int32_t arr = 9;
    for (int32_t t = 0; t < 1000; ++t) { 
        Node n = { .a = t, .b = t ^ 0xAA, .c = t + 3};  func(&arr, &n, 19); }
    return 0;
}

Prev Chapter: Chapter 17 - Lowering IR to Readable and Executable Code

This post is licensed under CC BY 4.0 by the author.