From 12bbb13497066926833644637d2e343d89c714d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 5 Apr 2015 22:24:15 +0200 Subject: [PATCH] Displaying changed AS3 scripts in GUI as bold --- .../src/com/jpexs/decompiler/flash/abc/ABC.java | 4 +++- .../decompiler/flash/abc/types/ScriptInfo.java | 15 ++++++++++++++- .../decompiler/flash/tags/DoABCDefineTag.java | 12 ++++++++++++ .../com/jpexs/decompiler/flash/tags/DoABCTag.java | 13 +++++++++++++ src/com/jpexs/decompiler/flash/gui/MainPanel.java | 4 ++-- .../jpexs/decompiler/flash/gui/abc/ABCPanel.java | 4 +++- .../flash/gui/abc/ASMSourceEditorPane.java | 13 +++++++++++-- .../flash/gui/abc/DecompiledEditorPane.java | 2 +- .../decompiler/flash/gui/abc/MethodCodePanel.java | 14 ++++++++++---- .../decompiler/flash/gui/tagtree/TagTree.java | 7 +++++++ 10 files changed, 76 insertions(+), 12 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 0c286cdac..5283fc0a7 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 @@ -542,6 +542,7 @@ public class ABC { si.traits = ais.readTraits("traits"); script_info.add(si); ais.endDumpLevel(); + si.setModified(false); } int bodies_count = ais.readU30("bodies_count"); @@ -1228,7 +1229,7 @@ public class ABC { method_info.remove(index); } - public void replaceSciptPack(ScriptPack pack, String as) throws AVM2ParseException, CompilationException, IOException, InterruptedException { + public void replaceScriptPack(ScriptPack pack, String as) throws AVM2ParseException, CompilationException, IOException, InterruptedException { String scriptName = pack.getPathScriptName() + ".as"; int oldIndex = pack.scriptIndex; int newIndex = script_info.size(); @@ -1248,6 +1249,7 @@ public class ABC { // Move newly added script to its position script_info.set(oldIndex, script_info.get(newIndex)); script_info.remove(newIndex); + script_info.get(oldIndex).setModified(true); pack(); // removes old classes/methods ((Tag) parentTag).setModified(true); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index a45d52f02..f2073a38c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -27,6 +27,19 @@ import java.util.List; public class ScriptInfo { + @Internal + private boolean modified = true; + + public void setModified(boolean modified) { + this.modified = modified; + } + + public boolean isModified() { + return modified; + } + + + @Internal public boolean deleted; @@ -35,7 +48,7 @@ public class ScriptInfo { public Traits traits; public ScriptInfo() { - traits = new Traits(); + traits = new Traits(); } public ScriptInfo(Traits traits) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java index 85e9669b0..87a9c0805 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ABCInputStream; import com.jpexs.decompiler.flash.abc.CopyOutputStream; +import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; @@ -139,4 +140,15 @@ public class DoABCDefineTag extends Tag implements ABCContainerTag { } return 0; } + + @Override + public void setModified(boolean value) { + super.setModified(value); + if (value == false && !isModified()) { + ABC abc = getABC(); + for (ScriptInfo si : abc.script_info) { + si.setModified(false); + } + } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java index 32f841e78..f07237991 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ABCInputStream; import com.jpexs.decompiler.flash.abc.CopyOutputStream; +import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFField; @@ -111,4 +112,16 @@ public class DoABCTag extends Tag implements ABCContainerTag { public int compareTo(ABCContainerTag o) { return 0; } + + @Override + public void setModified(boolean value) { + super.setModified(value); + if (value == false && !isModified()) { + ABC abc = getABC(); + for (ScriptInfo si : abc.script_info) { + si.setModified(false); + } + } + } + } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index cd9f2aecd..1946d69d9 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1839,7 +1839,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (bi != -1) { getABCPanel().abc.bodies.get(bi).restoreControlFlow(getABCPanel().abc.constants, getABCPanel().decompiledTextArea.getCurrentTrait(), getABCPanel().abc.method_info.get(getABCPanel().abc.bodies.get(bi).method_info)); } - getABCPanel().detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, getABCPanel().abc, getABCPanel().decompiledTextArea.getCurrentTrait()); + getABCPanel().detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, getABCPanel().abc, getABCPanel().decompiledTextArea.getCurrentTrait(),getABCPanel().detailPanel.methodTraitPanel.methodCodePanel.getScriptIndex()); } return true; } @@ -1942,7 +1942,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec getABCPanel().abc.bodies.get(bi).restoreControlFlow(getABCPanel().abc.constants, t, getABCPanel().abc.method_info.get(getABCPanel().abc.bodies.get(bi).method_info)); } } - getABCPanel().detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, getABCPanel().abc, t); + getABCPanel().detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, getABCPanel().abc, t,getABCPanel().detailPanel.methodTraitPanel.methodCodePanel.getScriptIndex()); } } catch (Exception ex) { logger.log(Level.SEVERE, "Deobfuscation error", ex); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index f8738395d..8d3965c7b 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -163,6 +163,8 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se public JButton cancelDecompiledButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16")); private static final String ACTION_ADD_TRAIT = "ADDTRAIT"; + + private static List modifiedPacks = new ArrayList<>(); public MainPanel getMainPanel() { return mainPanel; @@ -810,7 +812,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se } String as = decompiledTextArea.getText(); - abc.replaceSciptPack(pack, as); + abc.replaceScriptPack(pack, as); lastDecompiled = as; mainPanel.updateClassesList(); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 29f905a98..8811ed90e 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -50,7 +50,14 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi public ABC abc; public int bodyIndex = -1; + private int scriptIndex = -1; + public int getScriptIndex() { + return scriptIndex; + } + + + private List disassembledHilights = new ArrayList<>(); private List specialHilights = new ArrayList<>(); @@ -164,11 +171,12 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi return super.getName(); } - public void setBodyIndex(int bodyIndex, ABC abc, String name, Trait trait) { + public void setBodyIndex(int bodyIndex, ABC abc, String name, Trait trait, int scriptIndex) { this.bodyIndex = bodyIndex; this.abc = abc; this.name = name; this.trait = trait; + this.scriptIndex = scriptIndex; if (bodyIndex == -1) { return; } @@ -225,9 +233,10 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi } }, abc.bodies.get(bodyIndex), abc.method_info.get(abc.bodies.get(bodyIndex).method_info)); //acode.getBytes(abc.bodies.get(bodyIndex).getCodeBytes()); - abc.bodies.get(bodyIndex).setCode(acode); + abc.bodies.get(bodyIndex).setCode(acode); } ((Tag) abc.parentTag).setModified(true); + abc.script_info.get(scriptIndex).setModified(true); } catch (IOException ex) { } catch (InterruptedException ex) { } catch (AVM2ParseException ex) { diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 96f4b0bbc..74b51f18a 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -212,7 +212,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL abcPanel.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD, trait); MethodCodePanel methodCodePanel = abcPanel.detailPanel.methodTraitPanel.methodCodePanel; if (reset || (methodCodePanel.getBodyIndex() != bi)) { - methodCodePanel.setBodyIndex(bi, abc, name, trait); + methodCodePanel.setBodyIndex(bi, abc, name, trait,script.scriptIndex); abcPanel.detailPanel.setEditMode(false); this.isStatic = isStatic; } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java b/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java index bc41cea72..bb418dc1a 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java @@ -58,6 +58,10 @@ public class MethodCodePanel extends JPanel implements ActionListener { sourceTextArea.requestFocusInWindow(); } + public int getScriptIndex(){ + return sourceTextArea.getScriptIndex(); + } + public String getTraitName() { return sourceTextArea.getName(); } @@ -74,13 +78,15 @@ public class MethodCodePanel extends JPanel implements ActionListener { sourceTextArea.hilighSpecial(type, specialValue); } - public void setBodyIndex(int bodyIndex, ABC abc, Trait trait) { - sourceTextArea.setBodyIndex(bodyIndex, abc, sourceTextArea.getName(), trait); + public void setBodyIndex(int bodyIndex, ABC abc, Trait trait, int scriptIndex) { + sourceTextArea.setBodyIndex(bodyIndex, abc, sourceTextArea.getName(), trait,scriptIndex); } - public void setBodyIndex(int bodyIndex, ABC abc, String name, Trait trait) { - sourceTextArea.setBodyIndex(bodyIndex, abc, name, trait); + public void setBodyIndex(int bodyIndex, ABC abc, String name, Trait trait,int scriptIndex) { + sourceTextArea.setBodyIndex(bodyIndex, abc, name, trait,scriptIndex); } + + public int getBodyIndex() { return sourceTextArea.bodyIndex; diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java index 9028cc5c0..077bb18c3 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java @@ -192,6 +192,13 @@ public class TagTree extends JTree { } boolean isModified = val instanceof Tag && ((Tag) val).isModified(); + if(val instanceof ScriptPack){ + ScriptPack sp=(ScriptPack)val; + if(sp.abc.script_info.get(sp.scriptIndex).isModified()){ + isModified = true; + } + } + if (isModified) { if (boldFont == null) { Font font = getFont();