Exemplo n.º 1
0
  @Override
  public void translate(
      AVM2LocalData localData,
      TranslateStack stack,
      AVM2Instruction ins,
      List<GraphTargetItem> output,
      String path)
      throws InterruptedException {
    int argCount = ins.operands[0];
    List<GraphTargetItem> args = new ArrayList<>();
    for (int a = 0; a < argCount; a++) {
      args.add(0, stack.pop());
    }
    GraphTargetItem obj = stack.pop();

    boolean isXML = false;
    if (obj instanceof GetPropertyAVM2Item) {
      GetPropertyAVM2Item gpt = (GetPropertyAVM2Item) obj;
      if (gpt.object instanceof FindPropertyAVM2Item) {
        FindPropertyAVM2Item fpt = (FindPropertyAVM2Item) gpt.object;
        FullMultinameAVM2Item fptXmlMult = (FullMultinameAVM2Item) fpt.propertyName;
        FullMultinameAVM2Item gptXmlMult = (FullMultinameAVM2Item) gpt.propertyName;

        isXML =
            fptXmlMult.isXML(
                    localData.getConstants(),
                    localData.localRegNames,
                    localData.fullyQualifiedNames)
                && gptXmlMult.isXML(
                    localData.getConstants(),
                    localData.localRegNames,
                    localData.fullyQualifiedNames);
      }
    }
    if (obj instanceof GetLexAVM2Item) {
      GetLexAVM2Item glt = (GetLexAVM2Item) obj;
      isXML =
          glt.propertyName
              .getName(localData.getConstants(), localData.fullyQualifiedNames, true)
              .equals("XML");
    }

    if (isXML) {
      if (args.size() == 1) {
        GraphTargetItem arg = args.get(0);
        List<GraphTargetItem> xmlLines = new ArrayList<>();
        if (walkXML(arg, xmlLines)) {
          stack.push(new XMLAVM2Item(ins, xmlLines));
          return;
        }
      }
    }

    stack.push(new ConstructAVM2Item(ins, obj, args));
  }
Exemplo n.º 2
0
 @Override
 public void translate(
     boolean isStatic,
     int scriptIndex,
     int classIndex,
     HashMap<Integer, GraphTargetItem> localRegs,
     TranslateStack stack,
     ScopeStack scopeStack,
     AVM2ConstantPool constants,
     AVM2Instruction ins,
     List<MethodInfo> method_info,
     List<GraphTargetItem> output,
     MethodBody body,
     ABC abc,
     HashMap<Integer, String> localRegNames,
     List<String> fullyQualifiedNames,
     String path,
     HashMap<Integer, Integer> localRegsAssignmentIps,
     int ip,
     HashMap<Integer, List<Integer>> refs,
     AVM2Code code) {
   GraphTargetItem v2 = stack.pop();
   GraphTargetItem v1 = stack.pop();
   stack.push(new EqAVM2Item(ins, v1, v2));
 }
Exemplo n.º 3
0
 @Override
 public void translate(
     boolean isStatic,
     int scriptIndex,
     int classIndex,
     HashMap<Integer, GraphTargetItem> localRegs,
     TranslateStack stack,
     ScopeStack scopeStack,
     AVM2ConstantPool constants,
     AVM2Instruction ins,
     List<MethodInfo> method_info,
     List<GraphTargetItem> output,
     MethodBody body,
     ABC abc,
     HashMap<Integer, String> localRegNames,
     List<DottedChain> fullyQualifiedNames,
     String path,
     HashMap<Integer, Integer> localRegsAssignmentIps,
     int ip,
     HashMap<Integer, List<Integer>> refs,
     AVM2Code code) {
   int multinameIndex = ins.operands[0];
   FullMultinameAVM2Item multiname = resolveMultiname(stack, constants, multinameIndex, ins);
   GraphTargetItem obj = stack.pop();
   stack.push(new GetPropertyAVM2Item(ins, obj, multiname));
 }
 @Override
 public void translateContainer(
     List<List<GraphTargetItem>> content,
     GraphSourceItem lineStartItem,
     TranslateStack stack,
     List<GraphTargetItem> output,
     HashMap<Integer, String> regNames,
     HashMap<String, GraphTargetItem> variables,
     HashMap<String, GraphTargetItem> functions) {
   List<FunctionActionItem> funcList = new ArrayList<>();
   for (String key : functions.keySet()) {
     GraphTargetItem val = functions.get(key);
     if (val instanceof FunctionActionItem) {
       funcList.add((FunctionActionItem) val);
     }
   }
   FunctionActionItem fti =
       new FunctionActionItem(
           this,
           lineStartItem,
           functionName,
           paramNames,
           getRegNames(),
           content.get(0),
           constantPool,
           getFirstRegister(),
           new ArrayList<>(),
           funcList);
   functions.put(functionName, fti);
   stack.push(fti);
 }
 @Override
 public void translateInverted(
     HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, AVM2Instruction ins) {
   GraphTargetItem v2 = stack.pop();
   GraphTargetItem v1 = stack.pop();
   stack.push(new StrictEqAVM2Item(ins, v1, v2));
 }
