Add field references, only for getstatic currently
This commit is contained in:
@@ -2,7 +2,7 @@ package info.sigterm.deob;
|
||||
|
||||
import info.sigterm.deob.attributes.Attributes;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.UTF8;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -55,6 +55,11 @@ public class ClassFile
|
||||
attributes = new Attributes(this);
|
||||
}
|
||||
|
||||
public ClassGroup getGroup()
|
||||
{
|
||||
return group;
|
||||
}
|
||||
|
||||
public DataInputStream getStream()
|
||||
{
|
||||
return is;
|
||||
@@ -68,23 +73,43 @@ public class ClassFile
|
||||
public String getName()
|
||||
{
|
||||
Class entry = (Class) pool.getEntry(this_class);
|
||||
UTF8 className = (UTF8) pool.getEntry(entry.getIndex());
|
||||
return className.getValue();
|
||||
return entry.getName();
|
||||
}
|
||||
|
||||
public ClassFile getParent()
|
||||
{
|
||||
Class entry = (Class) pool.getEntry(super_class);
|
||||
String superName = entry.getName();
|
||||
ClassFile other = group.findClass(superName);
|
||||
assert other != this;
|
||||
return other;
|
||||
}
|
||||
|
||||
public Field findField(NameAndType nat)
|
||||
{
|
||||
Field f = fields.findField(nat);
|
||||
if (f != null)
|
||||
return f;
|
||||
|
||||
ClassFile parent = getParent();
|
||||
if (parent != null)
|
||||
return parent.findField(nat);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
ClassFile other = getParent();
|
||||
if (other == null)
|
||||
return; // inherits from a class not in my group
|
||||
|
||||
assert other != this;
|
||||
|
||||
this.parent = other;
|
||||
parent.children.add(this);
|
||||
}
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
methods.buildInstructionGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,10 @@ public class ClassGroup
|
||||
for (ClassFile c : classes)
|
||||
c.buildClassGraph();
|
||||
}
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
for (ClassFile c : classes)
|
||||
c.buildInstructionGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,5 +26,6 @@ public class Deob
|
||||
}
|
||||
|
||||
group.buildClassGraph();
|
||||
group.buildInstructionGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package info.sigterm.deob;
|
||||
|
||||
import info.sigterm.deob.attributes.Attributes;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.pool.UTF8;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Field
|
||||
{
|
||||
@@ -14,6 +17,8 @@ public class Field
|
||||
private int descriptorIndex;
|
||||
private Attributes attributes;
|
||||
|
||||
private ArrayList<Instruction> instructions = new ArrayList<Instruction>(); // instructions which reference this field
|
||||
|
||||
Field(Fields fields) throws IOException
|
||||
{
|
||||
this.fields = fields;
|
||||
@@ -30,4 +35,21 @@ public class Field
|
||||
{
|
||||
return fields;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
UTF8 u = (UTF8) fields.getClassFile().getPool().getEntry(nameIndex);
|
||||
return u.getValue();
|
||||
}
|
||||
|
||||
public String getDescriptor()
|
||||
{
|
||||
UTF8 u = (UTF8) fields.getClassFile().getPool().getEntry(descriptorIndex);
|
||||
return u.getValue();
|
||||
}
|
||||
|
||||
public void addReference(Instruction ins)
|
||||
{
|
||||
instructions.add(ins);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.sigterm.deob;
|
||||
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -27,4 +29,12 @@ public class Fields
|
||||
{
|
||||
return classFile;
|
||||
}
|
||||
|
||||
public Field findField(NameAndType nat)
|
||||
{
|
||||
for (Field f : fields)
|
||||
if (f.getName().equals(nat.getName()) && f.getDescriptor().equals(nat.getDescriptor()))
|
||||
return f;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,12 @@ public class Method
|
||||
{
|
||||
return (Code) attributes.findType(AttributeType.CODE);
|
||||
}
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
Code code = getCode();
|
||||
|
||||
if (code != null)
|
||||
code.buildInstructionGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,10 @@ public class Methods
|
||||
{
|
||||
return classFile;
|
||||
}
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
for (Method m : methods)
|
||||
m.buildInstructionGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,9 @@ public class Code extends Attribute
|
||||
{
|
||||
return maxLocals;
|
||||
}
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
instructions.buildInstructionGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@ public class Instruction
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
public Instructions getInstructions()
|
||||
{
|
||||
return instructions;
|
||||
}
|
||||
|
||||
public int getPc()
|
||||
{
|
||||
return pc;
|
||||
@@ -46,6 +51,10 @@ public class Instruction
|
||||
{
|
||||
}
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
}
|
||||
|
||||
public void execute(Execution e)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -53,6 +53,12 @@ public class Instructions
|
||||
i.buildJumpGraph();
|
||||
}
|
||||
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
for (Instruction i : instructions)
|
||||
i.buildInstructionGraph();
|
||||
}
|
||||
|
||||
public Code getCode()
|
||||
{
|
||||
return code;
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package info.sigterm.deob.attributes.code.instructions;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.Field;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -20,4 +25,23 @@ public class GetStatic extends Instruction
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
ConstantPool pool = this.getInstructions().getCode().getAttributes().getClassFile().getPool();
|
||||
Field entry = (Field) pool.getEntry(index);
|
||||
|
||||
Class clazz = entry.getClassEntry();
|
||||
NameAndType nat = entry.getNameAndType();
|
||||
|
||||
ClassFile cf = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
|
||||
if (cf == null)
|
||||
return;
|
||||
|
||||
info.sigterm.deob.Field f = cf.findField(nat);
|
||||
assert f != null;
|
||||
|
||||
f.addReference(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ public class Class extends PoolEntry
|
||||
index = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
public java.lang.String getName()
|
||||
{
|
||||
return index;
|
||||
UTF8 u = (UTF8) this.getPool().getEntry(index);
|
||||
return u.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,14 @@ public class Field extends PoolEntry
|
||||
classIndex = is.readUnsignedShort();
|
||||
nameAndTypeIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public Class getClassEntry()
|
||||
{
|
||||
return (Class) this.getPool().getEntry(classIndex);
|
||||
}
|
||||
|
||||
public NameAndType getNameAndType()
|
||||
{
|
||||
return (NameAndType) this.getPool().getEntry(nameAndTypeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,16 @@ public class NameAndType extends PoolEntry
|
||||
nameIndex = is.readUnsignedShort();
|
||||
descriptorIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public java.lang.String getName()
|
||||
{
|
||||
UTF8 u = (UTF8) this.getPool().getEntry(nameIndex);
|
||||
return u.getValue();
|
||||
}
|
||||
|
||||
public java.lang.String getDescriptor()
|
||||
{
|
||||
UTF8 u = (UTF8) this.getPool().getEntry(descriptorIndex);
|
||||
return u.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ public abstract class PoolEntry
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ConstantPool getPool()
|
||||
{
|
||||
return pool;
|
||||
}
|
||||
|
||||
public int getSlots()
|
||||
{
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user