Make specific/generic to try and allow changing constants without having to change instructions

This commit is contained in:
Adam
2015-09-26 23:59:05 -04:00
parent 9a5d2c801f
commit 9efef8aa59
10 changed files with 129 additions and 1 deletions

View File

@@ -228,4 +228,14 @@ public abstract class Instruction
public void renameMethod(Method oldMethod, net.runelite.deob.pool.Method newMethod)
{
}
public Instruction makeGeneric()
{
return this;
}
public Instruction makeSpecific()
{
return this;
}
}

View File

@@ -43,8 +43,14 @@ public class Instructions
{
Constructor<? extends Instruction> con = type.getInstructionClass().getConstructor(Instructions.class, InstructionType.class, int.class);
Instruction ins = con.newInstance(this, type, pc);
Instruction genericIns = ins.makeGeneric();
if (genericIns != ins)
{
genericIns.setPc(ins.getPc());
}
instructions.add(ins);
instructions.add(genericIns);
int len = ins.getLength();
pc += len;
@@ -168,6 +174,16 @@ public class Instructions
public void write(DataOutputStream out) throws IOException
{
// trnaslate instructions to specific
for (Instruction i : new ArrayList<>(instructions))
{
Instruction specific = i.makeSpecific();
if (i != specific)
{
replace(i, specific);
}
}
// generate pool indexes
for (Instruction i : new ArrayList<>(instructions))
i.prime();

View File

@@ -18,6 +18,11 @@ public class IConst_0 extends Instruction implements PushConstantInstruction
{
super(instructions, type, pc);
}
public IConst_0(Instructions instructions)
{
super(instructions, InstructionType.ICONST_0, 0);
}
@Override
public void execute(Frame frame)
@@ -44,4 +49,10 @@ public class IConst_0 extends Instruction implements PushConstantInstruction
{
return new LDC_W(this.getInstructions(), entry);
}
@Override
public Instruction makeGeneric()
{
return new LDC_W(this.getInstructions(), getConstant());
}
}

View File

@@ -18,6 +18,11 @@ public class IConst_1 extends Instruction implements PushConstantInstruction
{
super(instructions, type, pc);
}
public IConst_1(Instructions instructions)
{
super(instructions, InstructionType.ICONST_1, 0);
}
@Override
public void execute(Frame frame)
@@ -44,4 +49,10 @@ public class IConst_1 extends Instruction implements PushConstantInstruction
{
return new LDC_W(this.getInstructions(), entry);
}
@Override
public Instruction makeGeneric()
{
return new LDC_W(this.getInstructions(), getConstant());
}
}

View File

@@ -18,6 +18,11 @@ public class IConst_2 extends Instruction implements PushConstantInstruction
{
super(instructions, type, pc);
}
public IConst_2(Instructions instructions)
{
super(instructions, InstructionType.ICONST_2, 0);
}
@Override
public void execute(Frame frame)
@@ -44,4 +49,10 @@ public class IConst_2 extends Instruction implements PushConstantInstruction
{
return new LDC_W(this.getInstructions(), entry);
}
@Override
public Instruction makeGeneric()
{
return new LDC_W(this.getInstructions(), getConstant());
}
}

View File

@@ -18,6 +18,11 @@ public class IConst_3 extends Instruction implements PushConstantInstruction
{
super(instructions, type, pc);
}
public IConst_3(Instructions instructions)
{
super(instructions, InstructionType.ICONST_3, 0);
}
@Override
public void execute(Frame frame)
@@ -44,4 +49,10 @@ public class IConst_3 extends Instruction implements PushConstantInstruction
{
return new LDC_W(this.getInstructions(), entry);
}
@Override
public Instruction makeGeneric()
{
return new LDC_W(this.getInstructions(), getConstant());
}
}

View File

@@ -18,6 +18,11 @@ public class IConst_4 extends Instruction implements PushConstantInstruction
{
super(instructions, type, pc);
}
public IConst_4(Instructions instructions)
{
super(instructions, InstructionType.ICONST_4, 0);
}
@Override
public void execute(Frame frame)
@@ -44,4 +49,10 @@ public class IConst_4 extends Instruction implements PushConstantInstruction
{
return new LDC_W(this.getInstructions(), entry);
}
@Override
public Instruction makeGeneric()
{
return new LDC_W(this.getInstructions(), getConstant());
}
}

View File

@@ -18,6 +18,11 @@ public class IConst_5 extends Instruction implements PushConstantInstruction
{
super(instructions, type, pc);
}
public IConst_5(Instructions instructions)
{
super(instructions, InstructionType.ICONST_5, 0);
}
@Override
public void execute(Frame frame)
@@ -44,4 +49,10 @@ public class IConst_5 extends Instruction implements PushConstantInstruction
{
return new LDC_W(this.getInstructions(), entry);
}
@Override
public Instruction makeGeneric()
{
return new LDC_W(this.getInstructions(), getConstant());
}
}

View File

@@ -18,6 +18,11 @@ public class IConst_M1 extends Instruction implements PushConstantInstruction
{
super(instructions, type, pc);
}
public IConst_M1(Instructions instructions)
{
super(instructions, InstructionType.ICONST_M1, 0);
}
@Override
public void execute(Frame frame)

View File

@@ -110,4 +110,35 @@ public class LDC_W extends Instruction implements PushConstantInstruction
value = entry;
return this;
}
@Override
public Instruction makeSpecific()
{
switch (value.getType())
{
case INTEGER:
{
int i = (int) value.getObject();
switch (i)
{
case -1:
return new IConst_M1(this.getInstructions());
case 0:
return new IConst_0(this.getInstructions());
case 1:
return new IConst_1(this.getInstructions());
case 2:
return new IConst_2(this.getInstructions());
case 3:
return new IConst_3(this.getInstructions());
case 4:
return new IConst_4(this.getInstructions());
case 5:
return new IConst_5(this.getInstructions());
}
}
}
return super.makeSpecific();
}
}