Exemplo n.º 6
0
 @Override
 public void translate(
     AVM2LocalData localData,
     TranslateStack stack,
     AVM2Instruction ins,
     List<GraphTargetItem> output,
     String path) {
   stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
 }
 @Override
 public void translate(
     AVM2LocalData localData,
     TranslateStack stack,
     AVM2Instruction ins,
     List<GraphTargetItem> output,
     String path) {
   stack.push(new NewActivationAVM2Item(ins, localData.lineStartInstruction));
 }
 @Override
 public void translate(
     AVM2LocalData localData,
     TranslateStack stack,
     AVM2Instruction ins,
     List<GraphTargetItem> output,
     String path) {
   stack.push(new UndefinedAVM2Item(ins));
 }
Exemplo n.º 9
0
 @Override
 public void translate(
     AVM2LocalData localData,
     TranslateStack stack,
     AVM2Instruction ins,
     List<GraphTargetItem> output,
     String path) {
   GraphTargetItem obj = stack.pop();
   stack.push(new FilteredCheckAVM2Item(ins, localData.lineStartInstruction, obj));
 }
Exemplo n.º 10
0
 @Override
 public void translate(
     AVM2LocalData localData,
     TranslateStack stack,
     AVM2Instruction ins,
     List<GraphTargetItem> output,
     String path) {
   int multinameIndex = ins.operands[0];
   Multiname multiname = localData.getConstants().getMultiname(multinameIndex);
   stack.push(new GetLexAVM2Item(ins, multiname));
 }
Exemplo n.º 11
0
 @Override
 public void translate(
     AVM2LocalData localData,
     TranslateStack stack,
     AVM2Instruction ins,
     List<GraphTargetItem> output,
     String path) {
   GraphTargetItem v2 = stack.pop();
   GraphTargetItem v1 = stack.pop();
   stack.push(new LtAVM2Item(ins, localData.lineStartInstruction, v1, v2));
 }
 @Override
 public void translate(
     TranslateStack stack,
     List<GraphTargetItem> output,
     HashMap<Integer, String> regNames,
     HashMap<String, GraphTargetItem> variables,
     HashMap<String, GraphTargetItem> functions,
     int staticOperation,
     String path) {
   GraphTargetItem a = stack.pop();
   stack.push(new MBCharToAsciiActionItem(this, a));
 }
Exemplo n.º 13
0
 @Override
 public void translate(
     GraphSourceItem lineStartAction,
     TranslateStack stack,
     List<GraphTargetItem> output,
     HashMap<Integer, String> regNames,
     HashMap<String, GraphTargetItem> variables,
     HashMap<String, GraphTargetItem> functions,
     int staticOperation,
     String path) {
   GraphTargetItem object = stack.pop();
   stack.push(new TargetPathActionItem(this, lineStartAction, object));
 }
 @Override
 public void translate(
     TranslateStack stack,
     List<GraphTargetItem> output,
     HashMap<Integer, String> regNames,
     HashMap<String, GraphTargetItem> variables,
     HashMap<String, GraphTargetItem> functions,
     int staticOperation,
     String path) {
   GraphTargetItem value = stack.peek();
   stack.push(new DuplicateItem(this, value));
   value.getMoreSrc().add(new GraphSourceItemPos(this, 0));
 }
 @Override
 public void translateContainer(
     List<List<GraphTargetItem>> content,
     TranslateStack stack,
     List<GraphTargetItem> output,
     HashMap<Integer, String> regNames,
     HashMap<String, GraphTargetItem> variables,
     HashMap<String, GraphTargetItem> functions) {
   FunctionActionItem fti =
       new FunctionActionItem(
           this, functionName, paramNames, content.get(0), constantPool, 1, new ArrayList<>());
   // ActionGraph.translateViaGraph(regNames, variables, functions, code, version)
   stack.push(fti);
   functions.put(functionName, fti);
 }
