diff --git a/CHANGELOG.md b/CHANGELOG.md index 44edc2ebe..3afd3b594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Fixed - [#1970] FLA export - do not strip empty frames at the end of timeline +- [#1970] AS2 Renaming invalid identifiers for direct strings (no constant indices) +- [#1970] AS2 Renaming invalid identifiers IndexOutOfBounds on invalid constant index (obfuscated code, etc.) ## [18.3.5] - 2023-02-12 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 4c413f5aa..7fcb3c974 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -2747,6 +2747,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { } private int renameAS2Identifiers(RenameType renameType, Map selected) throws InterruptedException { + boolean wrongConstantIndices = false; HashMap actionsMap = new HashMap<>(); List allFunctions = new ArrayList<>(); List> allVariableNames = new ArrayList<>(); @@ -2963,7 +2964,11 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { pool.constants.add(changed); ci.index = pool.constants.size() - 1; } else { - pool.constants.set(ci.index, changed); + if (ci.index >= pool.constants.size()) { + wrongConstantIndices = true; + } else { + pool.constants.set(ci.index, changed); + } } } else { pu.replacement.set(it.getKey().pos, changed); @@ -2983,6 +2988,9 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { } deobfuscation.deobfuscateInstanceNames(false, deobfuscated, renameType, getTags(), selected); + if (wrongConstantIndices) { + logger.warning("Cannot properly rename some invalid AS2 identifiers as there exist unresolved constant indices. It might be fixed by turning Deobfuscation on and try to rename identifiers again."); + } return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index c437bdf23..676abf38f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -128,7 +128,11 @@ public class ActionPush extends Action { @Override protected void getContentBytes(SWFOutputStream sos) throws IOException { - for (Object o : values) { + List vals = values; + if (replacement != null) { + vals = replacement; + } + for (Object o : vals) { if (o instanceof String) { sos.writeUI8(0); sos.writeString((String) o); @@ -179,8 +183,12 @@ public class ActionPush extends Action { */ @Override protected int getContentBytesLength() { + List vals = values; + if (replacement != null) { + vals = replacement; + } int res = 0; - for (Object o : values) { + for (Object o : vals) { if (o instanceof String) { res += Utf8Helper.getBytesLength((String) o) + 2; } else if (o instanceof Float) { @@ -402,36 +410,7 @@ public class ActionPush extends Action { } else { o = constantPool.get(((ConstantIndex) o).index); } - } - /*if (o instanceof RegisterNumber) { - if (regNames.containsKey(((RegisterNumber) o).number)) { - ((RegisterNumber) o).name = regNames.get(((RegisterNumber) o).number); - } else if (output.size() >= 2) { //chained assignments:, ignore for class prototype assignment - GraphTargetItem last = output.get(output.size() - 1); - GraphTargetItem prev = output.get(output.size() - 2); - if (last instanceof SetTypeActionItem) { - if (prev instanceof StoreRegisterActionItem) { - StoreRegisterActionItem str = (StoreRegisterActionItem) prev; - if (str.register.number == ((RegisterNumber) o).number) { - SetTypeActionItem stt = (SetTypeActionItem) last; - stt.setTempRegister(((RegisterNumber) o).number); - if ((stt.getValue() instanceof IncrementActionItem) && (((IncrementActionItem) stt.getValue()).object.equals(stt.getObject()))) { - stack.push(new PreIncrementActionItem(this, lineStartAction, stt.getObject())); - } else if ((stt.getValue() instanceof DecrementActionItem) && (((DecrementActionItem) stt.getValue()).object.equals(stt.getObject()))) { - stack.push(new PreDecrementActionItem(this, lineStartAction, stt.getObject())); - } else { - //stack.push(last); - continue; - } - output.remove(output.size() - 1); - output.remove(output.size() - 1); - pos++; - continue; - } - } - } - } - }*/ + } if (o instanceof Boolean) { Boolean b = (Boolean) o; if (b) {