From 6cafe970fbddfc63f774d627c1d48cbb439bef01 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sat, 4 Jul 2015 20:47:07 +0200 Subject: [PATCH] invalid jump fix --- .../decompiler/flash/abc/ScriptPack.java | 3 ++- .../decompiler/flash/abc/avm2/AVM2Code.java | 13 ++++++++---- .../flash/abc/types/MethodBody.java | 2 +- .../jpexs/decompiler/flash/action/Action.java | 4 ++-- .../flash/locales/AppResources.properties | 2 ++ .../flash/locales/AppResources_hu.properties | 2 ++ .../src/com/jpexs/helpers/Helper.java | 20 ++++++++++++++++++- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 4df46c4f4..79a1c6532 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -61,6 +61,7 @@ public class ScriptPack extends AS3ClassTreeItem { public final List traitIndices; private final ClassPath path; + public boolean isSimple = false; @Override @@ -190,7 +191,7 @@ public class ScriptPack extends AS3ClassTreeItem { } catch (TimeoutException ex) { writer.continueMeasure(); logger.log(Level.SEVERE, "Decompilation error", ex); - Helper.appendTimeoutComment(writer, timeout); + Helper.appendTimeoutCommentAs3(writer, timeout, 0); return; } catch (ExecutionException ex) { writer.continueMeasure(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index d9dbd24a4..4bdc5bfcc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1149,9 +1149,11 @@ public class AVM2Code implements Cloneable { posCache = new ArrayList<>(); long a = 0; for (int i = 0; i < code.size(); i++) { - posCache.add(a); - a += code.get(i).getBytesLength(); + AVM2Instruction ins = code.get(i); + posCache.add(ins.offset); + a = ins.offset + ins.getBytesLength(); } + posCache.add(a); cacheActual = true; } @@ -1830,6 +1832,9 @@ public class AVM2Code implements Cloneable { if (targetAddress > endOffset) { return (int) (offset - targetAddress + endOffset); } + if (targetAddress < 0) { + return (int) (offset - targetAddress); + } return offset; } @@ -2228,7 +2233,7 @@ public class AVM2Code implements Cloneable { } while (ip < code.size()) { if (!refs.containsKey(ip)) { - refs.put(ip, new ArrayList()); + refs.put(ip, new ArrayList<>()); } refs.get(ip).add(lastIp); lastIp = ip; @@ -2276,7 +2281,7 @@ public class AVM2Code implements Cloneable { public HashMap> visitCode(MethodBody body) throws InterruptedException { HashMap> refs = new HashMap<>(); for (int i = 0; i < code.size(); i++) { - refs.put(i, new ArrayList()); + refs.put(i, new ArrayList<>()); } visitCode(0, 0, refs); int pos = 0; 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 eee1778e5..0de407f74 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 @@ -316,7 +316,7 @@ public final class MethodBody implements Cloneable { //writer.endMethod(); } else if (convertException instanceof TimeoutException) { // exception was logged in convert method - Helper.appendTimeoutComment(writer, timeout); + Helper.appendTimeoutCommentAs3(writer, timeout, getCode().code.size()); } else { // exception was logged in convert method Helper.appendErrorComment(writer, convertException); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index b74c72586..d538d4478 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -775,7 +775,7 @@ public abstract class Action implements GraphSourceItem { @Override public List call() throws Exception { int staticOperation = Graph.SOP_USE_STATIC; //(Boolean) Configuration.getConfig("autoDeobfuscate", true) ? Graph.SOP_SKIP_STATIC : Graph.SOP_USE_STATIC; - List tree = actionsToTree(new HashMap(), new HashMap(), new HashMap(), actions, version, staticOperation, path); + List tree = actionsToTree(new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); Graph.graphToString(tree, new NulWriter(), new LocalData()); return tree; } @@ -802,7 +802,7 @@ public abstract class Action implements GraphSourceItem { if (convertException == null) { Graph.graphToString(tree, writer, new LocalData()); } else if (convertException instanceof TimeoutException) { - Helper.appendTimeoutComment(writer, timeout); + Helper.appendTimeoutCommentAs2(writer, timeout, actions.size()); } else { Helper.appendErrorComment(writer, convertException); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties index b228c9a82..e99b4bab1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties @@ -19,6 +19,8 @@ decompilationError.timeout.description = Not decompiled due to timeout decompilationError.obfuscated = Code may be obfuscated decompilationError.errorType = Error type decompilationError.error.description = Not decompiled due to error +decompilationError.actionCount = Action count: +decompilationError.instructionCount = Instruction count: decompilation.skipped = Decompilation skipped decompilation.unsupported = Unsupported by decompiler diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_hu.properties b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_hu.properties index f78ea34a9..5429c47de 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_hu.properties +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_hu.properties @@ -19,6 +19,8 @@ decompilationError.timeout.description = Id\u0151t\u00fall\u00e9p\u00e9s miatt n decompilationError.obfuscated = K\u00f3d tal\u00e1n obfuszk\u00e1lva van decompilationError.errorType = Hiba t\u00edpus decompilationError.error.description = Hiba miatt nem lett visszaford\u00edtva +decompilationError.actionCount = Action-\u00f6k sz\u00e1ma: +decompilationError.instructionCount = Utas\u00edt\u00e1sok sz\u00e1ma: decompilation.skipped = Visszaford\u00edt\u00e1s mell\u0151zve decompilation.unsupported = Visszaford\u00edt\u00e1s nem t\u00e1mogatott diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 81e99c1b4..b7394f026 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -1048,10 +1048,28 @@ public class Helper { return "// " + AppResources.translate("decompilation.skipped"); } - public static void appendTimeoutComment(GraphTextWriter writer, int timeout) { + public static void appendTimeoutCommentAs2(GraphTextWriter writer, int timeout, int actionCount) { writer.appendNoHilight("/*").newLine(); writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError")).newLine(); writer.appendNoHilight(" * ").appendNoHilight(MessageFormat.format(AppResources.translate("decompilationError.timeout"), Helper.formatTimeToText(timeout))).newLine(); + if (actionCount > 0) { + writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError.instructionCount") + " " + actionCount).newLine(); + } + + writer.appendNoHilight(" */").newLine(); + writer.appendNoHilight("throw new Error(\""). + appendNoHilight(AppResources.translate("decompilationError.timeout.description")). + appendNoHilight("\");").newLine(); + } + + public static void appendTimeoutCommentAs3(GraphTextWriter writer, int timeout, int instructionCount) { + writer.appendNoHilight("/*").newLine(); + writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError")).newLine(); + writer.appendNoHilight(" * ").appendNoHilight(MessageFormat.format(AppResources.translate("decompilationError.timeout"), Helper.formatTimeToText(timeout))).newLine(); + if (instructionCount > 0) { + writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError.actionCount") + " " + instructionCount).newLine(); + } + writer.appendNoHilight(" */").newLine(); writer.appendNoHilight("throw new flash.errors.IllegalOperationError(\""). appendNoHilight(AppResources.translate("decompilationError.timeout.description")).