Exemplo n.º 16
0
 @Override
 public void translate(
     AVM2LocalData localData,
     TranslateStack stack,
     AVM2Instruction ins,
     List<GraphTargetItem> output,
     String path) {
   int argCount = ins.operands[0];
   List<GraphTargetItem> args = new ArrayList<>();
   for (int a = 0; a < argCount; a++) {
     args.add(0, stack.pop());
   }
   GraphTargetItem receiver = stack.pop();
   GraphTargetItem function = stack.pop();
   stack.push(new CallAVM2Item(ins, localData.lineStartInstruction, receiver, function, args));
 }
Exemplo n.º 17
0
 @Override
 public void translate(
     TranslateStack stack,
     List<GraphTargetItem> output,
     HashMap<Integer, String> regNames,
     HashMap<String, GraphTargetItem> variables,
     HashMap<String, GraphTargetItem> functions,
     int staticOperation,
     String path) {
   GraphTargetItem methodName = stack.pop();
   GraphTargetItem scriptObject = stack.pop();
   long numArgs = popLong(stack);
   List<GraphTargetItem> args = new ArrayList<>();
   for (long l = 0; l < numArgs; l++) {
     args.add(stack.pop());
   }
   stack.push(new NewMethodActionItem(this, scriptObject, methodName, args));
 }
Exemplo n.º 18
0
 @Override
 public void translate(
     boolean isStatic,
     int scriptIndex,
     int classIndex,
     HashMap<Integer, GraphTargetItem> localRegs,
     TranslateStack stack,
     ScopeStack scopeStack,
     AVM2ConstantPool constants,
     AVM2Instruction ins,
     List<MethodInfo> method_info,
     List<GraphTargetItem> output,
     MethodBody body,
     ABC abc,
     HashMap<Integer, String> localRegNames,
     List<DottedChain> fullyQualifiedNames,
     String path,
     HashMap<Integer, Integer> localRegsAssignmentIps,
     int ip,
     HashMap<Integer, List<Integer>> refs,
     AVM2Code code) {
   stack.push(new IntegerValueAVM2Item(ins, constants.getUInt(ins.operands[0])));
 }
