2. Contents
• Introduction
• Examples of base program
• Steps to de-compile java
• Input of the program
• Algorithm
• Output of the program
2
13-03-2015
3. 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-2015
3
4. 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-2015
4
5. Examples of base program
Consider the following example :
Public static int plus(int a, int b)
{
int c = a+b;
return c;
}
13-03-2015
5
6. • 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-2015
6
7. • If- else :
public int greaterThen(int intOne, int intTwo)
{
if (intOne > intTwo)
{
return 0;
}
else
{
return 1;
}
}
13-03-2015
7
14. • 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-2015
14
15. • Do- while :
public void doWhileLoop()
{
int i = 0;
do
{
i++;
}
while (i < 2);
}
13-03-2015
15
16. • 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-2015
16
17. • Try- catch block :
public void tryCatchCatchFinally(int i)
{
Try
{
i = 2;
}
catch (RuntimeException e)
{
i = 3;
}
finally
{
i = 4;
} }
13-03-2015
17
18. 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-2015
18