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 b7d6e8b53..47cfc01c0 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 @@ -202,6 +202,11 @@ public class MethodBody implements Cloneable, Serializable { if (convertException == null) { HashMap localRegNames = getLocalRegNames(abc); writer.startMethod(this.method_info); + if (Configuration.showMethodBodyId.get()) { + writer.appendNoHilight("// method body id:"); + writer.appendNoHilight(abc.findBodyIndex(this.method_info)); + writer.newLine(); + } Graph.graphToString(convertedItems, writer, LocalData.create(constants, localRegNames, fullyQualifiedNames)); writer.endMethod(); } else if (convertException instanceof TimeoutException) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 91d0b353c..3a988da46 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.configuration; import com.jpexs.decompiler.flash.ApplicationInfo; @@ -329,6 +330,10 @@ public class Configuration { @ConfigurationDefaultInt(128) public static final ConfigurationItem lzmaFastBytes = null; + @ConfigurationDefaultBoolean(false) + @ConfigurationCategory("debug") + public static final ConfigurationItem showMethodBodyId = null; + public static final ConfigurationItem pluginPath = null; private enum OSId { diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java index ef93c4f32..bacb4b4bb 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash; import com.jpexs.decompiler.flash.abc.ABC; @@ -63,6 +64,7 @@ public class ActionScript3Test extends ActionScriptTestBase { Configuration.autoDeobfuscate.set(false); Configuration.decompile.set(true); Configuration.registerNameFormat.set("_loc%d_"); + Configuration.showMethodBodyId.set(false); } private void decompileMethod(String methodName, String expectedResult, boolean isStatic) { diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 4388c4e82..fce49f0d9 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -1381,11 +1381,15 @@ public class CommandLineArgumentParser { if (Path.getExtension(repFile).equals(".as")) { replaceAS3(repText, pack); } else { - // todo: get Ids - int bodyIndex = 0; - int classIndex = 0; - int traitId = 0; - replaceAS3PCode(repText, pack.abc, bodyIndex, classIndex, traitId); + // todo: get traits + if (args.isEmpty()) { + badArguments(); + } + int bodyIndex = Integer.parseInt(args.remove()); + //int classIndex = 0; + //int traitId = 0; + Trait trait = null; //abc.findTraitByTraitId(classIndex, traitId); + replaceAS3PCode(repText, pack.abc, bodyIndex, trait); } } } @@ -1448,7 +1452,7 @@ public class CommandLineArgumentParser { src.setModified(); } - private static void replaceAS3PCode(String text, ABC abc, int bodyIndex, int classIndex, int traitId) throws IOException, InterruptedException { + private static void replaceAS3PCode(String text, ABC abc, int bodyIndex, Trait trait) throws IOException, InterruptedException { System.out.println("Replace AS3 PCode"); if (text.trim().startsWith("#hexdata")) { byte[] data = Helper.getBytesFromHexaText(text); @@ -1456,7 +1460,6 @@ public class CommandLineArgumentParser { mb.codeBytes = data; mb.setCode(null); } else { - Trait trait = abc.findTraitByTraitId(classIndex, traitId); try { AVM2Code acode = ASM3Parser.parse(new StringReader(text), abc.constants, trait, new MissingSymbolHandler() { //no longer ask for adding new constants diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 359b6f777..92bbeabd9 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -60,7 +60,6 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL private int classIndex = -1; private boolean isStatic = false; private final Cache cache = Cache.getInstance(true); - private Trait currentTrait = null; private final List scriptListeners = new ArrayList<>(); @@ -83,7 +82,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } public Trait getCurrentTrait() { - return currentTrait; + return abc.findTraitByTraitId(classIndex, lastTraitIndex); } public ScriptPack getScriptLeaf() { @@ -175,11 +174,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL if (bi == -1) { return false; } - View.execInEventDispatch(new Runnable() { - @Override - public void run() { - } - }); + //fix for inner functions: if (trait instanceof TraitMethodGetterSetter) { TraitMethodGetterSetter tm = (TraitMethodGetterSetter) trait; @@ -194,20 +189,21 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } } abcPanel.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD, trait); - if (reset || (abcPanel.detailPanel.methodTraitPanel.methodCodePanel.getBodyIndex() != bi)) { - abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, abc, name, trait); + MethodCodePanel methodCodePanel = abcPanel.detailPanel.methodTraitPanel.methodCodePanel; + if (reset || (methodCodePanel.getBodyIndex() != bi)) { + methodCodePanel.setBodyIndex(bi, abc, name, trait); abcPanel.detailPanel.setEditMode(false); this.isStatic = isStatic; } boolean success = false; Highlighting h = Highlighting.search(highlights, pos); if (h != null) { - abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighOffset(h.getPropertyLong("offset")); + methodCodePanel.hilighOffset(h.getPropertyLong("offset")); success = true; } Highlighting sh = Highlighting.search(specialHighlights, pos); if (sh != null) { - abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighSpecial(sh.getPropertyString("subtype"), (int) (long) sh.getPropertyLong("index")); + methodCodePanel.hilighSpecial(sh.getPropertyString("subtype"), (int) (long) sh.getPropertyLong("index")); success = true; } return success; @@ -254,6 +250,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } } int currentMethod = -1; + Trait currentTrait = getCurrentTrait(); if (currentTrait instanceof TraitMethodGetterSetter) { currentMethod = ((TraitMethodGetterSetter) currentTrait).method_info; } @@ -325,12 +322,12 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL name = abc.instance_info.get(classIndex).getName(abc.constants).getNameWithNamespace(abc.constants, false); } } - currentTrait = null; + Trait currentTrait = null; currentTraitHighlight = Highlighting.search(traitHighlights, pos); if (currentTraitHighlight != null) { lastTraitIndex = (int) (long) currentTraitHighlight.getPropertyLong("index"); if ((abc != null) && (classIndex != -1)) { - currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex); + currentTrait = getCurrentTrait(); isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex); if (currentTrait != null) { name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList(), false); @@ -347,11 +344,11 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL setNoTrait(); return; } - currentTrait = null; + Trait currentTrait = null; currentTraitHighlight = Highlighting.search(traitHighlights, pos); if (currentTraitHighlight != null) { lastTraitIndex = (int) (long) currentTraitHighlight.getPropertyLong("index"); - currentTrait = abc.findTraitByTraitId(classIndex, (int) (long) currentTraitHighlight.getPropertyLong("index")); + currentTrait = getCurrentTrait(); if (currentTrait != null) { if (currentTrait instanceof TraitSlotConst) { abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) currentTrait, abc, @@ -372,14 +369,14 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL currentTrait = null; if (abc != null) { name = abc.instance_info.get(classIndex).getName(abc.constants).getNameWithNamespace(abc.constants, false); - currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex); + currentTrait = getCurrentTrait(); isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex); if (currentTrait != null) { name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList(), false); } } - displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) (long) currentTraitHighlight.getPropertyLong("index")), name, currentTrait, isStatic); + displayMethod(pos, abc.findMethodIdByTraitId(classIndex, lastTraitIndex), name, currentTrait, isStatic); return; } setNoTrait(); diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 9e4ac4b57..33d2ec757 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -266,3 +266,6 @@ config.description.pluginPath = - config.name.deobfuscationMode = Deobfuscation mode config.description.deobfuscationMode = Run deobfuscation on every file before ActionScript decompilation + +config.name.showMethodBodyId = Show method body id +config.description.showMethodBodyId = Shows the id of the methodbody for command lineimport