Exemplo n.º 19
0
  @Override
  public void translate(
      boolean isStatic,
      int scriptIndex,
      int classIndex,
      HashMap<Integer, GraphTargetItem> localRegs,
      TranslateStack stack,
      ScopeStack scopeStack,
      AVM2ConstantPool constants,
      AVM2Instruction ins,
      List<MethodInfo> method_info,
      List<GraphTargetItem> output,
      MethodBody body,
      ABC abc,
      HashMap<Integer, String> localRegNames,
      List<DottedChain> fullyQualifiedNames,
      String path,
      HashMap<Integer, Integer> localRegsAssignmentIps,
      int ip,
      HashMap<Integer, List<Integer>> refs,
      AVM2Code code) {
    int slotIndex = ins.operands[0];
    GraphTargetItem value = stack.pop();
    GraphTargetItem obj = stack.pop(); // scopeId
    GraphTargetItem objnoreg = obj;
    obj = obj.getThroughRegister();
    Multiname slotname = null;
    if (obj instanceof NewActivationAVM2Item) {
      ((NewActivationAVM2Item) obj).slots.put(slotIndex, value);
    }

    if (obj instanceof ExceptionAVM2Item) {
      slotname = constants.getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
    } else if (obj instanceof ClassAVM2Item) {
      slotname = ((ClassAVM2Item) obj).className;
    } else if (obj instanceof ThisAVM2Item) {
      slotname = ((ThisAVM2Item) obj).className;
    } else if (obj instanceof ScriptAVM2Item) {
      for (int t = 0;
          t < abc.script_info.get(((ScriptAVM2Item) obj).scriptIndex).traits.traits.size();
          t++) {
        Trait tr = abc.script_info.get(((ScriptAVM2Item) obj).scriptIndex).traits.traits.get(t);
        if (tr instanceof TraitWithSlot) {
          if (((TraitWithSlot) tr).getSlotIndex() == slotIndex) {
            slotname = tr.getName(abc);
          }
        }
      }
    } else if (obj instanceof NewActivationAVM2Item) {

      for (int t = 0; t < body.traits.traits.size(); t++) {
        if (body.traits.traits.get(t) instanceof TraitWithSlot) {
          if (((TraitWithSlot) body.traits.traits.get(t)).getSlotIndex() == slotIndex) {
            slotname = body.traits.traits.get(t).getName(abc);
          }
        }
      }
    }

    if (slotname != null) {
      if (value instanceof LocalRegAVM2Item) {
        LocalRegAVM2Item lr = (LocalRegAVM2Item) value;
        String slotNameStr = slotname.getName(constants, fullyQualifiedNames, true);
        if (localRegNames.containsKey(lr.regIndex)) {
          if (localRegNames.get(lr.regIndex).equals(slotNameStr)) {
            return; // Register with same name to slot
          }
        }
      }
    }

    if (value.getNotCoerced().getThroughDuplicate() instanceof IncrementAVM2Item) {
      GraphTargetItem inside =
          ((IncrementAVM2Item) value.getNotCoerced())
              .value
              .getThroughRegister()
              .getNotCoerced()
              .getThroughDuplicate();
      if (inside instanceof GetSlotAVM2Item) {
        GetSlotAVM2Item slotItem = (GetSlotAVM2Item) inside;
        if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
            && (slotItem.slotName == slotname)) {
          if (stack.size() > 0) {
            GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
            if (top == inside) {
              stack.pop();
              stack.push(new PostIncrementAVM2Item(ins, inside));
            } else if ((top instanceof IncrementAVM2Item)
                && (((IncrementAVM2Item) top).value == inside)) {
              stack.pop();
              stack.push(new PreIncrementAVM2Item(ins, inside));
            } else {
              output.add(new PostIncrementAVM2Item(ins, inside));
            }
          } else {
            output.add(new PostIncrementAVM2Item(ins, inside));
          }
          return;
        }
      }
    }

    if (value.getNotCoerced().getThroughDuplicate() instanceof DecrementAVM2Item) {
      GraphTargetItem inside =
          ((DecrementAVM2Item) value.getNotCoerced())
              .value
              .getThroughRegister()
              .getNotCoerced()
              .getThroughDuplicate();
      if (inside instanceof GetSlotAVM2Item) {
        GetSlotAVM2Item slotItem = (GetSlotAVM2Item) inside;
        if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
            && (slotItem.slotName == slotname)) {
          if (stack.size() > 0) {
            GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
            if (top == inside) {
              stack.pop();
              stack.push(new PostDecrementAVM2Item(ins, inside));
            } else if ((top instanceof DecrementAVM2Item)
                && (((DecrementAVM2Item) top).value == inside)) {
              stack.pop();
              stack.push(new PreDecrementAVM2Item(ins, inside));
            } else {
              output.add(new PostDecrementAVM2Item(ins, inside));
            }
          } else {
            output.add(new PostDecrementAVM2Item(ins, inside));
          }
          return;
        }
      }
    }

    output.add(new SetSlotAVM2Item(ins, obj, slotname, value));
  }
  @Override
  public void translate(
      TranslateStack stack,
      List<GraphTargetItem> output,
      HashMap<Integer, String> regNames,
      HashMap<String, GraphTargetItem> variables,
      HashMap<String, GraphTargetItem> functions,
      int staticOperation,
      String path) {
    GraphTargetItem value = stack.pop().getThroughDuplicate();
    GraphTargetItem memberName = stack.pop();
    GraphTargetItem object = stack.pop();
    if (value instanceof IncrementActionItem) {
      GraphTargetItem obj = ((IncrementActionItem) value).object;
      if (!stack.isEmpty() && stack.peek().valueEquals(obj)) {
        stack.pop();
        stack.push(new PostIncrementActionItem(this, obj));
        return;
      }
    }
    if (value instanceof DecrementActionItem) {
      GraphTargetItem obj = ((DecrementActionItem) value).object;
      if (!stack.isEmpty() && stack.peek().valueEquals(obj)) {
        stack.pop();
        stack.push(new PostDecrementActionItem(this, obj));
        return;
      }
    }

    if (value instanceof IncrementActionItem) {
      if (((IncrementActionItem) value).object instanceof GetMemberActionItem) {
        if (((GetMemberActionItem) ((IncrementActionItem) value).object).object.equals(object)) {
          if (((GetMemberActionItem) ((IncrementActionItem) value).object)
              .memberName.equals(memberName)) {
            output.add(new PostIncrementActionItem(this, ((IncrementActionItem) value).object));
            return;
          }
        }
      }
    }
    if (value instanceof DecrementActionItem) {
      if (((DecrementActionItem) value).object instanceof GetMemberActionItem) {
        if (((GetMemberActionItem) ((DecrementActionItem) value).object)
            .object.valueEquals(object)) {
          if (((GetMemberActionItem) ((DecrementActionItem) value).object)
              .memberName.equals(memberName)) {
            output.add(new PostDecrementActionItem(this, ((DecrementActionItem) value).object));
            return;
          }
        }
      }
    }
    GraphTargetItem ret = new SetMemberActionItem(this, object, memberName, value);
    if (value instanceof StoreRegisterActionItem) {
      StoreRegisterActionItem sr = (StoreRegisterActionItem) value;
      if (sr.define) {
        value = sr.getValue();
        ((SetMemberActionItem) ret).setValue(value);
        if (value instanceof IncrementActionItem) {
          if (((IncrementActionItem) value).object instanceof GetMemberActionItem) {
            if (((GetMemberActionItem) ((IncrementActionItem) value).object)
                .valueEquals(((SetMemberActionItem) ret).getObject())) {
              ret = new PreIncrementActionItem(this, ((IncrementActionItem) value).object);
            }
          }
        } else if (value instanceof DecrementActionItem) {
          if (((DecrementActionItem) value).object instanceof GetMemberActionItem) {
            if (((GetMemberActionItem) ((DecrementActionItem) value).object)
                .valueEquals(((SetMemberActionItem) ret).getObject())) {
              ret = new PreDecrementActionItem(this, ((DecrementActionItem) value).object);
            }
          }
        } else {
          sr.temporary = true;
          ((SetMemberActionItem) ret).setValue(sr);
        }
        variables.put(
            "__register" + sr.register.number, new TemporaryRegister(sr.register.number, ret));
        return;
      }
    }
    output.add(ret);
  }
  @Override
  public void translate(
      TranslateStack stack,
      List<GraphTargetItem> output,
      HashMap<Integer, String> regNames,
      HashMap<String, GraphTargetItem> variables,
      HashMap<String, GraphTargetItem> functions,
      int staticOperation,
      String path) {
    GraphTargetItem value = stack.pop();
    RegisterNumber rn = new RegisterNumber(registerNumber);
    if (regNames.containsKey(registerNumber)) {
      rn.name = regNames.get(registerNumber);
    }
    value.getMoreSrc().add(new GraphSourceItemPos(this, 0));
    if (variables.containsKey("__register" + registerNumber)) {
      if (variables.get("__register" + registerNumber) instanceof TemporaryRegister) {
        variables.remove("__register" + registerNumber);
      }
    }
    boolean define = !variables.containsKey("__register" + registerNumber);
    if (regNames.containsKey(registerNumber)) {
      define = false;
    }
    variables.put("__register" + registerNumber, value);
    if (value instanceof DirectValueActionItem) {
      if (((DirectValueActionItem) value).value instanceof RegisterNumber) {
        if (((RegisterNumber) ((DirectValueActionItem) value).value).number == registerNumber) {
          stack.push(value);
          return;
        }
      }
    }
    if (value instanceof StoreRegisterActionItem) {
      if (((StoreRegisterActionItem) value).register.number == registerNumber) {
        stack.push(value);
        return;
      }
    }

    if (value instanceof IncrementActionItem) {
      GraphTargetItem obj = ((IncrementActionItem) value).object;
      if (!stack.isEmpty()) {
        if (stack.peek().valueEquals(obj)) {
          stack.pop();
          stack.push(new PostIncrementActionItem(this, obj));
          stack.push(obj);
          return;
        }
      }
    }
    if (value instanceof DecrementActionItem) {
      GraphTargetItem obj = ((DecrementActionItem) value).object;
      if (!stack.isEmpty()) {
        if (stack.peek().valueEquals(obj)) {
          stack.pop();
          stack.push(new PostDecrementActionItem(this, obj));
          stack.push(obj);
          return;
        }
      }
    }
    stack.push(new StoreRegisterActionItem(this, rn, value, define));
  }