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 23<br />

add<br />

beq.s l<br />

bge.s l<br />

bgt.s l<br />

ble.s l<br />

blt.s l<br />

bne.s l<br />

br.s l<br />

call<br />

div<br />

dup<br />

ldarg.s v<br />

ldc.t v<br />

ldloc.s v<br />

mul<br />

rem<br />

ret<br />

sub<br />

starg.s v<br />

stloc.s v<br />

Adds the top two elements <strong>of</strong> the stack<br />

Branches to l on equality<br />

Branches to l on greater than or equal to<br />

Branches to l on greater than<br />

Branches to l on less than or equal to<br />

Branches to l on less than<br />

Branches to l on not equal<br />

Unconditional branch to l<br />

Calls a method<br />

Divides the top two elements <strong>of</strong> the stack<br />

Duplicates the top value <strong>of</strong> the stack<br />

Pushes value <strong>of</strong> argument v onto the stack<br />

Pushes a constant v with type t onto the stack<br />

Pushes value <strong>of</strong> variable v onto the stack<br />

Multiplies the top two elements <strong>of</strong> the stack<br />

Calculates the remainder when dividing<br />

Returns from a method<br />

Subtracts the top two elements <strong>of</strong> the stack<br />

Pops a value and stores it in argument v<br />

Pops a value and stores it into v<br />

Figure 2.1: Some common IL instructions<br />

Figure 2.1. As an example, consider the following C# method which computes<br />

the GCD <strong>of</strong> two integers:<br />

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

{<br />

int x = a;<br />

int y = b;<br />

while (x !=y)<br />

if (x < y) y = y − x; else x = x − y;<br />

return x;<br />

}<br />

After compiling and disassembling this method, we obtain the IL code shown<br />

in Figure 2.2.<br />

As IL is a typed stack language, each value handled by the stack must have<br />

a type associated with it. For example, int32 is the type for 4-byte (32-bit)<br />

integers andfloat64 for 8-byte real numbers — number types can also be signed<br />

or unsigned. Non numeric types include string and bool.<br />

At the start <strong>of</strong> a method, various properties <strong>of</strong> the method are stated. First,<br />

the signature <strong>of</strong> the method is given. In the GCD example, we can see that the<br />

method expects two integers and returns one integer as the result. Next, the<br />

maximum stack depth in the method is specified by using the .maxstack keyword.<br />

If we make any changes to the IL code then we should check whether the<br />

maximum stack depth has increased and so must change the value <strong>of</strong>.maxstack<br />

accordingly. Finally the names and types <strong>of</strong> any local variables for this method<br />

are stated using the .locals keyword.

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

Saved successfully!

Ooh no, something went wrong!