From b98afed19b74888b8d415ebb7ea9df97bea9f7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 8 Nov 2015 22:46:52 +0100 Subject: [PATCH] AS3 direct edit: Try..catch in constructor fix Namespace resolving fix --- .../ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java | 8 +++----- .../flash/abc/avm2/parser/script/AVM2SourceGenerator.java | 4 ++-- .../com/jpexs/decompiler/flash/abc/types/MethodBody.java | 6 ++++++ .../jpexs/decompiler/flash/abc/types/traits/Trait.java | 8 ++++++-- .../decompiler/flash/abc/types/traits/TraitClass.java | 5 ++++- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java index ae9410467..b20158be0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -862,13 +862,11 @@ public class ABC { return bodyIdxFromMethodIdx; } - public DottedChain nsValueToName(DottedChain value) { - if (value == null) { - return null; + public DottedChain nsValueToName(String valueStr) { + if (valueStr == null) { + return DottedChain.EMPTY; } - String valueStr = value.toRawString(); - if (getNamespaceMap().containsKey(valueStr)) { return getNamespaceMap().get(valueStr); } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 181de0e22..b6ee95302 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -1226,10 +1226,10 @@ public class AVM2SourceGenerator implements SourceGenerator { MethodBody initBody = null; if (!isInterface) { initBody = abcIndex.getSelectedAbc().findBody(init); - initBody.getCode().code.addAll(constructor == null ? 0 : 2, initcode);//after getlocal0,pushscope + initBody.insertAll(constructor == null ? 0 : 2, initcode);//after getlocal0,pushscope if (sinitBody.getCode().code.get(sinitBody.getCode().code.size() - 1).definition instanceof ReturnVoidIns) { - sinitBody.getCode().code.addAll(2, sinitcode); //after getlocal0,pushscope + sinitBody.insertAll(2, sinitcode); //after getlocal0,pushscope } } sinitBody.markOffsets(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 0a928deec..c59d9a1bc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -227,6 +227,12 @@ public final class MethodBody implements Cloneable { getCode().insertInstruction(pos, instruction, this); } + public void insertAll(int pos, List list) { + for (AVM2Instruction ins : list) { + insertInstruction(pos++, ins); + } + } + /** * Inserts instruction at specified point. Handles offsets properly. Note: * If newinstruction is jump, the offset operand must be handled properly by diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 3aa160382..755cc9f25 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -131,13 +131,17 @@ public abstract class Trait implements Cloneable, Serializable { if (link_ns_index <= 0) { return null; } - DottedChain name = abc.constants.getNamespace(link_ns_index).getName(abc.constants); + Namespace ns = abc.constants.getNamespace(link_ns_index); + if (ns.kind != Namespace.KIND_NAMESPACE) { + return null; + } + String name = abc.constants.getString(ns.name_index); for (ABCContainerTag abcTag : abc.getAbcTags()) { DottedChain dc = abcTag.getABC().nsValueToName(name); nsname = dc.getLast(); if (nsname == null) { - break; + continue; } if (!nsname.isEmpty()) { return dc; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 1dfa9019c..2c81f03e1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -104,6 +104,8 @@ public class TraitClass extends Trait implements TraitWithSlot { } boolean raw = ns.kind == Namespace.KIND_NAMESPACE; DottedChain newimport = ns.getName(abc.constants); + + //Note: Following is weird and probably wrong - FIXIT! /*if ((ns.kind != Namespace.KIND_PACKAGE) && (ns.kind != Namespace.KIND_NAMESPACE) && (ns.kind != Namespace.KIND_STATIC_PROTECTED)) { @@ -113,7 +115,8 @@ public class TraitClass extends Trait implements TraitWithSlot { DottedChain oldimport = newimport; newimport = new DottedChain(); for (ABCContainerTag abcTag : abc.getAbcTags()) { - DottedChain newname = abcTag.getABC().nsValueToName(oldimport); + DottedChain newname = abcTag.getABC().nsValueToName(oldimport.toRawString()); /* why this? */ + if (newname.size() == 1 && newname.get(0).equals("-")) { return true; }