donot store empty AVM2 instruction operands array

This commit is contained in:
2014-09-06 21:51:32 +02:00
parent 8285a455b3
commit 334e6be6db
41 changed files with 88 additions and 84 deletions
@@ -796,7 +796,7 @@ public class AVM2Code implements Serializable {
di.name = instr.instructionName;
}
if (instr != null) {
int[] actualOperands;
int[] actualOperands = null;
if (instructionCode == 0x1b) { //switch
int firstOperand = ais.readS24("firstOperand");
int case_count = ais.readU30("case_count");
@@ -807,21 +807,23 @@ public class AVM2Code implements Serializable {
actualOperands[2 + c] = ais.readS24("actualOperand");
}
} else {
actualOperands = new int[instr.operands.length];
for (int op = 0; op < instr.operands.length; op++) {
switch (instr.operands[op] & 0xff00) {
case OPT_U30:
actualOperands[op] = ais.readU30("operand");
break;
case OPT_U8:
actualOperands[op] = ais.read("operand");
break;
case OPT_BYTE:
actualOperands[op] = (byte) ais.read("operand");
break;
case OPT_S24:
actualOperands[op] = ais.readS24("operand");
break;
if (instr.operands.length > 0) {
actualOperands = new int[instr.operands.length];
for (int op = 0; op < instr.operands.length; op++) {
switch (instr.operands[op] & 0xff00) {
case OPT_U30:
actualOperands[op] = ais.readU30("operand");
break;
case OPT_U8:
actualOperands[op] = ais.read("operand");
break;
case OPT_BYTE:
actualOperands[op] = (byte) ais.read("operand");
break;
case OPT_S24:
actualOperands[op] = ais.readS24("operand");
break;
}
}
}
}
@@ -52,7 +52,7 @@ public class AVM2Instruction implements Serializable, GraphSourceItem {
public AVM2Instruction(long offset, InstructionDefinition definition, int[] operands) {
this.definition = definition;
this.operands = operands;
this.operands = operands != null && operands.length > 0 ? operands : null;
this.offset = offset;
}
@@ -95,9 +95,11 @@ public class AVM2Instruction implements Serializable, GraphSourceItem {
public String toString() {
StringBuilder s = new StringBuilder();
s.append(definition.instructionName);
for (int i = 0; i < operands.length; i++) {
s.append(" ");
s.append(operands[i]);
if (operands != null) {
for (int i = 0; i < operands.length; i++) {
s.append(" ");
s.append(operands[i]);
}
}
return s.toString();
}
@@ -117,7 +117,7 @@ public abstract class AVM2Item extends GraphTargetItem {
return toSource(localData, generator);
}
List<GraphSourceItem> ret = toSource(localData, generator);
ret.add(new AVM2Instruction(0, new PopIns(), new int[]{}));
ret.add(new AVM2Instruction(0, new PopIns(), null));
return ret;
}
@@ -57,7 +57,7 @@ public class BooleanAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator,
new AVM2Instruction(0, value ? new PushTrueIns() : new PushFalseIns(), new int[]{})
new AVM2Instruction(0, value ? new PushTrueIns() : new PushFalseIns(), null)
);
}
@@ -113,22 +113,22 @@ public class CoerceAVM2Item extends AVM2Item {
AVM2Instruction ins;
switch (typeObj.toString()) {
case "*":
ins = new AVM2Instruction(0, new CoerceAIns(), new int[]{});
ins = new AVM2Instruction(0, new CoerceAIns(), null);
break;
case "String":
ins = new AVM2Instruction(0, new CoerceSIns(), new int[]{});
ins = new AVM2Instruction(0, new CoerceSIns(), null);
break;
case "Boolean":
ins = new AVM2Instruction(0, new ConvertBIns(), new int[]{});
ins = new AVM2Instruction(0, new ConvertBIns(), null);
break;
case "int":
ins = new AVM2Instruction(0, new ConvertIIns(), new int[]{});
ins = new AVM2Instruction(0, new ConvertIIns(), null);
break;
case "uint":
ins = new AVM2Instruction(0, new ConvertUIns(), new int[]{});
ins = new AVM2Instruction(0, new ConvertUIns(), null);
break;
case "Number":
ins = new AVM2Instruction(0, new ConvertDIns(), new int[]{});
ins = new AVM2Instruction(0, new ConvertDIns(), null);
break;
default:
int type_index = AVM2SourceGenerator.resolveType(localData, typeObj, ((AVM2SourceGenerator) generator).abc, (((AVM2SourceGenerator) generator).allABCs));
@@ -93,16 +93,16 @@ public class LocalRegAVM2Item extends AVM2Item {
AVM2Instruction ins;
switch (regIndex) {
case 0:
ins = new AVM2Instruction(0, new GetLocal0Ins(), new int[]{});
ins = new AVM2Instruction(0, new GetLocal0Ins(), null);
break;
case 1:
ins = new AVM2Instruction(0, new GetLocal1Ins(), new int[]{});
ins = new AVM2Instruction(0, new GetLocal1Ins(), null);
break;
case 2:
ins = new AVM2Instruction(0, new GetLocal2Ins(), new int[]{});
ins = new AVM2Instruction(0, new GetLocal2Ins(), null);
break;
case 3:
ins = new AVM2Instruction(0, new GetLocal3Ins(), new int[]{});
ins = new AVM2Instruction(0, new GetLocal3Ins(), null);
break;
default:
ins = new AVM2Instruction(0, new GetLocalIns(), new int[]{regIndex});
@@ -42,7 +42,7 @@ public class NanAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator,
new AVM2Instruction(0, new PushNanIns(), new int[]{})
new AVM2Instruction(0, new PushNanIns(), null)
);
}
@@ -54,7 +54,7 @@ public class NullAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator,
new AVM2Instruction(0, new PushNullIns(), new int[]{})
new AVM2Instruction(0, new PushNullIns(), null)
);
}
@@ -71,23 +71,23 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig
AVM2Instruction ins;
switch (regIndex) {
case 0:
ins = new AVM2Instruction(0, new SetLocal0Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal0Ins(), null);
break;
case 1:
ins = new AVM2Instruction(0, new SetLocal1Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal1Ins(), null);
break;
case 2:
ins = new AVM2Instruction(0, new SetLocal2Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal2Ins(), null);
break;
case 3:
ins = new AVM2Instruction(0, new SetLocal3Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal3Ins(), null);
break;
default:
ins = new AVM2Instruction(0, new SetLocalIns(), new int[]{regIndex});
break;
}
return toSourceMerge(localData, generator, value,
new AVM2Instruction(0, new DupIns(), new int[]{}), ins);
new AVM2Instruction(0, new DupIns(), null), ins);
}
@Override
@@ -95,16 +95,16 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig
AVM2Instruction ins;
switch (regIndex) {
case 0:
ins = new AVM2Instruction(0, new SetLocal0Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal0Ins(), null);
break;
case 1:
ins = new AVM2Instruction(0, new SetLocal1Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal1Ins(), null);
break;
case 2:
ins = new AVM2Instruction(0, new SetLocal2Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal2Ins(), null);
break;
case 3:
ins = new AVM2Instruction(0, new SetLocal3Ins(), new int[]{});
ins = new AVM2Instruction(0, new SetLocal3Ins(), null);
break;
default:
ins = new AVM2Instruction(0, new SetLocalIns(), new int[]{regIndex});
@@ -50,7 +50,7 @@ public class ThisAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, new AVM2Instruction(0, new GetLocal0Ins(), new int[]{})
return toSourceMerge(localData, generator, new AVM2Instruction(0, new GetLocal0Ins(), null)
);
}
@@ -64,7 +64,7 @@ public class UndefinedAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator,
new AVM2Instruction(0, new PushUndefinedIns(), new int[]{})
new AVM2Instruction(0, new PushUndefinedIns(), null)
);
}
}
@@ -75,12 +75,12 @@ public class AddAVM2Item extends BinaryOpItem {
IntegerValueAVM2Item iv = (IntegerValueAVM2Item) rightSide;
if (iv.value == 1) {
return toSourceMerge(localData, generator, leftSide,
new AVM2Instruction(0, new IncrementIns(), new int[]{})
new AVM2Instruction(0, new IncrementIns(), null)
);
}
}
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new AddIns(), new int[]{})
new AVM2Instruction(0, new AddIns(), null)
);
}
@@ -35,7 +35,7 @@ public class AsTypeAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new AsTypeLateIns(), new int[]{})
new AVM2Instruction(0, new AsTypeLateIns(), null)
);
}
@@ -42,7 +42,7 @@ public class BitAndAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new BitAndIns(), new int[]{})
new AVM2Instruction(0, new BitAndIns(), null)
);
}
@@ -42,7 +42,7 @@ public class BitNotAVM2Item extends UnaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value,
new AVM2Instruction(0, new BitNotIns(), new int[]{})
new AVM2Instruction(0, new BitNotIns(), null)
);
}
@@ -42,7 +42,7 @@ public class BitOrAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new BitOrIns(), new int[]{})
new AVM2Instruction(0, new BitOrIns(), null)
);
}
@@ -42,7 +42,7 @@ public class BitXorAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new BitXorIns(), new int[]{})
new AVM2Instruction(0, new BitXorIns(), null)
);
}
@@ -69,7 +69,7 @@ public class DivideAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new DivideIns(), new int[]{})
new AVM2Instruction(0, new DivideIns(), null)
);
}
@@ -61,7 +61,7 @@ public class EqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new EqualsIns(), new int[]{})
new AVM2Instruction(0, new EqualsIns(), null)
);
}
@@ -68,7 +68,7 @@ public class GeAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new GreaterEqualsIns(), new int[]{})
new AVM2Instruction(0, new GreaterEqualsIns(), null)
);
}
@@ -61,7 +61,7 @@ public class GtAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new GreaterThanIns(), new int[]{})
new AVM2Instruction(0, new GreaterThanIns(), null)
);
}
@@ -36,7 +36,7 @@ public class InAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new InIns(), new int[]{})
new AVM2Instruction(0, new InIns(), null)
);
}
@@ -36,7 +36,7 @@ public class InstanceOfAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new InstanceOfIns(), new int[]{})
new AVM2Instruction(0, new InstanceOfIns(), null)
);
}
@@ -36,7 +36,7 @@ public class IsTypeAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new IsTypeLateIns(), new int[]{})
new AVM2Instruction(0, new IsTypeLateIns(), null)
);
}
@@ -42,7 +42,7 @@ public class LShiftAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new LShiftIns(), new int[]{})
new AVM2Instruction(0, new LShiftIns(), null)
);
}
@@ -68,7 +68,7 @@ public class LeAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new LessEqualsIns(), new int[]{})
new AVM2Instruction(0, new LessEqualsIns(), null)
);
}
@@ -61,7 +61,7 @@ public class LtAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new LessThanIns(), new int[]{})
new AVM2Instruction(0, new LessThanIns(), null)
);
}
@@ -69,7 +69,7 @@ public class ModuloAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new ModuloIns(), new int[]{})
new AVM2Instruction(0, new ModuloIns(), null)
);
}
@@ -66,7 +66,7 @@ public class MultiplyAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new MultiplyIns(), new int[]{})
new AVM2Instruction(0, new MultiplyIns(), null)
);
}
@@ -42,7 +42,7 @@ public class NegAVM2Item extends UnaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value,
new AVM2Instruction(0, new NegateIns(), new int[]{})
new AVM2Instruction(0, new NegateIns(), null)
);
}
@@ -62,8 +62,8 @@ public class NeqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondit
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new EqualsIns(), new int[]{}),
new AVM2Instruction(0, new NotIns(), new int[]{})
new AVM2Instruction(0, new EqualsIns(), null),
new AVM2Instruction(0, new NotIns(), null)
);
}
@@ -42,7 +42,7 @@ public class RShiftAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new RShiftIns(), new int[]{})
new AVM2Instruction(0, new RShiftIns(), null)
);
}
@@ -64,7 +64,7 @@ public class StrictEqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfC
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new StrictEqualsIns(), new int[]{})
new AVM2Instruction(0, new StrictEqualsIns(), null)
);
}
@@ -65,8 +65,8 @@ public class StrictNeqAVM2Item extends BinaryOpItem implements LogicalOpItem, If
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new StrictEqualsIns(), new int[]{}),
new AVM2Instruction(0, new NotIns(), new int[]{})
new AVM2Instruction(0, new StrictEqualsIns(), null),
new AVM2Instruction(0, new NotIns(), null)
);
}
@@ -72,12 +72,12 @@ public class SubtractAVM2Item extends BinaryOpItem {
IntegerValueAVM2Item iv = (IntegerValueAVM2Item) rightSide;
if (iv.value == 1) {
return toSourceMerge(localData, generator, leftSide,
new AVM2Instruction(0, new DecrementIns(), new int[]{})
new AVM2Instruction(0, new DecrementIns(), null)
);
}
}
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new SubtractIns(), new int[]{})
new AVM2Instruction(0, new SubtractIns(), null)
);
}
@@ -71,7 +71,7 @@ public class TypeOfAVM2Item extends UnaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value,
new AVM2Instruction(0, new TypeOfIns(), new int[]{})
new AVM2Instruction(0, new TypeOfIns(), null)
);
}
@@ -42,7 +42,7 @@ public class URShiftAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new URShiftIns(), new int[]{})
new AVM2Instruction(0, new URShiftIns(), null)
);
}
@@ -889,7 +889,7 @@ public class ASM3Parser {
}
}
if (symb.value.toString().toLowerCase().equals("ffdec_deobfuscatepop")) {
lastIns = new AVM2Instruction(offset, new DeobfuscatePopIns(), new int[0]);
lastIns = new AVM2Instruction(offset, new DeobfuscatePopIns(), null);
code.code.add(lastIns);
offset += lastIns.getBytes().length;
insFound = true;
@@ -1680,7 +1680,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
if (ac == -1) {
if (parentConstMinAC == 0) {
mbodyCode.add(0, new AVM2Instruction(0, new GetLocal0Ins(), new int[]{}));
mbodyCode.add(0, new AVM2Instruction(0, new GetLocal0Ins(), null));
mbodyCode.add(1, new AVM2Instruction(0, new ConstructSuperIns(), new int[]{0}));
} else {
@@ -1689,8 +1689,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
}
if (className != null) {//It's method, not (inner) function
mbodyCode.add(0, new AVM2Instruction(0, new GetLocal0Ins(), new int[]{}));
mbodyCode.add(1, new AVM2Instruction(0, new PushScopeIns(), new int[]{}));
mbodyCode.add(0, new AVM2Instruction(0, new GetLocal0Ins(), null));
mbodyCode.add(1, new AVM2Instruction(0, new PushScopeIns(), null));
}
boolean addRet = false;
if (!mbodyCode.isEmpty()) {
@@ -1703,10 +1703,10 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
if (addRet) {
if (retType.toString().equals("*") || retType.toString().equals("void") || constructor) {
mbodyCode.add(new AVM2Instruction(0, new ReturnVoidIns(), new int[]{}));
mbodyCode.add(new AVM2Instruction(0, new ReturnVoidIns(), null));
} else {
mbodyCode.add(new AVM2Instruction(0, new PushUndefinedIns(), new int[]{}));
mbodyCode.add(new AVM2Instruction(0, new ReturnValueIns(), new int[]{}));
mbodyCode.add(new AVM2Instruction(0, new PushUndefinedIns(), null));
mbodyCode.add(new AVM2Instruction(0, new ReturnValueIns(), null));
}
}
mbody.exceptions = localData.exceptions.toArray(new ABCException[localData.exceptions.size()]);
@@ -29,7 +29,7 @@ public class ExceptionMarkAVM2Instruction extends AVM2Instruction {
public int exceptionId;
public ExceptionMarkAVM2Instruction(int exceptionId, int markType) {
super(0, null, new int[0]);
super(0, null, null);
this.markType = markType;
this.exceptionId = exceptionId;
this.definition = new InstructionDefinition(0, "--mark", new int[0]);
@@ -203,7 +203,7 @@ public class MethodBody implements Cloneable, Serializable {
HashMap<Integer, String> localRegNames = getLocalRegNames(abc);
writer.startMethod(this.method_info);
if (Configuration.showMethodBodyId.get()) {
writer.appendNoHilight("// method body id:");
writer.appendNoHilight("// method body id: ");
writer.appendNoHilight(abc.findBodyIndex(this.method_info));
writer.newLine();
}