23.11.2013 Views

Obfuscation of Abstract Data-Types - Rowan

Obfuscation of Abstract Data-Types - Rowan

Obfuscation of Abstract Data-Types - Rowan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 2. OBFUSCATIONS FOR INTERMEDIATE LANGUAGE 27<br />

gcd(int a, int b)<br />

{ int i;<br />

int j;<br />

i = a;<br />

j = b;<br />

if (i * i > 0) {goto IL001a;}<br />

else {goto IL0016;}<br />

IL000c: if (i < j) {j -= i; continue;}<br />

IL0016: i -= j;<br />

IL001a: if (i == j) {return i;}<br />

else {goto IL000c;}<br />

}<br />

Figure 2.3: Output from Salamander<br />

However in IL, we are allowed to use branches to jump into loops (while<br />

loops do not, <strong>of</strong> course, occur in IL — they are achieved by using conditional<br />

branches). So, if we insert this kind <strong>of</strong> jump in IL, we will have a control flow<br />

graph which is irreducible and a naive decompiler could produce incorrect C#<br />

code. A smarter decompiler could change the while into an if statement that<br />

uses goto jumps. As we do not actually want this jump to happen, we use an<br />

opaque predicate that is always false.<br />

Let us look at the GCD example in Section 2.1.1 again. Suppose that we<br />

want to insert the jump:<br />

if ((x ∗ x) < 0) goto L;<br />

before the while loop where L is a statement in the loop. So, we need to put<br />

instructions in the IL file to create this:<br />

IL0100: ldloc.0<br />

IL0101: ldloc.0<br />

IL0102: mul<br />

IL0103: ldc.i4.0<br />

IL0104: blt.s IL0010<br />

The place that we jump to in the IL needs to be chosen carefully — a<br />

suitable place in the GCD example would be between the instructions IL0003<br />

and IL0004. We must (obviously) ensure that it does actually jump to a place<br />

inside the while loop. Also, we must ensure that we do not interfere with the<br />

depth <strong>of</strong> the stack (so that we can still verify the program). Figure 2.3 shows the<br />

result <strong>of</strong> decompiling the resulting executable using the Salamander decompiler<br />

[45]. We can see that the while statement has been removed and in its place is<br />

a more complicated arrangement <strong>of</strong> ifs and gotos.<br />

This obfuscation as it stands is not very resilient. It is obvious that the<br />

conditional x ∗ x < 0 can never be true and so the jump into the loop never<br />

happens.<br />

2.3 Transformation Toolkit<br />

In the last section we saw writing obfuscations for IL involved finding appropriate<br />

instructions and replacing all occurrences <strong>of</strong> these instructions by a set <strong>of</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!