Post on 15-Jul-2015
Contents• Introduction
• Examples of base program
• Steps to de-compile java
• Input of the program
• Algorithm
• Output of the program
2
13
-03
-20
15
Introduction
• A de-compiler is a computer program that performs the reverse operation to that of
a compiler.
• The term de-compiler is most commonly applied to a program which translates
executable programs (the output from a compiler) into source code in a high level
language, when compiled, will produce an executable whose behavior is the same as
the original executable program.
13
-03
-20
15
3
Steps to de-compilation
• Parse Java class file
• Recreate signatures
• Convert byte code to Java executable code
Verify byte code
Perform trivial conversion
Reconstruct control structures
Scope & Type Variables
• Simplify code
13
-03
-20
15
4
Examples of base program
Consider the following example :
Public static int plus(int a, int b)
{
int c = a+b;
return c;
}
13
-03
-20
15
5
• Byte code :
Public static int plus(int, int)
Code :
Stack=2, locals=3, arguments =2;
0 : iload_0 // load int a
1 : iload_1 // load int b
2 :
13
-03
-20
15
6
• If- else :
public int greaterThen(int intOne, int intTwo)
{
if (intOne > intTwo)
{
return 0;
}
else
{
return 1;
}
}
13
-03
-20
15
7
• The above method results in following byte code :
• 0: iload_1
• 1: iload_2
• 2: if_icmple 7
• 5: iconst_0
• 6: ireturn
• 7:iconst_1
• 8: ireturn
13
-03
-20
15
8
• Switch :
public int simpleSwitch(int intOne)
{
switch (intOne)
{
case 0: return 3;
case 1: return 2;
case 4: return 1;
default: return -1;
}
}
13
-03
-20
15
9
• The above code produces following byte code :
0: iload_1
1: tableswitch
{
default: 42
min: 0
max: 4
0: 36
1: 38
2: 42
3: 42
4: 40
}
13
-03
-20
15
10
36: iconst_3
37: ireturn
38: iconst_2
39: ireturn
40: iconst_1
41: ireturn
42: iconst_m1
43: ireturn
13
-03
-20
15
11
• The above code produces following byte code :
0: iconst_0
1: istore_1
2: iload_1
3: iconst_2
4: if_icmpge 13
7: iinc 1, 1
10: goto 2
13: return
13
-03
-20
15
13
• For loop :
public void forLoop()
{
for(int i = 0; i < 2; i++)
{
}
}
The byte code produced by the for loop is similar to while loop.
13
-03
-20
15
14
• The above code generates the following byte code :
0: iconst_0
1: istore_1
2: iinc 1, 1
5: iload_1
6: iconst_2
7: if_icmplt 2
10: return
13
-03
-20
15
16
• Try- catch block :public void tryCatchCatchFinally(int i){ Try{i = 2; }catch (RuntimeException e){i = 3;} finally {i = 4;} }
13
-03
-20
15
17
Input of the program
• Input of the program is the byte code generated by Java Virtual Machine(JVM).
Consider the following byte code :
0: iload_0
1: iload_1
2: iadd
3: istore_2
4 : iload_2
5 : return
13
-03
-20
15
18
Output of the program
• The output of the de-complied byte code is java source code .
13
-03
-20
15
20