Java Decompiler.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
CSCI 160 Midterm Review Rasanjalee DM.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
1 InTroToJCL Introduction to Java Class Loaders. 2 class loader l ia an object responsible for loading classes. The class ClassLoader is an abstract class.
Copyright © 2001 Qusay H. Mahmoud Case Study A Global Compute Engine Here we will discuss some implementation details: – Class Loaders – Compute Engine.
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 6 Decision Making, Control Structures & Error Handling.
The Java Programming Language
Midterm II ICS111. Two Classes used to read user input 1.Scanner 2.BufferedReader 3.StringReader 4.1 and and 3.
1 Lecture 24 Abstract Data Types (ADT) –I Overview  What is an Abstract Data type?  What is Stack ADT?  Stack ADT Specifications  Array Implementation.
Outline Java program structure Basic program elements
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
UNDER THE HOOD: THE JAVA VIRTUAL MACHINE Lecture 24 – CS2110 – Fall 2009.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
A Safety-Critical Java Technology Compatibility Kit Hans Søndergaard Stephan Korsholm VIA University College, Horsens, Denmark & Anders P. Ravn Aalborg.
Computer Science and Engineering College of Engineering The Ohio State University Lot More Inheritance and Intro to Design Patterns Lecture 12.
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
1 Stacks. 2 A stack has the property that the last item placed on the stack will be the first item removed Commonly referred to as last-in, first-out,
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
COMP Parsing 3 of 4 Lectures 23. Using the Scanner Break input into tokens Use Scanner with delimiter: public void parse(String input ) { Scanner.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 Review of Java Basic Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – conditional statements –Flow of Control.
CS 153: Concepts of Compiler Design September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Building a Java Interpreter CS 142 (b) 01/14. Lab Sessions Monday, Wednesday – 10am – noon – ICS 189 Send an or make an appointment with the TA.
Java Programming Persistent Data Types. Persistent Data Structure A persistent data structure is a data structure having an internal state that never.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 3 – Extending classes.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Java Bytecode Verification Types Chris Male, David J. Pearce, Alex Potanin and Constantine Dymnikov Victoria University of Wellington, New.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Key Words / Reserved Words
Object-Oriented Concepts
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Control Structures.
null, true, and false are also reserved.
Circular List removedNode General Case Single Node Case lastNode aNode
Introduction to Java Programming
An overview of Java, Data types and variables
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Selection CSCE 121 J. Michael Moore.
Chapter 1: Computer Systems
Units with – James tedder
JavaScript Reserved Words
Simple Classes in Java CSCI 392 Classes – Part 1.
Module 2 - Part 1 Variables, Assignment, and Data Types
Building a Java Interpreter
The Recursive Descent Algorithm
Instructor: Alexander Stoytchev
Chap 2. Identifiers, Keywords, and Types
Agenda Types and identifiers Practice Assignment Keywords in Java
Lab 03 – Linked List.
Presentation transcript:

Java Decompiler

Decompiler Go from executable bytecode to the source code Bytecode has an M->N correspondence Partial structure destruction Executable has worse! Not all bytecode has corresponding source code

Class Parsing int flags = source.readUnsignedShort(); output.setFlags(flags); int this_id = source.readUnsignedShort(); String name = output.getClassName(this_id); output.setName(name); int super_id = source.readUnsignedShort(); String superName = null; if (super_id != 0)‏ superName = output.getClassName(super_id); output.setSuperClass(superName); int count = source.readUnsignedShort(); String interfaces[] = new String[count]; for (int i=0;i<count;i++) { int id = source.readUnsignedShort(); interfaces[i] = output.getClassName(id); } output.setInterfaces(interfaces); current = ClassLevel.METADATA;

Signature Parsing private String FieldType() { switch (peek()) { case 'B': case 'C': case 'D': case 'F': case 'I': case 'S': case 'Z': return BaseType(); case 'L': return ClassType(); case '[': return ArrayType(); } throw new ParseException(); private String ClassType() { StringBuilder sb = new StringBuilder(); if (next() != 'L') throw new ParseException(); while (peek() != ';') { char c = next(); sb.append(c == '/' ? '.' : c); next(); // consume ; return sb.toString();

Bytecode detection while (i < bytecode.length) { int index = i++; BytecodeInstruction expr; switch(bytecode[index] & 0xff) { case 0x02: //iconst_m1 case 0x03: //iconst_0 expr = new LoadConstantInstruction(int.class, bytecode[index]-0x03); break; case 0x99: //ifeq expr = new IfInstruction("eq",index+((bytecode[i++] << 8 & 0xff) | (bytecode[i++] & 0xff)), false); case 0xb6: //invokevirtual expr = new InvokeInstruction(info, (bytecode[i++] << 8 & 0xff) | (bytecode[i++] & 0xff), false, true); default: Logger.error("Illegal opcode: "+Integer.toHexString(bytecode[index] & 0xff)); expr = null; } if (expr != null) { CodeGraph.Node node = new Node(expr); if (lastNode != null) { if (last.usesNext())‏ lastNode.addChild(node); lastNode = node; last = expr; map.put(index, node);

Runtime annotation processing public final class OptClassLoader extends ClassLoader { public final Class<?> loadClass(String name, boolean resolve) { Annotation[] annotations = result.getAnnotations(); for (Annotation a : annotations) { Class<? extends Annotation> c = a.annotationType(); if (c.getName().equals("util.Option")) { addOption((Option)a); } else if (c.getName().equals("util.Options")) { Option[] defs = (Option[])c.getDeclaredMethod("value").invoke(a); for (Option o : defs)‏ addOption(o); } return result; private void addOption(Option o) { String name = o.name(); Class<?> type = o.type(); String def = o.def(); OptionManager.addOption(name,type,def);

Sample output File: abstract class Foobar implements java.io.Serializable { public abstract <T, E extends Throwable> T foobar(T bar) throws E; } Output: /* FILE: test.java */ Foobar() { 1012673: load java.lang.Object, 0-> { 7901508 } 7901508: invokenonvirtual java.lang.Object.<init>-> { 25771774 } 25771774: return (none)-> { } public abstract <T extends java.lang.Object, E extends java.lang.Throwable> T foobar(T {VAR0}) throws E;