@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)); }
@Override public void translate( AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) { GraphTargetItem ofs = stack.pop(); GraphTargetItem value = stack.pop(); output.add(new AlchemyStoreAVM2Item(ins, value, ofs, 'i', 8)); }
protected FullMultinameAVM2Item resolveMultiname( TranslateStack stack, AVM2ConstantPool constants, int multinameIndex, AVM2Instruction ins) { GraphTargetItem ns = null; GraphTargetItem name = null; if (multinameIndex > 0 && multinameIndex < constants.constant_multiname.size()) { if (constants.getMultiname(multinameIndex).needsName()) { name = stack.pop(); } if (constants.getMultiname(multinameIndex).needsNs()) { ns = stack.pop(); } } return new FullMultinameAVM2Item(ins, multinameIndex, name, ns); }
@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 propertyName = stack.pop(); GraphTargetItem object = stack.pop(); stack.push(new DeleteActionItem(this, lineStartAction, object, propertyName)); }
@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 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)); }
@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)); }
@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)); }
@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 subclass = stack.pop(); long inCount = popLong(stack); List<GraphTargetItem> superclasses = new ArrayList<>(); for (long l = 0; l < inCount; l++) { superclasses.add(stack.pop()); } output.add(new ImplementsOpActionItem(this, subclass, superclasses)); }
@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)); }
@Override public void translate( AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) { output.add(new ThrowAVM2Item(ins, localData.lineStartInstruction, stack.pop())); }
@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) { GraphTargetItem obj = stack.pop(); stack.push(new FilteredCheckAVM2Item(ins, localData.lineStartInstruction, obj)); }
@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) { output.add(new WithActionItem(this, stack.pop(), content.get(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( GraphSourceItem lineStartAction, TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) { output.add(new CallActionItem(this, lineStartAction, stack.pop())); }
@Override public void translate( AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) { GraphTargetItem top = stack.pop(); if ((!(top instanceof MarkItem))) { output.add(top); } }
@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)); }
@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 object = stack.pop(); output.add(new EnumerateActionItem(this, object)); }
@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 a = stack.pop(); GraphTargetItem b = stack.pop(); stack.push(new AddActionItem(this, lineStartAction, b, a, false)); }
@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) throws InterruptedException { GraphTargetItem frame = stack.pop(); List<GraphTargetItem> body = ActionGraph.translateViaGraph( regNames, variables, functions, skipped, SWF.DEFAULT_VERSION, staticOperation, path); output.add(new IfFrameLoadedActionItem(frame, body, this)); }
@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)); }
@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 targetString = stack.pop(); GraphTargetItem urlString = stack.pop(); Integer num = null; if (targetString.isCompileTime()) { Object res = targetString.getResult(); if (res instanceof String) { String tarStr = (String) res; String levelPrefix = "_level"; if (tarStr.startsWith(levelPrefix)) { try { num = Integer.valueOf(tarStr.substring(levelPrefix.length())); } catch (NumberFormatException nfe) { } } } } if (loadVariablesFlag) { if (num != null) { output.add( new LoadVariablesNumActionItem( this, urlString, new DirectValueActionItem(null, 0, (Long) (long) (int) num, new ArrayList<>()), sendVarsMethod)); } else { output.add(new LoadVariablesActionItem(this, urlString, targetString, sendVarsMethod)); } } else if (loadTargetFlag) { if ((urlString instanceof DirectValueActionItem) && (urlString.getResult().equals(""))) { output.add(new UnLoadMovieActionItem(this, targetString)); } else { output.add(new LoadMovieActionItem(this, urlString, targetString, sendVarsMethod)); } } else { String printPrefix = "print:#"; String printAsBitmapPrefix = "printasbitmap:#"; String urlStr = null; if (urlString.isCompileTime() && (urlString.getResult() instanceof String)) { urlStr = (String) urlString.getResult(); } if (num != null) { if ("".equals(urlStr)) { output.add( new UnLoadMovieNumActionItem( this, new DirectValueActionItem(null, 0, (Long) (long) (int) num, new ArrayList<>()))); } else if (urlStr != null && urlStr.startsWith(printPrefix)) { output.add( new PrintNumActionItem( this, new DirectValueActionItem((Long) (long) (int) num), new DirectValueActionItem(urlStr.substring(printPrefix.length())))); } else if (urlStr != null && urlStr.startsWith(printAsBitmapPrefix)) { output.add( new PrintAsBitmapNumActionItem( this, new DirectValueActionItem((Long) (long) (int) num), new DirectValueActionItem(urlStr.substring(printAsBitmapPrefix.length())))); } else { output.add( new LoadMovieNumActionItem( this, urlString, new DirectValueActionItem(null, 0, (Long) (long) (int) num, new ArrayList<>()), sendVarsMethod)); } } else { if (urlStr != null && urlStr.startsWith(printPrefix)) { output.add( new PrintActionItem( this, targetString, new DirectValueActionItem(urlStr.substring(printPrefix.length())))); } else if (urlStr != null && urlStr.startsWith(printAsBitmapPrefix)) { output.add( new PrintAsBitmapActionItem( this, targetString, new DirectValueActionItem(urlStr.substring(printAsBitmapPrefix.length())))); } else { output.add(new GetURL2ActionItem(this, urlString, targetString, sendVarsMethod)); } } } }
@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); }