Rename unique fields
This commit is contained in:
@@ -67,6 +67,11 @@ public class Field
|
|||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public Type getType()
|
public Type getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package info.sigterm.deob.attributes.code;
|
|||||||
|
|
||||||
import info.sigterm.deob.ClassFile;
|
import info.sigterm.deob.ClassFile;
|
||||||
import info.sigterm.deob.ConstantPool;
|
import info.sigterm.deob.ConstantPool;
|
||||||
|
import info.sigterm.deob.Field;
|
||||||
import info.sigterm.deob.execution.Frame;
|
import info.sigterm.deob.execution.Frame;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -211,4 +212,8 @@ public abstract class Instruction
|
|||||||
public void renameClass(ClassFile cf, String name)
|
public void renameClass(ClassFile cf, String name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void renameField(Field f, String name)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package info.sigterm.deob.attributes.code;
|
package info.sigterm.deob.attributes.code;
|
||||||
|
|
||||||
import info.sigterm.deob.ClassFile;
|
import info.sigterm.deob.ClassFile;
|
||||||
|
import info.sigterm.deob.Field;
|
||||||
import info.sigterm.deob.attributes.Code;
|
import info.sigterm.deob.attributes.Code;
|
||||||
import info.sigterm.deob.attributes.code.instruction.types.JumpingInstruction;
|
import info.sigterm.deob.attributes.code.instruction.types.JumpingInstruction;
|
||||||
import info.sigterm.deob.attributes.code.instructions.LDC;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@@ -203,4 +203,10 @@ public class Instructions
|
|||||||
for (Instruction i : instructions)
|
for (Instruction i : instructions)
|
||||||
i.renameClass(cf, name);
|
i.renameClass(cf, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void renameField(Field f, String name)
|
||||||
|
{
|
||||||
|
for (Instruction i : instructions)
|
||||||
|
i.renameField(f, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import info.sigterm.deob.execution.StackContext;
|
|||||||
import info.sigterm.deob.execution.Type;
|
import info.sigterm.deob.execution.Type;
|
||||||
import info.sigterm.deob.pool.Class;
|
import info.sigterm.deob.pool.Class;
|
||||||
import info.sigterm.deob.pool.Field;
|
import info.sigterm.deob.pool.Field;
|
||||||
|
import info.sigterm.deob.pool.NameAndType;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -66,4 +67,17 @@ public class GetField extends Instruction implements GetFieldInstruction
|
|||||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||||
field = new Field(new Class(name), field.getNameAndType());
|
field = new Field(new Class(name), field.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameField(info.sigterm.deob.Field f, String name)
|
||||||
|
{
|
||||||
|
if (field.getNameAndType().getName().equals(f.getName()) && field.getClassEntry().getName().equals(f.getFields().getClassFile().getName()))
|
||||||
|
{
|
||||||
|
Class clazz = field.getClassEntry();
|
||||||
|
NameAndType nat = field.getNameAndType();
|
||||||
|
|
||||||
|
NameAndType newNat = new NameAndType(name, nat.getDescriptorType());
|
||||||
|
field = new Field(clazz, newNat);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,4 +80,17 @@ public class GetStatic extends Instruction implements GetFieldInstruction
|
|||||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||||
field = new Field(new Class(name), field.getNameAndType());
|
field = new Field(new Class(name), field.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameField(info.sigterm.deob.Field f, String name)
|
||||||
|
{
|
||||||
|
if (field.getNameAndType().getName().equals(f.getName()) && field.getClassEntry().getName().equals(f.getFields().getClassFile().getName()))
|
||||||
|
{
|
||||||
|
Class clazz = field.getClassEntry();
|
||||||
|
NameAndType nat = field.getNameAndType();
|
||||||
|
|
||||||
|
NameAndType newNat = new NameAndType(name, nat.getDescriptorType());
|
||||||
|
field = new Field(clazz, newNat);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import info.sigterm.deob.execution.Stack;
|
|||||||
import info.sigterm.deob.execution.StackContext;
|
import info.sigterm.deob.execution.StackContext;
|
||||||
import info.sigterm.deob.pool.Class;
|
import info.sigterm.deob.pool.Class;
|
||||||
import info.sigterm.deob.pool.Field;
|
import info.sigterm.deob.pool.Field;
|
||||||
|
import info.sigterm.deob.pool.NameAndType;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -61,4 +62,17 @@ public class PutField extends Instruction implements SetFieldInstruction
|
|||||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||||
field = new Field(new Class(name), field.getNameAndType());
|
field = new Field(new Class(name), field.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameField(info.sigterm.deob.Field f, String name)
|
||||||
|
{
|
||||||
|
if (field.getNameAndType().getName().equals(f.getName()) && field.getClassEntry().getName().equals(f.getFields().getClassFile().getName()))
|
||||||
|
{
|
||||||
|
Class clazz = field.getClassEntry();
|
||||||
|
NameAndType nat = field.getNameAndType();
|
||||||
|
|
||||||
|
NameAndType newNat = new NameAndType(name, nat.getDescriptorType());
|
||||||
|
field = new Field(clazz, newNat);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import info.sigterm.deob.execution.Stack;
|
|||||||
import info.sigterm.deob.execution.StackContext;
|
import info.sigterm.deob.execution.StackContext;
|
||||||
import info.sigterm.deob.pool.Class;
|
import info.sigterm.deob.pool.Class;
|
||||||
import info.sigterm.deob.pool.Field;
|
import info.sigterm.deob.pool.Field;
|
||||||
|
import info.sigterm.deob.pool.NameAndType;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -60,4 +61,17 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
|||||||
if (field.getClassEntry().getName().equals(cf.getName()))
|
if (field.getClassEntry().getName().equals(cf.getName()))
|
||||||
field = new Field(new Class(name), field.getNameAndType());
|
field = new Field(new Class(name), field.getNameAndType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameField(info.sigterm.deob.Field f, String name)
|
||||||
|
{
|
||||||
|
if (field.getNameAndType().getName().equals(f.getName()) && field.getClassEntry().getName().equals(f.getFields().getClassFile().getName()))
|
||||||
|
{
|
||||||
|
Class clazz = field.getClassEntry();
|
||||||
|
NameAndType nat = field.getNameAndType();
|
||||||
|
|
||||||
|
NameAndType newNat = new NameAndType(name, nat.getDescriptorType());
|
||||||
|
field = new Field(clazz, newNat);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import info.sigterm.deob.ClassFile;
|
import info.sigterm.deob.ClassFile;
|
||||||
import info.sigterm.deob.ClassGroup;
|
import info.sigterm.deob.ClassGroup;
|
||||||
|
import info.sigterm.deob.Field;
|
||||||
import info.sigterm.deob.Interfaces;
|
import info.sigterm.deob.Interfaces;
|
||||||
import info.sigterm.deob.Method;
|
import info.sigterm.deob.Method;
|
||||||
import info.sigterm.deob.attributes.code.Exceptions;
|
import info.sigterm.deob.attributes.code.Exceptions;
|
||||||
@@ -74,21 +75,51 @@ public class RenameUnique
|
|||||||
cf.setName(name);
|
cf.setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void renameField(ClassGroup group, Field field, String name)
|
||||||
|
{
|
||||||
|
for (ClassFile c : group.getClasses())
|
||||||
|
{
|
||||||
|
for (Method method : c.getMethods().getMethods())
|
||||||
|
{
|
||||||
|
// rename on instructions
|
||||||
|
if (method.getCode() != null)
|
||||||
|
{
|
||||||
|
Instructions instructions = method.getCode().getInstructions();
|
||||||
|
instructions.renameField(field, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
field.setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
public void run(ClassGroup group)
|
public void run(ClassGroup group)
|
||||||
{
|
{
|
||||||
group.buildClassGraph();
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int classes = 0, fields = 0, methods = 0;
|
||||||
|
|
||||||
for (ClassFile cf : group.getClasses())
|
for (ClassFile cf : group.getClasses())
|
||||||
{
|
{
|
||||||
if (cf.getName().length() > 2)
|
if (cf.getName().length() > 2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
renameClass(group, cf, "class" + i++);
|
renameClass(group, cf, "class" + i++);
|
||||||
|
++classes;
|
||||||
// rename method
|
|
||||||
|
|
||||||
// rename fields
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rename fields
|
||||||
|
for (ClassFile cf : group.getClasses())
|
||||||
|
for (Field field : cf.getFields().getFields())
|
||||||
|
{
|
||||||
|
if (field.getName().length() > 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
renameField(group, field, "field" + i++);
|
||||||
|
++fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rename methods
|
||||||
|
|
||||||
|
System.out.println("Uniquely renamed " + classes + " classes, " + fields + " fields, and " + methods + " methods");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ public class NameAndType extends PoolEntry
|
|||||||
this.signature = sig;
|
this.signature = sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NameAndType(java.lang.String name, Type type)
|
||||||
|
{
|
||||||
|
super(ConstantType.NAME_AND_TYPE);
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve(ConstantPool pool)
|
public void resolve(ConstantPool pool)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user