From f0809171e3da615eea382801adfaeda3ae8b03f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 1 Sep 2025 20:07:01 +0200 Subject: [PATCH] Checkstyle fix --- .../instructions/InstructionDefinition.java | 201 ++++++++---------- .../abc/avm2/instructions/stack/PopIns.java | 2 +- .../parser/script/ActionSourceGenerator.java | 73 +++---- .../src/com/jpexs/decompiler/graph/Graph.java | 27 +-- .../decompiler/graph/GraphTargetItem.java | 63 +++--- .../decompiler/graph/SourceGenerator.java | 20 +- .../decompiler/graph/TranslateStack.java | 158 +++++++------- .../decompiler/graph/model/DuplicateItem.java | 5 +- .../decompiler/graph/model/TemporaryItem.java | 7 +- 9 files changed, 276 insertions(+), 280 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java index 485625d33..69ad99380 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java @@ -523,7 +523,7 @@ public abstract class InstructionDefinition implements Serializable { Traits traits = null; if (obj instanceof NewActivationAVM2Item) { traits = localData.methodBody.traits; - } else if (obj instanceof ThisAVM2Item && localData.classIndex > -1) { + } else if (obj instanceof ThisAVM2Item && localData.classIndex > -1) { traits = localData.abc.instance_info.get(localData.classIndex).instance_traits; } else if (obj instanceof ClassAVM2Item && localData.classIndex > -1) { traits = localData.abc.class_info.get(localData.classIndex).static_traits; @@ -559,13 +559,12 @@ public abstract class InstructionDefinition implements Serializable { */ @SuppressWarnings("unchecked") public void handleSetProperty(boolean init, AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List output, String path) { - stack.allowSwap(output); + stack.allowSwap(output); int multinameIndex = ins.operands[0]; GraphTargetItem value = stack.pop(); FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins, output); GraphTargetItem obj = stack.pop(); - - + /* if ((value instanceof IncrementAVM2Item) || (value instanceof DecrementAVM2Item)) { boolean isIncrement = (value instanceof IncrementAVM2Item); @@ -678,16 +677,11 @@ public abstract class InstructionDefinition implements Serializable { } } }*/ - - - - - //TestIncDec5 no result AIR /* var _temp_5:* = a; _temp_5.attrib = _temp_5.attrib + 1; - */ + */ if (value instanceof IncrementAVM2Item || value instanceof DecrementAVM2Item) { boolean isIncrement = value instanceof IncrementAVM2Item; @@ -714,13 +708,13 @@ public abstract class InstructionDefinition implements Serializable { } } } - - //TestIncDec6 no result AIR + + //TestIncDec6 no result AIR //In air, this is *POST* inc/decrement /* var _temp_5:* = a; _temp_5.attrib = _temp_5.attrib + 1; - */ + */ if (value instanceof IncrementAVM2Item || value instanceof DecrementAVM2Item) { boolean isIncrement = value instanceof IncrementAVM2Item; @@ -749,19 +743,17 @@ public abstract class InstructionDefinition implements Serializable { } } } - - - + if (value instanceof LocalRegAVM2Item) { LocalRegAVM2Item valueLocalReg = (LocalRegAVM2Item) value; LocalRegAVM2Item nameLocalReg = null; if (multiname.name instanceof LocalRegAVM2Item) { nameLocalReg = (LocalRegAVM2Item) multiname.name; - } - + } + if (obj instanceof LocalRegAVM2Item) { LocalRegAVM2Item objLocalReg = (LocalRegAVM2Item) obj; - + //TestIncDec3 with result /* //var _temp_5:* = §§findproperty(trace); @@ -771,7 +763,7 @@ public abstract class InstructionDefinition implements Serializable { var _temp_4:* = _loc4_ = (_loc2_ = a)[_loc3_ = 2] + 1; _loc2_[_loc3_] = _loc4_; trace(_temp_4); - */ + */ if (!stack.isEmpty() && stack.peek() instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) stack.peek(); if (setLocValue.value instanceof IncrementAVM2Item @@ -786,15 +778,15 @@ public abstract class InstructionDefinition implements Serializable { if (fm.name instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocName = (SetLocalAVM2Item) fm.name; if (valueLocalReg.regIndex == setLocValue.regIndex - && objLocalReg.regIndex == setLocObj.regIndex - && nameLocalReg.regIndex == setLocName.regIndex) { + && objLocalReg.regIndex == setLocObj.regIndex + && nameLocalReg.regIndex == setLocName.regIndex) { getProp.object = setLocObj.value; fm.name = setLocName.value; stack.pop(); if (isIncrement) { stack.push(new PreIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.push(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.push(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } @@ -804,15 +796,14 @@ public abstract class InstructionDefinition implements Serializable { } } } - + //TestIncDec3 no result /* var _loc2_:* = a; var _loc3_:int; var _loc4_:* = _loc2_[_loc3_ = 2] + 1; _loc2_[_loc3_] = _loc4_; - */ - + */ if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) output.get(output.size() - 1); if (setLocValue.value instanceof IncrementAVM2Item @@ -827,15 +818,15 @@ public abstract class InstructionDefinition implements Serializable { if (fm.name instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocName = (SetLocalAVM2Item) fm.name; if (valueLocalReg.regIndex == setLocValue.regIndex - && objLocalReg.regIndex == setLocObj.regIndex - && nameLocalReg.regIndex == setLocName.regIndex) { + && objLocalReg.regIndex == setLocObj.regIndex + && nameLocalReg.regIndex == setLocName.regIndex) { getProp.object = setLocObj.value; fm.name = setLocName.value; output.remove(output.size() - 1); if (isIncrement) { stack.addToOutput(new PreIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.addToOutput(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.addToOutput(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } @@ -845,8 +836,7 @@ public abstract class InstructionDefinition implements Serializable { } } } - - + //TestIncDec4 with result /* var _temp_4:* = §§findproperty(trace); @@ -856,7 +846,7 @@ public abstract class InstructionDefinition implements Serializable { var _loc4_:* = _temp_3 + 1; _loc2_[_loc3_] = _loc4_; trace(_temp_3); - */ + */ if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) output.get(output.size() - 1); if (setLocValue.value instanceof IncrementAVM2Item @@ -864,7 +854,7 @@ public abstract class InstructionDefinition implements Serializable { boolean isIncrement = setLocValue.value instanceof IncrementAVM2Item; if (setLocValue.value.value instanceof DuplicateItem) { DuplicateItem d = (DuplicateItem) setLocValue.value.value; - if (output.size() >= 2 + if (output.size() >= 2 && output.get(output.size() - 2) instanceof PushItem && output.get(output.size() - 2).value instanceof DuplicateSourceItem) { DuplicateSourceItem ds = (DuplicateSourceItem) output.get(output.size() - 2).value; @@ -882,8 +872,8 @@ public abstract class InstructionDefinition implements Serializable { if (fm.name instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocName = (SetLocalAVM2Item) fm.name; if (valueLocalReg.regIndex == setLocValue.regIndex - && objLocalReg.regIndex == setLocObj.regIndex - && nameLocalReg.regIndex == setLocName.regIndex) { + && objLocalReg.regIndex == setLocObj.regIndex + && nameLocalReg.regIndex == setLocName.regIndex) { getProp.object = setLocObj.value; fm.name = setLocName.value; output.remove(output.size() - 1); @@ -893,7 +883,7 @@ public abstract class InstructionDefinition implements Serializable { if (isIncrement) { stack.push(new PostIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.push(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.push(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } @@ -909,14 +899,14 @@ public abstract class InstructionDefinition implements Serializable { } } } - + //TestIncDec4 no result AIR /* var _loc2_:* = a; var _loc3_:int; var _loc4_:* = Number(_loc2_[_loc3_ = 2]) + 1; _loc2_[_loc3_] = _loc4_; - */ + */ if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) output.get(output.size() - 1); if (setLocValue.value instanceof IncrementAVM2Item @@ -932,8 +922,8 @@ public abstract class InstructionDefinition implements Serializable { if (fm.name instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocName = (SetLocalAVM2Item) fm.name; if (valueLocalReg.regIndex == setLocValue.regIndex - && objLocalReg.regIndex == setLocObj.regIndex - && nameLocalReg.regIndex == setLocName.regIndex) { + && objLocalReg.regIndex == setLocObj.regIndex + && nameLocalReg.regIndex == setLocName.regIndex) { getProp.object = setLocObj.value; fm.name = setLocName.value; output.remove(output.size() - 1); @@ -941,7 +931,7 @@ public abstract class InstructionDefinition implements Serializable { if (isIncrement) { stack.addToOutput(new PostIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.addToOutput(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.addToOutput(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } @@ -952,7 +942,7 @@ public abstract class InstructionDefinition implements Serializable { } } } - + //TestIncDec5 with result /* var _temp_4:* = §§findproperty(trace); @@ -961,7 +951,7 @@ public abstract class InstructionDefinition implements Serializable { var _temp_3:* = _loc3_ = (_loc2_ = a).attrib + 1; _loc2_.attrib = _loc3_; trace(_temp_3); - */ + */ if (!stack.isEmpty() && stack.peek() instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) stack.peek(); if (setLocValue.value instanceof IncrementAVM2Item @@ -975,13 +965,13 @@ public abstract class InstructionDefinition implements Serializable { FullMultinameAVM2Item fm = (FullMultinameAVM2Item) getProp.propertyName; if (fm.compareSame(multiname)) { if (valueLocalReg.regIndex == setLocValue.regIndex - && objLocalReg.regIndex == setLocObj.regIndex) { + && objLocalReg.regIndex == setLocObj.regIndex) { getProp.object = setLocObj.value; stack.pop(); if (isIncrement) { stack.push(new PreIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.push(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.push(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } @@ -991,14 +981,13 @@ public abstract class InstructionDefinition implements Serializable { } } } - - + //TestIncDec5 no result /* var _loc2_:* = a; var _loc3_:* = _loc2_.attrib + 1; _loc2_.attrib = _loc3_; - */ + */ if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) output.get(output.size() - 1); if (setLocValue.value instanceof IncrementAVM2Item @@ -1012,14 +1001,14 @@ public abstract class InstructionDefinition implements Serializable { FullMultinameAVM2Item fm = (FullMultinameAVM2Item) getProp.propertyName; if (fm.compareSame(multiname)) { if (valueLocalReg.regIndex == setLocValue.regIndex - && objLocalReg.regIndex == setLocObj.regIndex) { + && objLocalReg.regIndex == setLocObj.regIndex) { getProp.object = setLocObj.value; output.remove(output.size() - 1); stack.moveToStack(output); if (isIncrement) { stack.addToOutput(new PreIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.addToOutput(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.addToOutput(new PreDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } @@ -1029,8 +1018,7 @@ public abstract class InstructionDefinition implements Serializable { } } } - - + //TestIncDec6 with result /* var _temp_3:* = §§findproperty(trace); @@ -1039,7 +1027,7 @@ public abstract class InstructionDefinition implements Serializable { var _loc3_:* = _temp_2 + 1; _loc2_.attrib = _loc3_; trace(_temp_2); - */ + */ if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) output.get(output.size() - 1); if (setLocValue.value instanceof IncrementAVM2Item @@ -1047,7 +1035,7 @@ public abstract class InstructionDefinition implements Serializable { boolean isIncrement = setLocValue.value instanceof IncrementAVM2Item; if (setLocValue.value.value instanceof DuplicateItem) { DuplicateItem d = (DuplicateItem) setLocValue.value.value; - if (output.size() >= 2 + if (output.size() >= 2 && output.get(output.size() - 2) instanceof PushItem && output.get(output.size() - 2).value instanceof DuplicateSourceItem) { DuplicateSourceItem ds = (DuplicateSourceItem) output.get(output.size() - 2).value; @@ -1073,7 +1061,7 @@ public abstract class InstructionDefinition implements Serializable { if (isIncrement) { stack.push(new PostIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.push(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.push(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } @@ -1089,7 +1077,7 @@ public abstract class InstructionDefinition implements Serializable { } } } - + //TestIncDec10 with result /* var _temp_3:* = §§findproperty(trace); @@ -1098,7 +1086,7 @@ public abstract class InstructionDefinition implements Serializable { var _loc2_:* = _temp_2 + 1; _loc1_.attrib = _loc2_; trace(_temp_2); - */ + */ if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocValue = (SetLocalAVM2Item) output.get(output.size() - 1); if (setLocValue.value instanceof IncrementAVM2Item @@ -1106,7 +1094,7 @@ public abstract class InstructionDefinition implements Serializable { boolean isIncrement = setLocValue.value instanceof IncrementAVM2Item; if (setLocValue.value.value instanceof DuplicateItem) { DuplicateItem d = (DuplicateItem) setLocValue.value.value; - if (output.size() >= 2 + if (output.size() >= 2 && output.get(output.size() - 2) instanceof PushItem && output.get(output.size() - 2).value instanceof DuplicateSourceItem) { DuplicateSourceItem ds = (DuplicateSourceItem) output.get(output.size() - 2).value; @@ -1131,13 +1119,13 @@ public abstract class InstructionDefinition implements Serializable { if (isIncrement) { stack.push(new PostIncrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } else { - stack.push(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); + stack.push(new PostDecrementAVM2Item(setLocValue.value.getSrc(), setLocValue.value.getLineStartItem(), getProp)); } return; } } } - } + } } } } @@ -1146,9 +1134,7 @@ public abstract class InstructionDefinition implements Serializable { } } } - - - + /*stack.moveToStack(output); if (!stack.isEmpty()) { GraphTargetItem checked = checkIncDec(false, multinameIndex, ins, localData, stack.peek(), valueLocalReg, nameLocalReg, objLocalReg); @@ -1176,7 +1162,7 @@ public abstract class InstructionDefinition implements Serializable { var _temp_1:* = attrib + 1; attrib = _temp_1; _temp_3(_temp_1); - */ + */ if (value instanceof DuplicateItem) { if (!stack.isEmpty() && stack.peek() instanceof DuplicateSourceItem) { DuplicateItem d = (DuplicateItem) value; @@ -1188,7 +1174,7 @@ public abstract class InstructionDefinition implements Serializable { if (st.value instanceof IncrementAVM2Item || st.value instanceof DecrementAVM2Item) { boolean isIncrement = st.value instanceof IncrementAVM2Item; - + boolean ok = false; //assembled.TestIncrement2 if (st.value.value instanceof GetLexAVM2Item) { @@ -1222,28 +1208,28 @@ public abstract class InstructionDefinition implements Serializable { } } } - + //TestIncDec9 no result AIR //attrib = attrib + 1; if (value instanceof IncrementAVM2Item - || value instanceof DecrementAVM2Item) { - boolean isIncrement = value instanceof IncrementAVM2Item; - if (value.value instanceof GetPropertyAVM2Item) { - GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) value.value; - if (getProp.propertyName instanceof FullMultinameAVM2Item) { - FullMultinameAVM2Item fm = (FullMultinameAVM2Item) getProp.propertyName; - if (fm.compareSame(multiname)) { + || value instanceof DecrementAVM2Item) { + boolean isIncrement = value instanceof IncrementAVM2Item; + if (value.value instanceof GetPropertyAVM2Item) { + GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) value.value; + if (getProp.propertyName instanceof FullMultinameAVM2Item) { + FullMultinameAVM2Item fm = (FullMultinameAVM2Item) getProp.propertyName; + if (fm.compareSame(multiname)) { if (isIncrement) { stack.addToOutput(new PreIncrementAVM2Item(value.getSrc(), value.getLineStartItem(), getProp)); } else { stack.addToOutput(new PreDecrementAVM2Item(value.getSrc(), value.getLineStartItem(), getProp)); } return; - } - } - } + } + } + } } - + //TestInc10 with result AIR /* //var _temp_4:* = trace; @@ -1251,15 +1237,15 @@ public abstract class InstructionDefinition implements Serializable { var _temp_1:* = attrib; attrib = _temp_1 + 1; _temp_4(_temp_1); - */ + */ if (value instanceof IncrementAVM2Item - || value instanceof DecrementAVM2Item) { - boolean isIncrement = value instanceof IncrementAVM2Item; + || value instanceof DecrementAVM2Item) { + boolean isIncrement = value instanceof IncrementAVM2Item; if (value.value instanceof DuplicateItem) { DuplicateItem d = (DuplicateItem) value.value; if (!output.isEmpty() && output.get(output.size() - 1) instanceof PushItem - && output.get(output.size() - 1) .value instanceof DuplicateSourceItem) { - DuplicateSourceItem ds = (DuplicateSourceItem) output.get(output.size() - 1) .value ; + && output.get(output.size() - 1).value instanceof DuplicateSourceItem) { + DuplicateSourceItem ds = (DuplicateSourceItem) output.get(output.size() - 1).value; if (d.tempIndex == ds.tempIndex) { if (output.size() >= 2 && output.get(output.size() - 2) instanceof SetTemporaryItem) { SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 2); @@ -1281,7 +1267,7 @@ public abstract class InstructionDefinition implements Serializable { } } } - + if (ok) { output.remove(output.size() - 1); output.remove(output.size() - 1); @@ -1297,33 +1283,33 @@ public abstract class InstructionDefinition implements Serializable { } } } - } + } } } - + //TestInc10 no result AIR //attrib = attrib + 1; if (value instanceof IncrementAVM2Item - || value instanceof DecrementAVM2Item) { - boolean isIncrement = value instanceof IncrementAVM2Item; + || value instanceof DecrementAVM2Item) { + boolean isIncrement = value instanceof IncrementAVM2Item; if (value.value instanceof ConvertAVM2Item) { if (value.value.value instanceof GetPropertyAVM2Item) { GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) value.value.value; if (getProp.propertyName instanceof FullMultinameAVM2Item) { FullMultinameAVM2Item fm = (FullMultinameAVM2Item) getProp.propertyName; - if (fm.compareSame(multiname)) { - if (isIncrement) { - stack.addToOutput(new PostIncrementAVM2Item(value.getSrc(), value.getLineStartItem(), getProp)); - } else { - stack.addToOutput(new PostDecrementAVM2Item(value.getSrc(), value.getLineStartItem(), getProp)); - } - return; + if (fm.compareSame(multiname)) { + if (isIncrement) { + stack.addToOutput(new PostIncrementAVM2Item(value.getSrc(), value.getLineStartItem(), getProp)); + } else { + stack.addToOutput(new PostDecrementAVM2Item(value.getSrc(), value.getLineStartItem(), getProp)); + } + return; } } - } + } } } - + if (multiname.name instanceof CommaExpressionItem) { CommaExpressionItem ce = (CommaExpressionItem) multiname.name; if (ce.commands.size() == 2) { @@ -1333,16 +1319,16 @@ public abstract class InstructionDefinition implements Serializable { if (setLocal.regIndex == localReg.regIndex) { GraphSourceItem src = setLocal.getSrc(); if (src != null) { - if (localData.getSetLocalUsages(localData.code.adr2pos(src.getAddress())).size() == 1) { + if (localData.getSetLocalUsages(localData.code.adr2pos(src.getAddress())).size() == 1) { multiname.name = setLocal.value; } - } + } } } } - } - - if (obj.getThroughDuplicate() instanceof ConstructAVM2Item) { + } + + if (obj.getThroughDuplicate() instanceof ConstructAVM2Item) { ConstructAVM2Item c = (ConstructAVM2Item) obj.getThroughDuplicate(); if (c.object instanceof ApplyTypeAVM2Item) { ApplyTypeAVM2Item at = (ApplyTypeAVM2Item) c.object; @@ -1351,7 +1337,7 @@ public abstract class InstructionDefinition implements Serializable { vals.add(value); c.object = new InitVectorAVM2Item(c.getInstruction(), c.getLineStartIns(), at.params.get(0), vals); if (obj instanceof DuplicateItem) { - if (!stack.isEmpty() + if (!stack.isEmpty() && stack.peek() instanceof DuplicateSourceItem && stack.peek().getThroughDuplicate() == obj.getThroughDuplicate()) { if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetTemporaryItem) { @@ -1363,14 +1349,14 @@ public abstract class InstructionDefinition implements Serializable { } } stack.push(stack.pop().value); - } + } } return; } else if (c.object instanceof InitVectorAVM2Item) { InitVectorAVM2Item iv = (InitVectorAVM2Item) c.object; iv.arguments.add(value); if (obj instanceof DuplicateItem) { - if (!stack.isEmpty() + if (!stack.isEmpty() && stack.peek() instanceof DuplicateSourceItem && stack.peek().getThroughDuplicate() == obj.getThroughDuplicate()) { if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetTemporaryItem) { @@ -1381,19 +1367,18 @@ public abstract class InstructionDefinition implements Serializable { } } stack.push(stack.pop().value); - } + } } return; } - } - + } + Reference isStatic = new Reference<>(false); Reference type = new Reference<>(null); Reference callType = new Reference<>(null); GetPropertyIns.resolvePropertyType(localData, obj, multiname, isStatic, type, callType); //obj = obj.getThroughDuplicate(); - SetTypeAVM2Item result; if (init) { result = new InitPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, value, type.getVal(), callType.getVal(), isStatic.getVal()); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java index f3e17b492..c91030138 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java @@ -63,7 +63,7 @@ public class PopIns extends InstructionDefinition { return; } - stack.addToOutput(top); + stack.addToOutput(top); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java index 68af24437..3aa9b7bc6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java @@ -90,7 +90,7 @@ import java.util.logging.Logger; public class ActionSourceGenerator implements SourceGenerator { private final List constantPool; - + private int constantPoolLength; private final int swfVersion; @@ -163,10 +163,9 @@ public class ActionSourceGenerator implements SourceGenerator { if (swfVersion <= 4) { return items; } - return items; - + //TODO: This should take into account important offsets (jumps) //And not group Pushes over different parts of code /*Like: @@ -218,7 +217,7 @@ public class ActionSourceGenerator implements SourceGenerator { prevPush = null; } } - return ret; */ + return ret; */ } private List nonempty(List list) { @@ -253,7 +252,7 @@ public class ActionSourceGenerator implements SourceGenerator { } byte[] onTrueBytes = Action.actionsToBytes(onTrue, false, SWF.DEFAULT_VERSION); int onTrueLen = onTrueBytes.length; - + if (onTrueLen > 32767) { throw new CompilationException("Generated offset for onTrue part of " + errorTitle + " is larger than maximum allowed for SI16.", errorLine); } @@ -302,8 +301,8 @@ public class ActionSourceGenerator implements SourceGenerator { int nOffset = -pos + continueOffset; if (nOffset < -32768 || nOffset > 32767) { throw new CompilationException("Generated offset for Continue is outside bounds of SI16.", item.line); - } - + } + aj.setJumpOffset(nOffset); aj.isContinue = false; } @@ -311,7 +310,7 @@ public class ActionSourceGenerator implements SourceGenerator { int nOffset = -pos + breakOffset; if (nOffset < -32768 || nOffset > 32767) { throw new CompilationException("Generated offset for Break is outside bounds of SI16.", item.line); - } + } aj.setJumpOffset(nOffset); aj.isBreak = false; } @@ -555,7 +554,7 @@ public class ActionSourceGenerator implements SourceGenerator { * @return Push constant item */ public DirectValueActionItem pushConstTargetItem(String s) { - + //ActionConstantPool was introduced in SWF 5 if (swfVersion < 5) { return new DirectValueActionItem(null, null, 0, s, constantPool); @@ -564,7 +563,7 @@ public class ActionSourceGenerator implements SourceGenerator { int index = constantPool.indexOf(s); if (index == -1) { int newItemLen = ActionConstantPool.calculateSize(s, charset); - if (constantPool.size() < 0xffff + if (constantPool.size() < 0xffff && constantPoolLength + newItemLen <= 0xffff) { // constant pool is not full constantPool.add(s); @@ -577,7 +576,7 @@ public class ActionSourceGenerator implements SourceGenerator { return new DirectValueActionItem(null, null, 0, s, constantPool); } - return new DirectValueActionItem(null, null, 0, new ConstantIndex(index), constantPool); + return new DirectValueActionItem(null, null, 0, new ConstantIndex(index), constantPool); } /** @@ -587,25 +586,25 @@ public class ActionSourceGenerator implements SourceGenerator { * @return Push constant action */ public ActionPush pushConst(String s) { - + if (swfVersion < 5) { return new ActionPush(s, charset); - } - + } + int index = constantPool.indexOf(s); - if (index == -1) { - + if (index == -1) { + if (constantPool.size() == 0xffff) { return new ActionPush(s, charset); - } - + } + int newItemLen = ActionConstantPool.calculateSize(s, charset); - + //constant pool is full if (constantPoolLength + newItemLen > 0xffff) { return new ActionPush(s, charset); } - + constantPool.add(s); index = constantPool.indexOf(s); constantPoolLength += newItemLen; @@ -916,15 +915,15 @@ public class ActionSourceGenerator implements SourceGenerator { whileBody.add(whileajmp); int whileExprLen = Action.actionsToBytes(whileExpr, false, SWF.DEFAULT_VERSION).length; int whileBodyLen = Action.actionsToBytes(whileBody, false, SWF.DEFAULT_VERSION).length; - + if (whileBodyLen > 32767) { throw new CompilationException("Generated offset for While is larger than maximum allowed for SI16.", item.line); } - + int whileJumpOffset = -(whileExprLen + whileBodyLen); if (whileJumpOffset < -32768) { throw new CompilationException("Generated offset for While is lower than mininum allowed for SI16.", item.line); - } + } whileajmp.setJumpOffset(whileJumpOffset); whileaif.setJumpOffset(whileBodyLen); ret.addAll(whileExpr); @@ -953,11 +952,11 @@ public class ActionSourceGenerator implements SourceGenerator { ret.addAll(doExpr); ActionIf doif = new ActionIf(0, charset); ret.add(doif); - int offset = doBodyLen + doExprLen + doif.getTotalActionLength(); + int offset = doBodyLen + doExprLen + doif.getTotalActionLength(); if (-offset < -32768) { throw new CompilationException("Generated offset for DoWhile is lower than mininum allowed for SI16.", item.line); - } - + } + doif.setJumpOffset(-offset); fixLoop(doBody, offset, doBodyLen, item); return ret; @@ -986,7 +985,7 @@ public class ActionSourceGenerator implements SourceGenerator { if (ifOffset > 32767) { throw new CompilationException("Generated offset for For is larger than maximum allowed for SI16.", item.line); } - + forajmp.setJumpOffset(jmpOffset); foraif.setJumpOffset(ifOffset); ret.addAll(generateToActionList(localData, item.firstCommands)); @@ -996,8 +995,8 @@ public class ActionSourceGenerator implements SourceGenerator { ret.add(forajmp); fixLoop(forBody, forBodyLen + forFinalLen + forajmpLen, forBodyLen, item); return ret; - } - + } + @Override public List generate(SourceGeneratorLocalData localData, SwitchItem item) throws CompilationException { List ret = new ArrayList<>(); @@ -1103,7 +1102,7 @@ public class ActionSourceGenerator implements SourceGenerator { } checkOffsetBounds(defJmpPos, "Switch", item.line); - + defJump.setJumpOffset(defJmpPos); List caseCmdsAll = new ArrayList<>(); int breakOffset = 0; @@ -1193,6 +1192,14 @@ public class ActionSourceGenerator implements SourceGenerator { return ret; } + + @Override + public List generate(SourceGeneratorLocalData localData, SwapItem item) throws CompilationException { + List ret = new ArrayList<>(); + ret.add(new ActionStackSwap()); + return ret; + } + private int checkOffsetBounds(int offset, String errorItem, int errorLine) throws CompilationException { if (offset < -32768) { throw new CompilationException("Generated offset for " + errorItem + " is lower than mininum allowed for SI16.", errorLine); @@ -1202,10 +1209,4 @@ public class ActionSourceGenerator implements SourceGenerator { } return offset; } - @Override - public List generate(SourceGeneratorLocalData localData, SwapItem item) throws CompilationException { - List ret = new ArrayList<>(); - ret.add(new ActionStackSwap()); - return ret; - } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index ae0260946..ad77078e2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -1038,7 +1038,8 @@ public class Graph { //fixSwitchEnds(ret); handleSetTemporaryDeclarations(ret); return ret; - } + } + private void handleSetTemporaryDeclarations(List items) { for (int i = 0; i < items.size(); i++) { GraphTargetItem item = items.get(i); @@ -1050,7 +1051,7 @@ public class Graph { DuplicateSourceItem s = (DuplicateSourceItem) item; s.declaration = true; }*/ - + Reference iRef = new Reference<>(i); item.visitRecursivelyNoBlock(new AbstractGraphTargetRecursiveVisitor() { @Override @@ -1069,7 +1070,7 @@ public class Graph { items.add(iRef.getVal(), dec); iRef.setVal(iRef.getVal() + 1); }*/ - } + } }); i = iRef.getVal(); if (item instanceof Block) { @@ -2862,7 +2863,7 @@ public class Graph { } if (!bcsLeft.isEmpty()) { - for (int c = currentLoop.breakCandidates.size() - 1; c >= 0; c--) { + for (int c = currentLoop.breakCandidates.size() - 1; c >= 0; c--) { if (!bcsLeft.contains(c)) { GraphPart cand = currentLoop.breakCandidates.get(c); removedX.add(cand); @@ -2965,7 +2966,7 @@ public class Graph { if (removedX.contains(cand)) { if (debugPrintLoopList) { System.err.println("cand " + cand + " is removed"); - } + } continue; } if (bannedCandidates.contains(cand)) { @@ -3332,13 +3333,13 @@ public class Graph { System.err.println("Adding break"); } makeAllCommands(ret, stack); - + BreakItem br = new BreakItem(dialect, null, localData.lineStartInstruction, el.id); if (part.start >= code.size() - 1) { br.isScriptEnd = true; } ret.add(br); - + return ret; } if (el.loopPreContinue == part) { @@ -3412,10 +3413,10 @@ public class Graph { } } - if (code.size() <= part.start) { + if (code.size() <= part.start) { if (!(!ret.isEmpty() && ret.get(ret.size() - 1) instanceof ExitItem)) { stack.setConnectedOutput(0, ret, localData); - stack.addToOutput(new ScriptEndItem(dialect)); + stack.addToOutput(new ScriptEndItem(dialect)); } return ret; } @@ -3579,7 +3580,7 @@ public class Graph { } while (exHappened); if ((part.end >= code.size() - 1) && getNextParts(localData, part).isEmpty()) { if (!(!output.isEmpty() && output.get(output.size() - 1) instanceof ExitItem)) { - stack.addToOutput(new ScriptEndItem(dialect)); + stack.addToOutput(new ScriptEndItem(dialect)); } } } @@ -3904,7 +3905,7 @@ public class Graph { GraphTargetItem rightSide = ((PushItem) filteredOnTrue.get(filteredOnTrue.size() - 1)).value; GraphTargetItem prevExpr = stack.pop(); GraphTargetItem leftSide = expr.getNotCoercedNoDup(); - + prevExpr = prevExpr.getThroughDuplicate(); boolean hideEmptyTrueFalse = true; @@ -3923,7 +3924,7 @@ public class Graph { stack.push(rightSide); } else if (hideEmptyTrueFalse && rightSide.getNotCoercedNoDup() instanceof FalseItem) { stack.push(prevExpr); - } else { + } else { stack.push(new OrItem(dialect, null, localData.lineStartInstruction, prevExpr, rightSide)); } } else if (leftSide.invert(null).getNotCoercedNoDup() instanceof DuplicateItem) { @@ -3940,7 +3941,7 @@ public class Graph { stack.push(rightSide); } else if (hideEmptyTrueFalse && rightSide.getNotCoercedNoDup() instanceof TrueItem) { stack.push(prevExpr); - } else { + } else { stack.push(new AndItem(dialect, null, localData.lineStartInstruction, prevExpr, rightSide)); } } else if (prevExpr instanceof FalseItem) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 180af7e4c..efef135eb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -77,7 +77,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { public static final int PRECEDENCE_LOGICALOR = 12; public static final int PRECEDENCE_NULLCOALESCE = 13; - + public static final int PRECEDENCE_CONDITIONAL = 14; public static final int PRECEDENCE_ASSIGNMENT = 15; @@ -120,27 +120,28 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { * Line start item */ public GraphSourceItem lineStartItem; - + /** * ASM Position */ protected int pos = 0; - + /** * Dialect */ public GraphTargetDialect dialect; - + /** * Position in output - current list of GraphTargetItems - */ + */ public int outputPos = -1; - + /** - * Line in decompiled source code. Used mainly in Parsers/Code generators to report bugs. + * Line in decompiled source code. Used mainly in Parsers/Code generators to + * report bugs. */ public int line; - + /** * Gets the line start item * @@ -149,7 +150,6 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { public GraphSourceItem getLineStartItem() { return lineStartItem; } - /** * Simplifies something @@ -243,10 +243,11 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { /** * Constructs GraphTargetItem + * * @param dialect Dialect */ public GraphTargetItem(GraphTargetDialect dialect) { - this(dialect, null, null, NOPRECEDENCE); + this(dialect, null, null, NOPRECEDENCE); } /** @@ -255,7 +256,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { * @param dialect Dialect * @param src Source item * @param lineStartItem Line start item - * @param precedence Precedence + * @param precedence Precedence */ public GraphTargetItem(GraphTargetDialect dialect, GraphSourceItem src, GraphSourceItem lineStartItem, int precedence) { this(dialect, src, lineStartItem, precedence, null); @@ -321,9 +322,10 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { public int getPos() { return pos; } - + /** * Sets position + * * @param pos Position */ public void setPos(int pos) { @@ -494,15 +496,16 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { * @throws InterruptedException On interrupt */ public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException; - + /** - * Append this to a writer, ignoring parenthesis (in CommaExpression and/or Parenthesis) + * Append this to a writer, ignoring parenthesis (in CommaExpression and/or + * Parenthesis) * * @param writer Writer * @param localData Local data * @return Writer * @throws InterruptedException On interrupt - */ + */ public GraphTextWriter appendNoParenthesis(GraphTextWriter writer, LocalData localData) throws InterruptedException { return appendTo(writer, localData); } @@ -755,9 +758,10 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { public boolean handlesNewLine() { return false; } - + /** * Checks whether this item needs single newline before and after. + * * @return True if needs */ public boolean hasSingleNewLineAround() { @@ -1145,13 +1149,15 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { } return o1.equals(o2); } - + /** * Checks set temporary at the end of output and expected dupSource, dup. * Then removes the last output command when neccessary. + * * @param stack Stack * @param output Output - * @param dupSource Expected DuplicateSourceItem, if not, the command won't do anything + * @param dupSource Expected DuplicateSourceItem, if not, the command won't + * do anything * @param dup Expected DuplicateItem, if not the command won't do anything */ public static void checkDup(TranslateStack stack, List output, GraphTargetItem dupSource, GraphTargetItem dup) { @@ -1160,7 +1166,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { } if (!(output.get(output.size() - 1) instanceof SetTemporaryItem)) { return; - } + } dupSource = dupSource.getNotCoercedNoDup(); if (!(dupSource instanceof DuplicateSourceItem)) { return; @@ -1168,20 +1174,22 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { dup = dup.getNotCoercedNoDup(); if (!(dup instanceof DuplicateItem)) { return; - } + } DuplicateSourceItem ds = (DuplicateSourceItem) dupSource; DuplicateItem d = (DuplicateItem) dup; SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 1); if (ds.tempIndex != d.tempIndex || d.tempIndex != st.tempIndex) { return; } - - output.remove(output.size() - 1); + + output.remove(output.size() - 1); stack.moveToStack(output); } - + /** - * Checks whether items are result of dup instruction and removes SetTemportary from output when neccessary + * Checks whether items are result of dup instruction and removes + * SetTemportary from output when neccessary + * * @param item1 * @param item2 * @param output @@ -1193,14 +1201,13 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { return -1; } if (!((item1 instanceof DuplicateSourceItem && item2 instanceof DuplicateItem) - || (item1 instanceof DuplicateItem && item2 instanceof DuplicateSourceItem)) - ) { + || (item1 instanceof DuplicateItem && item2 instanceof DuplicateSourceItem))) { return -2; } if (((HasTempIndex) item1).getTempIndex() != ((HasTempIndex) item2).getTempIndex()) { return -2; } - + if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetTemporaryItem) { SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 1); if (st.getTempIndex() == ((HasTempIndex) item1).getTempIndex()) { @@ -1208,7 +1215,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { stack.moveToStack(output); } } - + return ((HasTempIndex) item1).getTempIndex(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java index 97d560a6a..e3df68498 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java @@ -234,16 +234,6 @@ public interface SourceGenerator { * @throws CompilationException On compilation error */ public List generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException; - - /** - * Generates DiscardValue action. - * - * @param localData Local data - * @param item GraphTargetItem - * @return List of GraphSourceItem - * @throws CompilationException On compilation error - */ - public List generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException; /** * Generates source code for SwapItem. @@ -254,4 +244,14 @@ public interface SourceGenerator { * @throws CompilationException On compilation error */ public List generate(SourceGeneratorLocalData localData, SwapItem item) throws CompilationException; + + /** + * Generates DiscardValue action. + * + * @param localData Local data + * @param item GraphTargetItem + * @return List of GraphSourceItem + * @throws CompilationException On compilation error + */ + public List generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/TranslateStack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/TranslateStack.java index 8402aa83c..b28c99dce 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/TranslateStack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/TranslateStack.java @@ -56,44 +56,43 @@ public class TranslateStack extends Stack { * Path */ private final String path; - + private List connectedOutput = null; - + private int prevOutputSize = 0; private Map marks = new HashMap<>(); - + public List outputQueue = new ArrayList<>(); - + public BaseLocalData localData = null; @Override public synchronized Object clone() { - TranslateStack st = (TranslateStack) super.clone(); + TranslateStack st = (TranslateStack) super.clone(); st.outputQueue = new ArrayList<>(outputQueue); return st; - } - + } + @Override public void clear() { super.clear(); outputQueue.clear(); } - - + public void setConnectedOutput(int prevOutputSize, List connectedOutput, BaseLocalData localData) { this.prevOutputSize = prevOutputSize; this.connectedOutput = connectedOutput; this.localData = localData; - } - + } + @Override public GraphTargetItem push(GraphTargetItem item) { if (!outputQueue.isEmpty()) { if ((item instanceof FindPropertyAVM2Item) || isDupsOnly()) { finishBlock(connectedOutput); } else { - outputQueue.add(item); + outputQueue.add(item); item = new CommaExpressionItem(item.dialect, null, item.lineStartItem, outputQueue); outputQueue = new ArrayList<>(); } @@ -103,9 +102,9 @@ public class TranslateStack extends Stack { } return super.push(item); } - + //for #116 - private boolean isDupsOnly() { + private boolean isDupsOnly() { for (GraphTargetItem item : this) { if (item instanceof DuplicateItem) { continue; @@ -117,25 +116,27 @@ public class TranslateStack extends Stack { } return true; } - + /** * Sets mark. + * * @param name Name * @param value Value */ public void setMark(String name, GraphTargetItem value) { marks.put(name, value); } - + /** * Gets mark. + * * @param name Name * @return Value */ public GraphTargetItem getMark(String name) { return marks.get(name); } - + /** * Simplifies all items in the stack. */ @@ -246,50 +247,50 @@ public class TranslateStack extends Stack { finishBlock(connectedOutput); connectedOutput.addAll(oldQueue); } - - if (isEmpty() && connectedOutput != null) { - for (int i = connectedOutput.size() - 1; i >= 0; i--) { - GraphTargetItem item = connectedOutput.get(i); - if (item instanceof Block) { - break; - } - if (item instanceof PushItem) { - PushItem pi = (PushItem) item; - if (pi.value instanceof SetTemporaryItem) { - SetTemporaryItem st = (SetTemporaryItem) pi.value; - connectedOutput.set(i, st); - return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, st.tempIndex); - } else if (pi.value instanceof DuplicateSourceItem) { - DuplicateSourceItem ds = (DuplicateSourceItem) pi.value; - //connectedOutput.set(i, new SetTemporaryItem(pi.dialect, ds.getSrc(), ds.getLineStartItem(), ds.value, ds.tempIndex,"push")); - connectedOutput.remove(i); - return ds; //new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), ds.value, ds.tempIndex); - } else if (pi.value instanceof DuplicateItem) { - DuplicateItem d = (DuplicateItem) pi.value; - //connectedOutput.remove(i); - //connectedOutput.set(i, new SetTemporaryItem(pi.dialect, d.getSrc(), d.getLineStartItem(), d.value, d.tempIndex)); - connectedOutput.remove(i); - return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, d.tempIndex); - } else if (pi.value instanceof TemporaryItem) { - connectedOutput.remove(i); - return pi.value; - } else { + + if (isEmpty() && connectedOutput != null) { + for (int i = connectedOutput.size() - 1; i >= 0; i--) { + GraphTargetItem item = connectedOutput.get(i); + if (item instanceof Block) { + break; + } + if (item instanceof PushItem) { + PushItem pi = (PushItem) item; + if (pi.value instanceof SetTemporaryItem) { + SetTemporaryItem st = (SetTemporaryItem) pi.value; + connectedOutput.set(i, st); + return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, st.tempIndex); + } else if (pi.value instanceof DuplicateSourceItem) { + DuplicateSourceItem ds = (DuplicateSourceItem) pi.value; + //connectedOutput.set(i, new SetTemporaryItem(pi.dialect, ds.getSrc(), ds.getLineStartItem(), ds.value, ds.tempIndex,"push")); + connectedOutput.remove(i); + return ds; //new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), ds.value, ds.tempIndex); + } else if (pi.value instanceof DuplicateItem) { + DuplicateItem d = (DuplicateItem) pi.value; + //connectedOutput.remove(i); + //connectedOutput.set(i, new SetTemporaryItem(pi.dialect, d.getSrc(), d.getLineStartItem(), d.value, d.tempIndex)); + connectedOutput.remove(i); + return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, d.tempIndex); + } else if (pi.value instanceof TemporaryItem) { + connectedOutput.remove(i); + return pi.value; + } else { int temp = localData.maxTempIndex.getVal() + 1; localData.maxTempIndex.setVal(temp); connectedOutput.set(i, new SetTemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, temp, "push", 1)); return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, temp); - } - } - } + } + } + } } - + if (path != null) { if (this.isEmpty()) { /*if (connectedOutput != null && !connectedOutput.isEmpty() && connectedOutput.get(connectedOutput.size() - 1) instanceof PushItem) { PushItem pi = (PushItem) connectedOutput.remove(connectedOutput.size() - 1); return pi.value; }*/ - + PopItem oldpop = getPop(); pop = null; Logger.getLogger(TranslateStack.class.getName()).log(Level.FINE, "{0}: Attempt to Pop empty stack", path); @@ -298,7 +299,7 @@ public class TranslateStack extends Stack { } return super.pop(); } - + public void moveToStack(List output) { if (!isEmpty()) { return; @@ -310,12 +311,12 @@ public class TranslateStack extends Stack { } } i++; - while(i < output.size()) { + while (i < output.size()) { PushItem pi = (PushItem) output.remove(i); push(pi.value); } } - + private boolean isAllTemp() { for (int i = 0; i < size(); i++) { GraphTargetItem item = get(i); @@ -329,22 +330,21 @@ public class TranslateStack extends Stack { } return true; } - + public void addToOutput(GraphTargetItem item) { - if (isEmpty() + if (isEmpty() || peek() instanceof ExceptionAVM2Item - || peek() instanceof NewActivationAVM2Item - //|| isAllTemp() - ) { + || peek() instanceof NewActivationAVM2Item //|| isAllTemp() + ) { connectedOutput.add(item); return; } outputQueue.add(item); - if (item instanceof ExitItem) { - finishBlock(connectedOutput); - } + if (item instanceof ExitItem) { + finishBlock(connectedOutput); + } } - + public void finishBlock(List output) { if (connectedOutput == null) { return; @@ -367,11 +367,11 @@ public class TranslateStack extends Stack { continue; } output.add(pos, beforeExit ? item : new PushItem(item)); - }*/ - + }*/ + int clen = output.size(); boolean isExit = false; - + if (!outputQueue.isEmpty() && outputQueue.get(outputQueue.size() - 1) instanceof ExitItem) { isExit = true; } @@ -417,12 +417,12 @@ public class TranslateStack extends Stack { output.add(clen, new PushItem(p)); } } - } - + } + output.addAll(outputQueue); outputQueue.clear(); } - + public void allowSwap(List output) { /* if (!isEmpty()) { @@ -459,7 +459,7 @@ public class TranslateStack extends Stack { pop(); push(ti.value); - */ + */ if (!isEmpty()) { return; } @@ -469,7 +469,7 @@ public class TranslateStack extends Stack { if (!(output.get(output.size() - 1) instanceof PushItem)) { return; } - + if (!(output.get(output.size() - 2) instanceof PushItem)) { return; } @@ -477,31 +477,31 @@ public class TranslateStack extends Stack { if (!(output.get(output.size() - 3) instanceof SetTemporaryItem)) { return; } - + PushItem pi1 = (PushItem) output.get(output.size() - 1); if (!(pi1.value instanceof TemporaryItem)) { return; } - + TemporaryItem ti = (TemporaryItem) pi1.value; - + SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 3); - + if (!"swap".equals(st.getSuffix())) { return; } - + if (st.getTempIndex() != ti.getTempIndex()) { return; } - + PushItem pi2 = (PushItem) output.get(output.size() - 2); - + output.remove(output.size() - 1); output.remove(output.size() - 1); output.remove(output.size() - 1); push(pi2.value); - push(ti.value); + push(ti.value); //moveToStack(output); - } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/DuplicateItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/DuplicateItem.java index 79cb73052..97a91825b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/DuplicateItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/DuplicateItem.java @@ -36,9 +36,10 @@ import java.util.Set; public class DuplicateItem extends GraphTargetItem implements SimpleValue, HasTempIndex { public int tempIndex; + /** * Constructor. - * + * * @param dialect Dialect * @param src Source * @param lineStartIns Line start item @@ -149,5 +150,5 @@ public class DuplicateItem extends GraphTargetItem implements SimpleValue, HasTe @Override public void visit(GraphTargetVisitorInterface visitor) { - } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TemporaryItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TemporaryItem.java index 5d0f89039..855d56f97 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TemporaryItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/TemporaryItem.java @@ -38,9 +38,10 @@ import java.util.Set; public class TemporaryItem extends GraphTargetItem implements SimpleValue, HasTempIndex { public int tempIndex; + /** * Constructor. - * + * * @param dialect Dialect * @param src Source * @param lineStartIns Line start item @@ -131,7 +132,7 @@ public class TemporaryItem extends GraphTargetItem implements SimpleValue, HasTe public boolean hasSideEffect() { return value.hasSideEffect(); } - + @Override public int getTempIndex() { return tempIndex; @@ -139,5 +140,5 @@ public class TemporaryItem extends GraphTargetItem implements SimpleValue, HasTe @Override public void visit(GraphTargetVisitorInterface visitor) { - } + } }