Class writing, call graph, eclipse project
This commit is contained in:
@@ -5,6 +5,7 @@ import info.sigterm.deob.pool.Class;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -54,6 +55,28 @@ public class ClassFile
|
||||
|
||||
attributes = new Attributes(this);
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeInt(0xcafebabe);
|
||||
|
||||
out.writeShort(minor_version);
|
||||
out.writeShort(major_version);
|
||||
|
||||
pool.write(out);
|
||||
|
||||
out.writeShort(access_flags);
|
||||
out.writeShort(this_class);
|
||||
out.writeShort(super_class);
|
||||
|
||||
interfaces.write(out);
|
||||
|
||||
fields.write(out);
|
||||
|
||||
methods.write(out);
|
||||
|
||||
attributes.write(out);
|
||||
}
|
||||
|
||||
public ClassGroup getGroup()
|
||||
{
|
||||
@@ -74,6 +97,11 @@ public class ClassFile
|
||||
{
|
||||
return fields;
|
||||
}
|
||||
|
||||
public Methods getMethods()
|
||||
{
|
||||
return methods;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
@@ -144,6 +172,11 @@ public class ClassFile
|
||||
methods.buildInstructionGraph();
|
||||
}
|
||||
|
||||
public void buildCallGraph()
|
||||
{
|
||||
methods.buildCallGraph();
|
||||
}
|
||||
|
||||
public boolean instanceOf(ClassFile other)
|
||||
{
|
||||
return this == other || interfaces.instanceOf(other) || (getParent() != null && getParent().instanceOf(other));
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassGroup
|
||||
{
|
||||
@@ -18,6 +19,11 @@ public class ClassGroup
|
||||
classes.add(cf);
|
||||
return cf;
|
||||
}
|
||||
|
||||
public List<ClassFile> getClasses()
|
||||
{
|
||||
return classes;
|
||||
}
|
||||
|
||||
public ClassFile findClass(String name)
|
||||
{
|
||||
@@ -39,4 +45,10 @@ public class ClassGroup
|
||||
for (ClassFile c : classes)
|
||||
c.buildInstructionGraph();
|
||||
}
|
||||
|
||||
public void buildCallGraph()
|
||||
{
|
||||
for (ClassFile c : classes)
|
||||
c.buildCallGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package info.sigterm.deob;
|
||||
|
||||
import info.sigterm.deob.attributes.code.instructions.Return;
|
||||
import info.sigterm.deob.pool.ConstantType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
import info.sigterm.deob.pool.UTF8;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
@@ -35,12 +38,7 @@ public class ConstantPool
|
||||
PoolEntry entry = con.newInstance(this);
|
||||
|
||||
pool[i] = entry;
|
||||
|
||||
for (int j = 1; j < entry.getSlots(); ++j)
|
||||
{
|
||||
pool[i + 1] = entry;
|
||||
++i;
|
||||
}
|
||||
i += entry.getSlots() - 1;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -48,6 +46,19 @@ public class ConstantPool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(count);
|
||||
for (int i = 1; i < count; ++i)
|
||||
{
|
||||
PoolEntry entry = pool[i];
|
||||
if (entry == null)
|
||||
continue;
|
||||
out.writeByte(entry.getType().getType());
|
||||
entry.write(out);
|
||||
}
|
||||
}
|
||||
|
||||
public ClassFile getClassFile()
|
||||
{
|
||||
@@ -58,4 +69,22 @@ public class ConstantPool
|
||||
{
|
||||
return pool[index];
|
||||
}
|
||||
|
||||
public int findUTF8Index(String s)
|
||||
{
|
||||
for (int i = 1; i < count; ++i)
|
||||
{
|
||||
PoolEntry entry = pool[i];
|
||||
if (entry instanceof UTF8)
|
||||
{
|
||||
UTF8 u = (UTF8) entry;
|
||||
if (s.equals(u.getValue()))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,17 @@ package info.sigterm.deob;
|
||||
|
||||
import info.sigterm.deob.execution.Execution;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
public class Deob
|
||||
{
|
||||
@@ -30,8 +35,27 @@ public class Deob
|
||||
|
||||
group.buildClassGraph();
|
||||
group.buildInstructionGraph();
|
||||
group.buildCallGraph();
|
||||
|
||||
execute(group);
|
||||
//checkCallGraph(group);
|
||||
|
||||
//execute(group);
|
||||
|
||||
JarOutputStream jout = new JarOutputStream(new FileOutputStream("d:/rs/07/adamout.jar"), new Manifest());
|
||||
|
||||
for (ClassFile cf : group.getClasses())
|
||||
{
|
||||
JarEntry entry = new JarEntry(cf.getName() + ".class");
|
||||
jout.putNextEntry(entry);
|
||||
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
cf.write(new DataOutputStream(bout));
|
||||
jout.write(bout.toByteArray());
|
||||
|
||||
jout.closeEntry();
|
||||
}
|
||||
|
||||
jout.close();
|
||||
}
|
||||
|
||||
private static void execute(ClassGroup group) throws IOException
|
||||
@@ -42,4 +66,18 @@ public class Deob
|
||||
Execution e = new Execution(group);
|
||||
e.run(cf, method);
|
||||
}
|
||||
|
||||
private static void checkCallGraph(ClassGroup group)
|
||||
{
|
||||
for (ClassFile cf : group.getClasses())
|
||||
{
|
||||
for (Method m : cf.getMethods().getMethods())
|
||||
{
|
||||
if (m.callsFrom.isEmpty())
|
||||
{
|
||||
System.out.println(cf.getName() + " " + m.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.pool.UTF8;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -40,6 +41,14 @@ public class Field
|
||||
descriptorIndex = is.readUnsignedShort();
|
||||
attributes = new Attributes(this);
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(accessFlags);
|
||||
out.writeShort(nameIndex);
|
||||
out.writeShort(descriptorIndex);
|
||||
attributes.write(out);
|
||||
}
|
||||
|
||||
public Fields getFields()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Fields
|
||||
@@ -24,6 +25,13 @@ public class Fields
|
||||
for (int i = 0; i < count; ++i)
|
||||
fields[i] = new Field(this);
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(count);
|
||||
for (Field f : fields)
|
||||
f.write(out);
|
||||
}
|
||||
|
||||
public ClassFile getClassFile()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Interfaces
|
||||
@@ -25,6 +26,13 @@ public class Interfaces
|
||||
interfaces[i] = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(count);
|
||||
for (int i : interfaces)
|
||||
out.writeShort(i);
|
||||
}
|
||||
|
||||
public boolean instanceOf(ClassFile cf)
|
||||
{
|
||||
for (int i : interfaces)
|
||||
|
||||
@@ -3,10 +3,15 @@ package info.sigterm.deob;
|
||||
import info.sigterm.deob.attributes.AttributeType;
|
||||
import info.sigterm.deob.attributes.Attributes;
|
||||
import info.sigterm.deob.attributes.Code;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.callgraph.Node;
|
||||
import info.sigterm.deob.pool.UTF8;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Method
|
||||
{
|
||||
@@ -16,6 +21,8 @@ public class Method
|
||||
private int nameIndex;
|
||||
private int descriptorIndex;
|
||||
private Attributes attributes;
|
||||
public List<Node> callsTo = new ArrayList<>(),
|
||||
callsFrom = new ArrayList<>();
|
||||
|
||||
Method(Methods methods) throws IOException
|
||||
{
|
||||
@@ -28,6 +35,19 @@ public class Method
|
||||
descriptorIndex = is.readUnsignedShort();
|
||||
attributes = new Attributes(this);
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(accessFlags);
|
||||
out.writeShort(nameIndex);
|
||||
out.writeShort(descriptorIndex);
|
||||
attributes.write(out);
|
||||
}
|
||||
|
||||
protected void remove()
|
||||
{
|
||||
assert callsFrom.isEmpty();
|
||||
}
|
||||
|
||||
public Methods getMethods()
|
||||
{
|
||||
@@ -58,4 +78,19 @@ public class Method
|
||||
if (code != null)
|
||||
code.buildInstructionGraph();
|
||||
}
|
||||
|
||||
public void buildCallGraph()
|
||||
{
|
||||
Code code = getCode();
|
||||
|
||||
if (code != null)
|
||||
code.buildCallGraph();
|
||||
}
|
||||
|
||||
public void addCallTo(Instruction ins, Method method)
|
||||
{
|
||||
Node node = new Node(this, method, ins);
|
||||
callsTo.add(node);
|
||||
method.callsFrom.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,16 @@ package info.sigterm.deob;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Methods
|
||||
{
|
||||
ClassFile classFile;
|
||||
|
||||
private int count;
|
||||
private Method[] methods;
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
|
||||
Methods(ClassFile cf) throws IOException
|
||||
{
|
||||
@@ -18,11 +20,23 @@ public class Methods
|
||||
|
||||
DataInputStream is = cf.getStream();
|
||||
|
||||
count = is.readUnsignedShort();
|
||||
methods = new Method[count];
|
||||
int count = is.readUnsignedShort();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
methods[i] = new Method(this);
|
||||
methods.add(new Method(this));
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(methods.size());
|
||||
for (Method m : methods)
|
||||
m.write(out);
|
||||
}
|
||||
|
||||
public void removeMethod(Method m)
|
||||
{
|
||||
m.remove();
|
||||
methods.remove(methods);
|
||||
}
|
||||
|
||||
public ClassFile getClassFile()
|
||||
@@ -30,6 +44,11 @@ public class Methods
|
||||
return classFile;
|
||||
}
|
||||
|
||||
public List<Method> getMethods()
|
||||
{
|
||||
return methods;
|
||||
}
|
||||
|
||||
public Method findMethod(NameAndType nat)
|
||||
{
|
||||
for (Method m : methods)
|
||||
@@ -51,4 +70,10 @@ public class Methods
|
||||
for (Method m : methods)
|
||||
m.buildInstructionGraph();
|
||||
}
|
||||
|
||||
public void buildCallGraph()
|
||||
{
|
||||
for (Method m : methods)
|
||||
m.buildCallGraph();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package info.sigterm.deob.attributes;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Attribute
|
||||
public abstract class Attribute
|
||||
{
|
||||
private Attributes attributes;
|
||||
private AttributeType type;
|
||||
private int length;
|
||||
public int nameIndex;
|
||||
|
||||
Attribute(Attributes attr, AttributeType type) throws IOException
|
||||
{
|
||||
@@ -17,6 +20,18 @@ public class Attribute
|
||||
DataInputStream is = attr.getStream();
|
||||
this.length = is.readInt();
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
writeAttr(new DataOutputStream(bout));
|
||||
|
||||
byte[] b = bout.toByteArray();
|
||||
out.writeInt(b.length);
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
public abstract void writeAttr(DataOutputStream out) throws IOException;
|
||||
|
||||
public Attributes getAttributes()
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ public enum AttributeType
|
||||
|
||||
private String name;
|
||||
private Class<? extends Attribute> clazz;
|
||||
public int nameIndex;
|
||||
|
||||
AttributeType(String name, Class<? extends Attribute> clazz)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.Method;
|
||||
import info.sigterm.deob.pool.UTF8;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
@@ -99,6 +100,7 @@ public class Attributes
|
||||
{
|
||||
Constructor<? extends Attribute> con = type.getAttributeClass().getConstructor(new Class[] { Attributes.class });
|
||||
Attribute attr = con.newInstance(this);
|
||||
attr.nameIndex = nameIndex;
|
||||
|
||||
attributes[i] = attr;
|
||||
}
|
||||
@@ -108,4 +110,14 @@ public class Attributes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(count);
|
||||
for (Attribute a : attributes)
|
||||
{
|
||||
out.writeShort(a.nameIndex);
|
||||
a.write(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import info.sigterm.deob.attributes.code.Exceptions;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Code extends Attribute
|
||||
@@ -26,7 +27,7 @@ public class Code extends Attribute
|
||||
instructions = new Instructions(this);
|
||||
|
||||
exceptions = new Exceptions(this);
|
||||
attributes = new Attributes(this);
|
||||
this.attributes = new Attributes(this);
|
||||
}
|
||||
|
||||
public int getMaxStack()
|
||||
@@ -53,4 +54,20 @@ public class Code extends Attribute
|
||||
{
|
||||
instructions.buildInstructionGraph();
|
||||
}
|
||||
|
||||
public void buildCallGraph()
|
||||
{
|
||||
instructions.buildCallGraph();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAttr(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(maxStack);
|
||||
out.writeShort(maxLocals);
|
||||
|
||||
instructions.write(out);
|
||||
exceptions.write(out);
|
||||
attributes.write(out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,22 +3,29 @@ package info.sigterm.deob.attributes;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConstantValue extends Attribute
|
||||
{
|
||||
private int constantVlaueIndex;
|
||||
private int constantValueIndex;
|
||||
|
||||
public ConstantValue(Attributes attributes) throws IOException
|
||||
{
|
||||
super(attributes, AttributeType.CONSTANT_VALUE);
|
||||
|
||||
DataInputStream is = attributes.getStream();
|
||||
constantVlaueIndex = is.readUnsignedShort();
|
||||
constantValueIndex = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public PoolEntry getValue()
|
||||
{
|
||||
return this.getAttributes().getClassFile().getPool().getEntry(constantVlaueIndex);
|
||||
return this.getAttributes().getClassFile().getPool().getEntry(constantValueIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAttr(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(constantValueIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package info.sigterm.deob.attributes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Unknown extends Attribute
|
||||
@@ -29,4 +30,10 @@ public class Unknown extends Attribute
|
||||
|
||||
assert read == len;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAttr(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Exception
|
||||
@@ -26,6 +27,14 @@ public class Exception
|
||||
catchType = is.readUnsignedShort();
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(startPc);
|
||||
out.writeShort(endPc);
|
||||
out.writeShort(handlerPc);
|
||||
out.writeShort(catchType);
|
||||
}
|
||||
|
||||
public Exceptions getExceptions()
|
||||
{
|
||||
return exceptions;
|
||||
|
||||
@@ -4,6 +4,7 @@ import info.sigterm.deob.attributes.Code;
|
||||
import info.sigterm.deob.execution.ObjectInstance;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -25,6 +26,13 @@ public class Exceptions
|
||||
for (int i = 0; i < count; ++i)
|
||||
exceptions[i] = new Exception(this);
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(exceptions.length);
|
||||
for (Exception e : exceptions)
|
||||
e.write(out);
|
||||
}
|
||||
|
||||
public Code getCode()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@ package info.sigterm.deob.attributes.code;
|
||||
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Instruction
|
||||
@@ -21,6 +23,11 @@ public abstract class Instruction
|
||||
this.type = type;
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
out.writeByte(type.getCode());
|
||||
}
|
||||
|
||||
public Instructions getInstructions()
|
||||
{
|
||||
@@ -59,6 +66,10 @@ public abstract class Instruction
|
||||
public void buildInstructionGraph()
|
||||
{
|
||||
}
|
||||
|
||||
public void buildCallGraph()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void execute(Frame e);
|
||||
}
|
||||
|
||||
@@ -2,15 +2,18 @@ package info.sigterm.deob.attributes.code;
|
||||
|
||||
import info.sigterm.deob.attributes.Code;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Instructions
|
||||
{
|
||||
private Code code;
|
||||
private ArrayList<Instruction> instructions = new ArrayList<Instruction>();
|
||||
private List<Instruction> instructions = new ArrayList<>();
|
||||
|
||||
public Instructions(Code code) throws IOException
|
||||
{
|
||||
@@ -46,6 +49,21 @@ public class Instructions
|
||||
|
||||
buildJumpGraph();
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream o = new DataOutputStream(b);
|
||||
int pc = 0;
|
||||
for (Instruction i : instructions)
|
||||
{
|
||||
i.write(o, pc);
|
||||
pc = o.size();
|
||||
}
|
||||
byte[] ba = b.toByteArray();
|
||||
out.writeInt(ba.length);
|
||||
out.write(ba);
|
||||
}
|
||||
|
||||
private void buildJumpGraph()
|
||||
{
|
||||
@@ -58,6 +76,12 @@ public class Instructions
|
||||
for (Instruction i : instructions)
|
||||
i.buildInstructionGraph();
|
||||
}
|
||||
|
||||
public void buildCallGraph()
|
||||
{
|
||||
for (Instruction i : instructions)
|
||||
i.buildCallGraph();
|
||||
}
|
||||
|
||||
public Code getCode()
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ALoad extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class ALoad extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -10,6 +10,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ANewArray extends Instruction
|
||||
@@ -24,6 +25,13 @@ public class ANewArray extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AStore extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class AStore extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BiPush extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class BiPush extends Instruction
|
||||
b = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -10,6 +10,7 @@ import info.sigterm.deob.execution.ObjectInstance;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CheckCast extends Instruction
|
||||
@@ -24,6 +25,13 @@ public class CheckCast extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DLoad extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class DLoad extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DStore extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class DStore extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FLoad extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class FLoad extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FStore extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class FStore extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -12,6 +12,7 @@ import info.sigterm.deob.pool.Field;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GetField extends Instruction
|
||||
@@ -26,6 +27,13 @@ public class GetField extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -13,6 +13,7 @@ import info.sigterm.deob.pool.Field;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GetStatic extends Instruction
|
||||
@@ -27,6 +28,13 @@ public class GetStatic extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Goto extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class Goto extends Instruction
|
||||
offset = is.readShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GotoW extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class GotoW extends Instruction
|
||||
offset = is.readInt();
|
||||
length += 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeInt(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class IInc extends Instruction
|
||||
@@ -22,6 +23,14 @@ public class IInc extends Instruction
|
||||
inc = is.readByte();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
out.writeByte(inc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ILoad extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class ILoad extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class IStore extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class IStore extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -7,6 +7,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.Path;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class If extends Instruction
|
||||
@@ -21,6 +22,13 @@ public class If extends Instruction
|
||||
offset = is.readShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
|
||||
@@ -7,6 +7,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.Path;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class If0 extends Instruction
|
||||
@@ -21,6 +22,13 @@ public class If0 extends Instruction
|
||||
offset = is.readShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
|
||||
@@ -10,6 +10,7 @@ import info.sigterm.deob.execution.ObjectInstanceBase;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InstanceOf extends Instruction
|
||||
@@ -24,6 +25,13 @@ public class InstanceOf extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -10,8 +10,10 @@ import info.sigterm.deob.execution.ClassInstance;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.ObjectInstance;
|
||||
import info.sigterm.deob.pool.InterfaceMethod;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InvokeInterface extends Instruction
|
||||
@@ -29,6 +31,36 @@ public class InvokeInterface extends Instruction
|
||||
is.skip(1);
|
||||
length += 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
out.writeByte(count);
|
||||
out.writeByte(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildCallGraph()
|
||||
{
|
||||
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
|
||||
|
||||
ConstantPool pool = thisClass.getPool();
|
||||
InterfaceMethod method = (InterfaceMethod) pool.getEntry(index);
|
||||
|
||||
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
|
||||
NameAndType nat = method.getNameAndType();
|
||||
|
||||
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
|
||||
|
||||
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
|
||||
if (otherClass == null)
|
||||
return;
|
||||
info.sigterm.deob.Method other = otherClass.findMethod(nat);
|
||||
|
||||
thisMethod.addCallTo(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -9,9 +9,11 @@ import info.sigterm.deob.execution.ClassInstance;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.ObjectInstance;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InvokeSpecial extends Instruction
|
||||
@@ -26,6 +28,35 @@ public class InvokeSpecial extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildCallGraph()
|
||||
{
|
||||
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
|
||||
|
||||
ConstantPool pool = thisClass.getPool();
|
||||
Method method = (Method) pool.getEntry(index);
|
||||
|
||||
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
|
||||
NameAndType nat = method.getNameAndType();
|
||||
|
||||
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
|
||||
|
||||
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
|
||||
if (otherClass == null)
|
||||
return;
|
||||
|
||||
info.sigterm.deob.Method other = otherClass.findMethod(nat);
|
||||
|
||||
thisMethod.addCallTo(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -7,8 +7,10 @@ import info.sigterm.deob.attributes.code.InstructionType;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InvokeStatic extends Instruction
|
||||
@@ -23,6 +25,35 @@ public class InvokeStatic extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildCallGraph()
|
||||
{
|
||||
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
|
||||
|
||||
ConstantPool pool = thisClass.getPool();
|
||||
Method method = (Method) pool.getEntry(index);
|
||||
|
||||
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
|
||||
NameAndType nat = method.getNameAndType();
|
||||
|
||||
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
|
||||
|
||||
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
|
||||
if (otherClass == null)
|
||||
return;
|
||||
|
||||
info.sigterm.deob.Method other = otherClass.findMethod(nat);
|
||||
|
||||
thisMethod.addCallTo(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -9,8 +9,10 @@ import info.sigterm.deob.execution.ClassInstance;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.ObjectInstance;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InvokeVirtual extends Instruction
|
||||
@@ -25,6 +27,36 @@ public class InvokeVirtual extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildCallGraph()
|
||||
{
|
||||
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
|
||||
|
||||
ConstantPool pool = thisClass.getPool();
|
||||
Method method = (Method) pool.getEntry(index);
|
||||
|
||||
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
|
||||
NameAndType nat = method.getNameAndType();
|
||||
|
||||
info.sigterm.deob.Method thisMethod = this.getInstructions().getCode().getAttributes().getMethod();
|
||||
|
||||
ClassFile otherClass = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
|
||||
if (otherClass == null)
|
||||
return;
|
||||
info.sigterm.deob.Method other = otherClass.findMethod(nat);
|
||||
if (other == null)
|
||||
return;
|
||||
|
||||
thisMethod.addCallTo(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -8,6 +8,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LDC extends Instruction
|
||||
@@ -22,6 +23,13 @@ public class LDC extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -8,6 +8,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LDC2_W extends Instruction
|
||||
@@ -22,6 +23,13 @@ public class LDC2_W extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -8,6 +8,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LDC_W extends Instruction
|
||||
@@ -22,6 +23,13 @@ public class LDC_W extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LLoad extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class LLoad extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LStore extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class LStore extends Instruction
|
||||
index = is.readByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -7,6 +7,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.Path;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LookupSwitch extends Instruction
|
||||
@@ -40,6 +41,25 @@ public class LookupSwitch extends Instruction
|
||||
|
||||
length += tableSkip + 8 + (count * 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
|
||||
int tableSkip = 4 - (pc + 1) % 4;
|
||||
if (tableSkip == 4) tableSkip = 0;
|
||||
if (tableSkip > 0) out.write(new byte[tableSkip]);
|
||||
|
||||
out.writeInt(def);
|
||||
|
||||
out.writeInt(count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
out.writeInt(match[i]);
|
||||
out.writeInt(branch[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
|
||||
@@ -9,6 +9,7 @@ import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MultiANewArray extends Instruction
|
||||
@@ -26,6 +27,14 @@ public class MultiANewArray extends Instruction
|
||||
length += 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
out.writeByte(dimensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ import info.sigterm.deob.execution.ObjectInstance;
|
||||
import info.sigterm.deob.pool.Class;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class New extends Instruction
|
||||
@@ -24,6 +25,13 @@ public class New extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class NewArray extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class NewArray extends Instruction
|
||||
this.type = is.readUnsignedByte();
|
||||
length += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeByte(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -12,6 +12,7 @@ import info.sigterm.deob.pool.Field;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PutField extends Instruction
|
||||
@@ -26,6 +27,13 @@ public class PutField extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -13,6 +13,7 @@ import info.sigterm.deob.pool.Field;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PutStatic extends Instruction
|
||||
@@ -27,6 +28,13 @@ public class PutStatic extends Instruction
|
||||
index = is.readUnsignedShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SiPush extends Instruction
|
||||
@@ -20,6 +21,13 @@ public class SiPush extends Instruction
|
||||
s = is.readShort();
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
out.writeShort(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
|
||||
@@ -7,6 +7,7 @@ import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.Path;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TableSwitch extends Instruction
|
||||
@@ -38,6 +39,23 @@ public class TableSwitch extends Instruction
|
||||
|
||||
length += tableSkip + 12 + (count * 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
|
||||
int tableSkip = 4 - (pc + 1) % 4;
|
||||
if (tableSkip == 4) tableSkip = 0;
|
||||
if (tableSkip > 0) out.write(new byte[tableSkip]);
|
||||
|
||||
out.writeInt(def);
|
||||
out.writeInt(low);
|
||||
out.writeInt(high);
|
||||
|
||||
for (int i = 0; i < high - low + 1; ++i)
|
||||
out.writeInt(jumps[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
|
||||
@@ -6,6 +6,7 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Wide extends Instruction
|
||||
@@ -33,6 +34,22 @@ public class Wide extends Instruction
|
||||
length += 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out, int pc) throws IOException
|
||||
{
|
||||
super.write(out, pc);
|
||||
|
||||
out.writeByte(opcode);
|
||||
out.writeShort(index);
|
||||
|
||||
InstructionType optype = InstructionType.findInstructionFromCode(opcode);
|
||||
assert optype != null;
|
||||
if (optype == InstructionType.IINC)
|
||||
{
|
||||
out.writeShort(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Frame e)
|
||||
|
||||
17
src/main/java/info/sigterm/deob/callgraph/Node.java
Normal file
17
src/main/java/info/sigterm/deob/callgraph/Node.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package info.sigterm.deob.callgraph;
|
||||
|
||||
import info.sigterm.deob.Method;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
|
||||
public class Node
|
||||
{
|
||||
public Method from, to;
|
||||
public Instruction ins;
|
||||
|
||||
public Node(Method from, Method to, Instruction ins)
|
||||
{
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.ins = ins;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Class extends PoolEntry
|
||||
@@ -22,4 +23,10 @@ public class Class extends PoolEntry
|
||||
UTF8 u = (UTF8) this.getPool().getEntry(index);
|
||||
return u.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Double extends PoolEntry
|
||||
@@ -29,4 +30,10 @@ public class Double extends PoolEntry
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeDouble(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Field extends PoolEntry
|
||||
@@ -29,4 +30,11 @@ public class Field extends PoolEntry
|
||||
{
|
||||
return (NameAndType) this.getPool().getEntry(nameAndTypeIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(classIndex);
|
||||
out.writeShort(nameAndTypeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Float extends PoolEntry
|
||||
@@ -23,4 +24,10 @@ public class Float extends PoolEntry
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeFloat(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Integer extends PoolEntry
|
||||
@@ -23,4 +24,10 @@ public class Integer extends PoolEntry
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InterfaceMethod extends PoolEntry
|
||||
@@ -29,4 +30,11 @@ public class InterfaceMethod extends PoolEntry
|
||||
{
|
||||
return (NameAndType) this.getPool().getEntry(nameAndTypeIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(classIndex);
|
||||
out.writeShort(nameAndTypeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Long extends PoolEntry
|
||||
@@ -29,4 +30,10 @@ public class Long extends PoolEntry
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeLong(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Method extends PoolEntry
|
||||
@@ -29,4 +30,11 @@ public class Method extends PoolEntry
|
||||
{
|
||||
return (NameAndType) this.getPool().getEntry(nameAndTypeIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(classIndex);
|
||||
out.writeShort(nameAndTypeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -87,4 +88,11 @@ public class NameAndType extends PoolEntry
|
||||
return true;
|
||||
return !methodRefType.endsWith(")V");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(nameIndex);
|
||||
out.writeShort(descriptorIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package info.sigterm.deob.pool;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
public abstract class PoolEntry
|
||||
@@ -12,11 +15,18 @@ public abstract class PoolEntry
|
||||
this.pool = pool;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public abstract void write(DataOutputStream out) throws IOException;
|
||||
|
||||
public ConstantPool getPool()
|
||||
{
|
||||
return pool;
|
||||
}
|
||||
|
||||
public ConstantType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getSlots()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class String extends PoolEntry
|
||||
@@ -23,4 +24,10 @@ public class String extends PoolEntry
|
||||
{
|
||||
return this.getPool().getEntry(stringIndex).getObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
out.writeShort(stringIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.sigterm.deob.pool;
|
||||
import info.sigterm.deob.ConstantPool;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UTF8 extends PoolEntry
|
||||
@@ -51,4 +52,14 @@ public class UTF8 extends PoolEntry
|
||||
{
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user