Allow pool to be dynamically rebuilt
This commit is contained in:
@@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
public class Class extends PoolEntry
|
||||
{
|
||||
private int index;
|
||||
private java.lang.String name;
|
||||
|
||||
public Class(ConstantPool pool) throws IOException
|
||||
{
|
||||
@@ -17,11 +18,32 @@ public class Class extends PoolEntry
|
||||
DataInputStream is = pool.getClassFile().getStream();
|
||||
index = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve()
|
||||
{
|
||||
name = this.getPool().getUTF8(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prime()
|
||||
{
|
||||
index = this.getPool().makeUTF8(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof Class))
|
||||
return false;
|
||||
|
||||
Class c = (Class) other;
|
||||
return name.equals(c.name);
|
||||
}
|
||||
|
||||
public java.lang.String getName()
|
||||
{
|
||||
UTF8 u = (UTF8) this.getPool().getEntry(index);
|
||||
return u.getValue();
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,4 +51,10 @@ public class Class extends PoolEntry
|
||||
{
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,23 @@ public class Double extends PoolEntry
|
||||
|
||||
value = is.readDouble();
|
||||
}
|
||||
|
||||
public Double(ConstantPool pool, double d)
|
||||
{
|
||||
super(pool, ConstantType.DOUBLE);
|
||||
|
||||
value = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof Double))
|
||||
return false;
|
||||
|
||||
Double d = (Double) other;
|
||||
return value == d.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
|
||||
@@ -8,8 +8,9 @@ import java.io.IOException;
|
||||
|
||||
public class Field extends PoolEntry
|
||||
{
|
||||
private int classIndex;
|
||||
private int nameAndTypeIndex;
|
||||
private int classIndex, natIndex;
|
||||
private Class clazz;
|
||||
private NameAndType nat;
|
||||
|
||||
public Field(ConstantPool pool) throws IOException
|
||||
{
|
||||
@@ -18,23 +19,47 @@ public class Field extends PoolEntry
|
||||
DataInputStream is = pool.getClassFile().getStream();
|
||||
|
||||
classIndex = is.readUnsignedShort();
|
||||
nameAndTypeIndex = is.readUnsignedShort();
|
||||
natIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve()
|
||||
{
|
||||
clazz = this.getPool().getClass(classIndex);
|
||||
nat = this.getPool().getNameAndType(natIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prime()
|
||||
{
|
||||
classIndex = this.getPool().make(clazz);
|
||||
natIndex = this.getPool().make(nat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof Field))
|
||||
return false;
|
||||
|
||||
Field f = (Field) other;
|
||||
return clazz.equals(f.clazz) && nat.equals(f.nat);
|
||||
}
|
||||
|
||||
public Class getClassEntry()
|
||||
{
|
||||
return (Class) this.getPool().getEntry(classIndex);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public NameAndType getNameAndType()
|
||||
{
|
||||
return (NameAndType) this.getPool().getEntry(nameAndTypeIndex);
|
||||
return nat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(classIndex);
|
||||
out.writeShort(nameAndTypeIndex);
|
||||
out.writeShort(natIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,23 @@ public class Float extends PoolEntry
|
||||
|
||||
value = is.readFloat();
|
||||
}
|
||||
|
||||
public Float(ConstantPool pool, float f)
|
||||
{
|
||||
super(pool, ConstantType.FLOAT);
|
||||
|
||||
value = f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof Float))
|
||||
return false;
|
||||
|
||||
Float f = (Float) other;
|
||||
return value == f.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject()
|
||||
|
||||
@@ -18,6 +18,23 @@ public class Integer extends PoolEntry
|
||||
|
||||
value = is.readInt();
|
||||
}
|
||||
|
||||
public Integer(ConstantPool pool, int i)
|
||||
{
|
||||
super(pool, ConstantType.INTEGER);
|
||||
|
||||
value = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof Integer))
|
||||
return false;
|
||||
|
||||
Integer i = (Integer) other;
|
||||
return value == i.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject()
|
||||
|
||||
@@ -8,8 +8,9 @@ import java.io.IOException;
|
||||
|
||||
public class InterfaceMethod extends PoolEntry
|
||||
{
|
||||
private int classIndex;
|
||||
private int nameAndTypeIndex;
|
||||
private int classIndex, natIndex;
|
||||
private Class clazz;
|
||||
private NameAndType nat;
|
||||
|
||||
public InterfaceMethod(ConstantPool pool) throws IOException
|
||||
{
|
||||
@@ -18,23 +19,47 @@ public class InterfaceMethod extends PoolEntry
|
||||
DataInputStream is = pool.getClassFile().getStream();
|
||||
|
||||
classIndex = is.readUnsignedShort();
|
||||
nameAndTypeIndex = is.readUnsignedShort();
|
||||
natIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve()
|
||||
{
|
||||
clazz = this.getPool().getClass(classIndex);
|
||||
nat = this.getPool().getNameAndType(natIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prime()
|
||||
{
|
||||
classIndex = this.getPool().make(clazz);
|
||||
natIndex = this.getPool().make(nat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof InterfaceMethod))
|
||||
return false;
|
||||
|
||||
InterfaceMethod i = (InterfaceMethod) other;
|
||||
return clazz.equals(i.clazz) && nat.equals(i.nat);
|
||||
}
|
||||
|
||||
public Class getClassEntry()
|
||||
{
|
||||
return (Class) this.getPool().getEntry(classIndex);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public NameAndType getNameAndType()
|
||||
{
|
||||
return (NameAndType) this.getPool().getEntry(nameAndTypeIndex);
|
||||
return nat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(classIndex);
|
||||
out.writeShort(nameAndTypeIndex);
|
||||
out.writeShort(natIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,23 @@ public class Long extends PoolEntry
|
||||
|
||||
value = is.readLong();
|
||||
}
|
||||
|
||||
public Long(ConstantPool pool, long l)
|
||||
{
|
||||
super(pool, ConstantType.LONG);
|
||||
|
||||
value = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof Long))
|
||||
return false;
|
||||
|
||||
Long l = (Long) other;
|
||||
return value == l.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
|
||||
@@ -8,8 +8,9 @@ import java.io.IOException;
|
||||
|
||||
public class Method extends PoolEntry
|
||||
{
|
||||
private int classIndex;
|
||||
private int nameAndTypeIndex;
|
||||
private int classIndex, natIndex;
|
||||
private Class clazz;
|
||||
private NameAndType nat;
|
||||
|
||||
public Method(ConstantPool pool) throws IOException
|
||||
{
|
||||
@@ -18,23 +19,47 @@ public class Method extends PoolEntry
|
||||
DataInputStream is = pool.getClassFile().getStream();
|
||||
|
||||
classIndex = is.readUnsignedShort();
|
||||
nameAndTypeIndex = is.readUnsignedShort();
|
||||
natIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve()
|
||||
{
|
||||
clazz = this.getPool().getClass(classIndex);
|
||||
nat = this.getPool().getNameAndType(natIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prime()
|
||||
{
|
||||
classIndex = this.getPool().make(clazz);
|
||||
natIndex = this.getPool().make(nat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof Method))
|
||||
return false;
|
||||
|
||||
Method m = (Method) other;
|
||||
return clazz.equals(m.clazz) && nat.equals(m.nat);
|
||||
}
|
||||
|
||||
public Class getClassEntry()
|
||||
{
|
||||
return (Class) this.getPool().getEntry(classIndex);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public NameAndType getNameAndType()
|
||||
{
|
||||
return (NameAndType) this.getPool().getEntry(nameAndTypeIndex);
|
||||
return nat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(classIndex);
|
||||
out.writeShort(nameAndTypeIndex);
|
||||
out.writeShort(natIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class NameAndType extends PoolEntry
|
||||
{
|
||||
private int nameIndex;
|
||||
private int descriptorIndex;
|
||||
private int nameIndex, descriptorIndex;
|
||||
private java.lang.String name, descriptor;
|
||||
|
||||
public NameAndType(ConstantPool pool) throws IOException
|
||||
{
|
||||
@@ -23,24 +23,46 @@ public class NameAndType extends PoolEntry
|
||||
descriptorIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public NameAndType(ConstantPool pool, int name, int type)
|
||||
public NameAndType(java.lang.String name, java.lang.String type)
|
||||
{
|
||||
super(pool, ConstantType.NAME_AND_TYPE);
|
||||
super(null, ConstantType.NAME_AND_TYPE);
|
||||
|
||||
this.nameIndex = name;
|
||||
this.descriptorIndex = type;
|
||||
this.name = name;
|
||||
descriptor = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve()
|
||||
{
|
||||
name = this.getPool().getUTF8(nameIndex);
|
||||
descriptor = this.getPool().getUTF8(descriptorIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prime()
|
||||
{
|
||||
nameIndex = this.getPool().makeUTF8(name);
|
||||
descriptorIndex = this.getPool().makeUTF8(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof NameAndType))
|
||||
return false;
|
||||
|
||||
NameAndType nat = (NameAndType) other;
|
||||
return name.equals(nat.name) && descriptor.equals(nat.descriptor);
|
||||
}
|
||||
|
||||
public java.lang.String getName()
|
||||
{
|
||||
UTF8 u = (UTF8) this.getPool().getEntry(nameIndex);
|
||||
return u.getValue();
|
||||
return name;
|
||||
}
|
||||
|
||||
public java.lang.String getDescriptor()
|
||||
{
|
||||
UTF8 u = (UTF8) this.getPool().getEntry(descriptorIndex);
|
||||
return u.getValue();
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public Object getStackObject()
|
||||
|
||||
@@ -7,8 +7,9 @@ import info.sigterm.deob.ConstantPool;
|
||||
|
||||
public abstract class PoolEntry
|
||||
{
|
||||
private ConstantPool pool;
|
||||
public ConstantPool pool;
|
||||
private ConstantType type;
|
||||
public int id;
|
||||
|
||||
protected PoolEntry(ConstantPool pool, ConstantType type)
|
||||
{
|
||||
@@ -16,6 +17,18 @@ public abstract class PoolEntry
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
// read objects from indexes
|
||||
public void resolve()
|
||||
{
|
||||
}
|
||||
|
||||
// make objects and prime indexes
|
||||
public void prime()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract boolean equals(Object other);
|
||||
|
||||
public abstract void write(DataOutputStream out) throws IOException;
|
||||
|
||||
public ConstantPool getPool()
|
||||
@@ -35,6 +48,6 @@ public abstract class PoolEntry
|
||||
|
||||
public Object getObject()
|
||||
{
|
||||
throw new RuntimeException("No getObject implemented for " + this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
public class String extends PoolEntry
|
||||
{
|
||||
private int stringIndex;
|
||||
private java.lang.String string;
|
||||
|
||||
public String(ConstantPool pool) throws IOException
|
||||
{
|
||||
@@ -18,11 +19,40 @@ public class String extends PoolEntry
|
||||
|
||||
stringIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public String(ConstantPool pool, java.lang.String str)
|
||||
{
|
||||
super(pool, ConstantType.STRING);
|
||||
|
||||
string = str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve()
|
||||
{
|
||||
string = this.getPool().getUTF8(stringIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prime()
|
||||
{
|
||||
stringIndex = this.getPool().makeUTF8(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof String))
|
||||
return false;
|
||||
|
||||
String s = (String) other;
|
||||
return string.equals(s.string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject()
|
||||
{
|
||||
return this.getPool().getEntry(stringIndex).getObject();
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,58 +8,48 @@ import java.io.IOException;
|
||||
|
||||
public class UTF8 extends PoolEntry
|
||||
{
|
||||
private StringBuilder sb = new StringBuilder();
|
||||
private java.lang.String string;
|
||||
|
||||
public UTF8(ConstantPool pool) throws IOException
|
||||
{
|
||||
super(pool, ConstantType.UTF8);
|
||||
|
||||
DataInputStream ios = pool.getClassFile().getStream();
|
||||
|
||||
short length = ios.readShort();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int a = ios.read();
|
||||
if ((a & 0x80) == 0)
|
||||
{
|
||||
sb.append((char)a);
|
||||
}
|
||||
else if ((a & 0x20) == 0)
|
||||
{
|
||||
int b = ios.read();
|
||||
char c = (char)(((a & 0x1f) << 6) + (b & 0x3f));
|
||||
sb.append(c);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int b = ios.read();
|
||||
int c = ios.read();
|
||||
char ch = (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f));
|
||||
sb.append(ch);
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
string = ios.readUTF();
|
||||
}
|
||||
|
||||
public UTF8(java.lang.String value)
|
||||
{
|
||||
super(null, ConstantType.UTF8);
|
||||
|
||||
string = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (!(other instanceof UTF8))
|
||||
return false;
|
||||
|
||||
UTF8 u = (UTF8) other;
|
||||
return string.equals(u.string);
|
||||
}
|
||||
|
||||
public java.lang.String getValue()
|
||||
{
|
||||
return (java.lang.String) getObject();
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject()
|
||||
{
|
||||
return sb.toString();
|
||||
return getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
java.lang.String s = getValue();
|
||||
byte[] bytes = s.getBytes("UTF-8");
|
||||
|
||||
out.writeShort(bytes.length);
|
||||
out.write(bytes);
|
||||
out.writeUTF(s);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user