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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1. OBFUSCATION 19<br />

Then the relationship between A and B 1 and B 2 is given by the following rule:<br />

{<br />

B1 [f<br />

A[i] = 1 (i)] if ch(i)<br />

B 2 [f 2 (i)] otherwise<br />

To ensure that there are no index clashes we require that f 1 is injective for the<br />

values for which ch is true (similarly for f 2 ).<br />

This relationship can be generalised so that A could be split between more<br />

than two arrays. For this, ch should be regarded as a choice function — this<br />

will determine which array each element should be transformed to.<br />

We can write the transformation described in (1.3) as:<br />

{<br />

B1 [i div 2] if i is even<br />

A[i] =<br />

(1.4)<br />

B 2 [i div 2] if i is odd<br />

We will consider this obfuscation in much greater detail: in Section 2.3.7 we<br />

give a specification <strong>of</strong> this transformation and in Chapter 4 we apply splits to<br />

more general data-types.<br />

1.3.7 Program transformation<br />

We now show how we can transform a method using example (1.4) above. The<br />

statement A[i] = V is transformed to:<br />

if ((i%2) == 0) {B 1 [i/2] = V ; } else {B 2 [i/2] = V ; } (1.5)<br />

and an occurrence <strong>of</strong> A[i] on the right hand side <strong>of</strong> an assignment can be dealt<br />

with in a similar manner by substituting either B 1 [i/2] or B 2 [i/2] for A[i].<br />

As a simple example, we present an imperative program for finding the first<br />

n Fibonacci numbers:<br />

A[0] = 0;<br />

A[1] = 1;<br />

i = 2;<br />

while (i ≤ n)<br />

{ A[i] = A[i−1] + A[i−2];<br />

i + +;<br />

}<br />

In this program, we can easily spot the Fibonacci identity:<br />

fib(0) = 0<br />

fib(1) = 1<br />

fib(n) = fib(n−1) + fib(n−2) (∀n ≥ 2)<br />

Let us now obfuscate the array by using the rules above. We obtain the<br />

program shown in Figure 1.1 which, after some simplifications, becomes:<br />

B 1 [0] = 0;<br />

B 2 [0] = 1;<br />

i = 2;<br />

while (i ≤ n)<br />

{ if (i %2 == 0) B 1 [i/2] = B 2 [(i − 1)/2] + B 1 [(i − 2)/2];<br />

else B 2 [i/2] = B 1 [(i − 1)/2] + B 2 [(i − 2)/2];<br />

i + +;<br />

}

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

Saved successfully!

Ooh no, something went wrong!