Build class graph
This commit is contained in:
@@ -1,10 +1,20 @@
|
|||||||
package info.sigterm.deob;
|
package info.sigterm.deob;
|
||||||
|
|
||||||
|
import info.sigterm.deob.pool.Class;
|
||||||
|
import info.sigterm.deob.pool.UTF8;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ClassFile
|
public class ClassFile
|
||||||
{
|
{
|
||||||
|
private ClassGroup group;
|
||||||
|
private DataInputStream is;
|
||||||
|
|
||||||
|
private ClassFile parent; // super class
|
||||||
|
private ArrayList<ClassFile> children = new ArrayList<ClassFile>(); // classes which inherit from this
|
||||||
|
|
||||||
private int magic;
|
private int magic;
|
||||||
private short minor_version;
|
private short minor_version;
|
||||||
private short major_version;
|
private short major_version;
|
||||||
@@ -17,10 +27,9 @@ public class ClassFile
|
|||||||
private Methods methods;
|
private Methods methods;
|
||||||
private Attributes attributes;
|
private Attributes attributes;
|
||||||
|
|
||||||
private DataInputStream is;
|
public ClassFile(ClassGroup group, DataInputStream is) throws IOException
|
||||||
|
|
||||||
public ClassFile(DataInputStream is) throws IOException
|
|
||||||
{
|
{
|
||||||
|
this.group = group;
|
||||||
this.is = is;
|
this.is = is;
|
||||||
|
|
||||||
magic = is.readInt();
|
magic = is.readInt();
|
||||||
@@ -54,4 +63,28 @@ public class ClassFile
|
|||||||
{
|
{
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
Class entry = (Class) pool.getEntry(this_class);
|
||||||
|
UTF8 className = (UTF8) pool.getEntry(entry.getIndex());
|
||||||
|
return className.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildClassGraph()
|
||||||
|
{
|
||||||
|
Class entry = (Class) pool.getEntry(super_class);
|
||||||
|
UTF8 className = (UTF8) pool.getEntry(entry.getIndex());
|
||||||
|
String superName = className.getValue();
|
||||||
|
|
||||||
|
ClassFile other = group.findClass(superName);
|
||||||
|
if (other == null)
|
||||||
|
return; // inherits from a class not in my group
|
||||||
|
|
||||||
|
assert other != null;
|
||||||
|
assert other != this;
|
||||||
|
|
||||||
|
this.parent = other;
|
||||||
|
parent.children.add(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/main/java/info/sigterm/deob/ClassGroup.java
Normal file
35
src/main/java/info/sigterm/deob/ClassGroup.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package info.sigterm.deob;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ClassGroup
|
||||||
|
{
|
||||||
|
private ArrayList<ClassFile> classes = new ArrayList<ClassFile>();
|
||||||
|
|
||||||
|
public ClassGroup()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassFile addClass(String name, DataInputStream is) throws IOException
|
||||||
|
{
|
||||||
|
ClassFile cf = new ClassFile(this, is);
|
||||||
|
classes.add(cf);
|
||||||
|
return cf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassFile findClass(String name)
|
||||||
|
{
|
||||||
|
for (ClassFile c : classes)
|
||||||
|
if (c.getName().equals(name))
|
||||||
|
return c;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildClassGraph()
|
||||||
|
{
|
||||||
|
for (ClassFile c : classes)
|
||||||
|
c.buildClassGraph();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ public class Deob
|
|||||||
{
|
{
|
||||||
public static void main(String[] args) throws IOException
|
public static void main(String[] args) throws IOException
|
||||||
{
|
{
|
||||||
|
ClassGroup group = new ClassGroup();
|
||||||
|
|
||||||
JarFile jar = new JarFile(args[0]);
|
JarFile jar = new JarFile(args[0]);
|
||||||
for (Enumeration<JarEntry> it = jar.entries(); it.hasMoreElements();)
|
for (Enumeration<JarEntry> it = jar.entries(); it.hasMoreElements();)
|
||||||
{
|
{
|
||||||
@@ -20,7 +22,9 @@ public class Deob
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
InputStream is = jar.getInputStream(entry);
|
InputStream is = jar.getInputStream(entry);
|
||||||
ClassFile c = new ClassFile(new DataInputStream(is));
|
group.addClass(entry.getName(), new DataInputStream(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.buildClassGraph();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package info.sigterm.deob.attributes.code.instructions;
|
||||||
|
|
||||||
|
import info.sigterm.deob.attributes.code.Instruction;
|
||||||
|
import info.sigterm.deob.attributes.code.InstructionType;
|
||||||
|
import info.sigterm.deob.attributes.code.Instructions;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class InvokeDynamic extends Instruction
|
||||||
|
{
|
||||||
|
private int index;
|
||||||
|
|
||||||
|
public InvokeDynamic(Instructions instructions, InstructionType type, int pc) throws IOException
|
||||||
|
{
|
||||||
|
super(instructions, type, pc);
|
||||||
|
|
||||||
|
DataInputStream is = instructions.getCode().getAttributes().getStream();
|
||||||
|
index = is.readUnsignedShort();
|
||||||
|
is.skip(2);
|
||||||
|
length += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,4 +16,9 @@ public class Class extends PoolEntry
|
|||||||
DataInputStream is = pool.getClassFile().getStream();
|
DataInputStream is = pool.getClassFile().getStream();
|
||||||
index = is.readUnsignedShort();
|
index = is.readUnsignedShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getIndex()
|
||||||
|
{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user