Merge origin/master

This commit is contained in:
Jindra Petřík
2014-11-22 06:23:09 +01:00
33 changed files with 1028 additions and 1000 deletions
@@ -178,7 +178,7 @@ public class FontPanel extends javax.swing.JPanel {
}
}
ft.setModified(true);
SWF.clearImageCache();
ft.getSwf().clearImageCache();
}
public void showFontTag(FontTag ft) {
@@ -575,7 +575,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
try {
swf.deobfuscateIdentifiers(RenameType.TYPENUMBER);
swf.assignClassesToSymbols();
clearCache();
swf.clearScriptCache();
if (abcPanel != null) {
abcPanel.reload();
}
@@ -1037,15 +1037,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
return null;
}
private void clearCache() {
if (abcPanel != null) {
abcPanel.decompiledTextArea.clearScriptCache();
}
if (actionPanel != null) {
actionPanel.clearCache();
}
}
public void gotoFrame(int frame) {
TreeItem treeItem = (TreeItem) tagTree.getLastSelectedPathComponent();
if (treeItem == null) {
@@ -1087,7 +1078,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
public void disableDecompilationChanged() {
clearCache();
clearAllScriptCache();
if (abcPanel != null) {
abcPanel.reload();
}
@@ -1095,6 +1087,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
updateClassesList();
}
private void clearAllScriptCache() {
for (SWFList swfList : swfs) {
for (SWF swf : swfList) {
swf.clearScriptCache();
}
}
}
public void searchAs() {
if (searchDialog == null) {
searchDialog = new SearchDialog(getMainFrame().getWindow());
@@ -1204,7 +1204,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
public void autoDeobfuscateChanged() {
Helper.decompilationErrorAdd = AppStrings.translate(Configuration.autoDeobfuscate.get() ? "deobfuscation.comment.failed" : "deobfuscation.comment.tryenable");
clearCache();
clearAllScriptCache();
if (abcPanel != null) {
abcPanel.reload();
}
@@ -1507,7 +1507,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
}
SWF.clearImageCache();
swf.clearImageCache();
reload(true);
}
}
@@ -1672,7 +1672,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
Main.stopWork();
View.showMessageDialog(null, translate("message.rename.renamed").replace("%count%", Integer.toString(cnt)));
swf.assignClassesToSymbols();
clearCache();
swf.clearScriptCache();
if (abcPanel != null) {
abcPanel.reload();
}
@@ -1743,7 +1743,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
@Override
public void run() {
clearCache();
clearAllScriptCache();
getABCPanel().reload();
updateClassesList();
}
@@ -1792,7 +1792,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
public void refreshDecompiled() {
clearCache();
clearAllScriptCache();
if (abcPanel != null) {
abcPanel.reload();
}
@@ -1881,7 +1881,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
refreshTree();
setTagTreeSelectedNode(newTag);
}
SWF.clearImageCache();
it.getSwf().clearImageCache();
} catch (IOException ex) {
logger.log(Level.SEVERE, "Invalid image", ex);
View.showMessageDialog(null, translate("error.image.invalid"), translate("error"), JOptionPane.ERROR_MESSAGE);
@@ -1903,7 +1903,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
refreshTree();
setTagTreeSelectedNode(newTag);
}
SWF.clearImageCache();
st.getSwf().clearImageCache();
} catch (IOException ex) {
logger.log(Level.SEVERE, "Invalid image", ex);
View.showMessageDialog(null, translate("error.image.invalid"), translate("error"), JOptionPane.ERROR_MESSAGE);
@@ -966,9 +966,10 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
break;
case ACTION_SAVE_GENERIC_TAG: {
genericTagPanel.save();
SWF.clearImageCache();
Tag tag = genericTagPanel.getTag();
tag.getSwf().updateCharacters();
SWF swf = tag.getSwf();
swf.clearImageCache();
swf.updateCharacters();
tag.getTimelined().getTimeline().reset();
mainPanel.refreshTree();
mainPanel.setTagTreeSelectedNode(tag);
@@ -131,7 +131,7 @@ public class TextPanel extends JPanel implements ActionListener {
setEditText(false);
mainPanel.reload(true);
}
SWF.clearImageCache();
item.getSwf().clearImageCache();
}
break;
}
@@ -167,7 +167,8 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
pos++;
String workText = AppStrings.translate("work.searching");
String decAdd = "";
if (!decompiledTextArea.isCached(item.getValue())) {
final ScriptPack pack = item.getValue();
if (!SWF.isCached(pack)) {
decAdd = ", " + AppStrings.translate("work.decompiling");
}
@@ -176,10 +177,9 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
@Override
public Void doInBackground() throws Exception {
decompiledTextArea.cacheScriptPack(item.getValue(), swf.abcList);
if (pat.matcher(decompiledTextArea.getCachedText(item.getValue())).find()) {
if (pat.matcher(SWF.getCached(pack).text).find()) {
ABCPanelSearchResult searchResult = new ABCPanelSearchResult();
searchResult.scriptPack = item.getValue();
searchResult.scriptPack = pack;
searchResult.classPath = item.getKey();
found.add(searchResult);
}
@@ -644,7 +644,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
public void reload() {
lastDecompiled = "";
decompiledTextArea.clearScriptCache();
swf.clearScriptCache();
decompiledTextArea.reloadClass();
detailPanel.methodTraitPanel.methodCodePanel.clear();
}
@@ -781,7 +781,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
case ACTION_SAVE_DECOMPILED:
ScriptPack pack = decompiledTextArea.getScriptLeaf();
int oldIndex = pack.scriptIndex;
decompiledTextArea.uncache(pack);
SWF.uncache(pack);
try {
String oldSp = null;
@@ -1,65 +0,0 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.helpers.HighlightedText;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import java.io.Serializable;
import java.util.List;
/**
*
* @author JPEXS
*/
public class CachedDecompilation implements Serializable {
public String text;
public List<Highlighting> traitHilights;
public List<Highlighting> classHilights;
public List<Highlighting> methodHilights;
public List<Highlighting> instructionHilights;
public List<Highlighting> specialHilights;
public List<Highlighting> getInstructionHighlights() {
return instructionHilights;
}
public List<Highlighting> getTraitHighlights() {
return traitHilights;
}
public List<Highlighting> getMethodHighlights() {
return methodHilights;
}
public List<Highlighting> getClassHighlights() {
return classHilights;
}
public List<Highlighting> getSpecialHighligths() {
return specialHilights;
}
public CachedDecompilation(HighlightedText HighlightedText) {
this.text = HighlightedText.text;
this.traitHilights = HighlightedText.traitHilights;
this.classHilights = HighlightedText.classHilights;
this.methodHilights = HighlightedText.methodHilights;
this.instructionHilights = HighlightedText.instructionHilights;
this.specialHilights = HighlightedText.specialHilights;
}
}
@@ -16,7 +16,9 @@
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.CachedDecompilation;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
@@ -32,17 +34,12 @@ import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction;
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.decompiler.flash.helpers.HighlightedText;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.helpers.Cache;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
@@ -72,7 +69,6 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
private final ABCPanel abcPanel;
private int classIndex = -1;
private boolean isStatic = false;
private final Cache<ScriptPack, CachedDecompilation> cache = Cache.getInstance(true);
private final List<Runnable> scriptListeners = new ArrayList<>();
@@ -583,25 +579,6 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
}
}
public void uncache(ScriptPack pack) {
cache.remove(pack);
}
public boolean isCached(ScriptPack pack) {
return cache.contains(pack);
}
private CachedDecompilation getCached(ScriptPack pack) throws InterruptedException {
if (!cache.contains(pack)) {
cacheScriptPack(pack, abcList);
}
return (CachedDecompilation) cache.get(pack);
}
public String getCachedText(ScriptPack pack) throws InterruptedException {
return getCached(pack).text;
}
public void gotoLastTrait() {
gotoTrait(lastTraitIndex);
}
@@ -647,27 +624,6 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
}
private List<ABCContainerTag> abcList;
public void clearScriptCache() {
cache.clear();
}
public void cacheScriptPack(ScriptPack scriptLeaf, List<ABCContainerTag> abcList) throws InterruptedException {
int maxCacheSize = 50;
int scriptIndex = scriptLeaf.scriptIndex;
ScriptInfo script = null;
ABC abc = scriptLeaf.abc;
if (scriptIndex > -1) {
script = abc.script_info.get(scriptIndex);
}
if (!cache.contains(scriptLeaf)) {
boolean parallel = Configuration.parallelSpeedUp.get();
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
scriptLeaf.toSource(writer, abcList, script.traits.traits, ScriptExportMode.AS, parallel);
HighlightedText hilightedCode = new HighlightedText(writer);
cache.put(scriptLeaf, new CachedDecompilation(hilightedCode));
}
}
public void setScript(ScriptPack scriptLeaf, List<ABCContainerTag> abcList) {
abcPanel.scriptNameLabel.setText(scriptLeaf.getClassPath().toString());
int scriptIndex = scriptLeaf.scriptIndex;
@@ -691,8 +647,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
this.script = scriptLeaf;
CachedDecompilation cd = null;
try {
cacheScriptPack(scriptLeaf, abcList);
cd = getCached(scriptLeaf);
cd = SWF.getCached(scriptLeaf);
} catch (InterruptedException ex) {
}
if (cd != null) {
@@ -710,7 +665,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
public void reloadClass() {
int ci = classIndex;
uncache(script);
SWF.uncache(script);
if ((script != null) && (abc != null)) {
setScript(script, abcList);
}
@@ -724,7 +679,6 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
public void setABC(ABC abc) {
this.abc = abc;
cache.clear();
setText("");
}
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionGraph;
import com.jpexs.decompiler.flash.action.ActionList;
import com.jpexs.decompiler.flash.action.CachedScript;
import com.jpexs.decompiler.flash.action.parser.ActionParseException;
import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptLexer;
@@ -48,7 +49,6 @@ import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.helpers.Cache;
import com.jpexs.helpers.CancellableWorker;
import com.jpexs.helpers.Helper;
import java.awt.BorderLayout;
@@ -129,7 +129,6 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
private String lastDecompiled = "";
private ASMSource lastASM;
public SearchPanel<ActionSearchResult> searchPanel;
private Cache<ASMSource, CachedScript> cache = Cache.getInstance(true);
private CancellableWorker setSourceWorker;
public void clearSource() {
@@ -143,10 +142,6 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
srcHexOnly = null;
}
public void clearCache() {
cache.clear();
}
public String getStringUnderCursor() {
int pos = decompiledEditor.getCaretPosition();
@@ -213,27 +208,6 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
return null;
}
private CachedScript getCached(ASMSource pack) {
return (CachedScript) cache.get(pack);
}
private boolean isCached(ASMSource src) {
return cache.contains(src);
}
private void cacheScript(ASMSource src, List<Action> actions) throws InterruptedException {
if (!cache.contains(src)) {
if (actions == null) {
actions = src.getActions();
}
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
Action.actionsToSource(src, actions, src.toString()/*FIXME?*/, writer);
List<Highlighting> hilights = writer.instructionHilights;
String srcNoHex = writer.toString();
cache.put(src, new CachedScript(srcNoHex, hilights));
}
}
public boolean search(final String txt, boolean ignoreCase, boolean regexp) {
if ((txt != null) && (!txt.isEmpty())) {
searchPanel.setOptions(ignoreCase, regexp);
@@ -251,18 +225,18 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
pos++;
String workText = AppStrings.translate("work.searching");
String decAdd = "";
if (!isCached(item.getValue())) {
ASMSource asm = item.getValue();
if (!SWF.isCached(asm)) {
decAdd = ", " + AppStrings.translate("work.decompiling");
}
Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + asms.size() + ") " + item.getKey() + "... ");
try {
cacheScript(item.getValue(), null);
if (pat.matcher(SWF.getCached(asm, null).text).find()) {
found.add(new ActionSearchResult(asm, item.getKey()));
}
} catch (InterruptedException ex) {
break;
}
if (pat.matcher(getCached(item.getValue()).text).find()) {
found.add(new ActionSearchResult(item.getValue(), item.getKey()));
}
}
Main.stopWork();
@@ -434,10 +408,9 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
if (Configuration.decompile.get()) {
setDecompiledText("//" + AppStrings.translate("work.decompiling") + "...");
if (!useCache) {
uncache(asm);
SWF.uncache(asm);
}
cacheScript(asm, actions);
CachedScript sc = getCached(asm);
CachedScript sc = SWF.getCached(asm, actions);
decompiledHilights = sc.hilights;
lastDecompiled = sc.text;
lastASM = asm;
@@ -830,8 +803,4 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
}
});
}
private void uncache(ASMSource pack) {
cache.remove(pack);
}
}
@@ -1,36 +0,0 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.action;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import java.io.Serializable;
import java.util.List;
/**
*
* @author JPEXS
*/
public class CachedScript implements Serializable {
public String text;
List<Highlighting> hilights;
public CachedScript(String text, List<Highlighting> hilights) {
this.text = text;
this.hilights = hilights;
}
}
@@ -288,10 +288,13 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener {
@Override
public void actionPerformed(ActionEvent ae) {
tag.getSwf().tags.remove(tag);
SWF sourceSwf = tag.getSwf();
sourceSwf.tags.remove(tag);
tag.setSwf(targetSwf);
targetSwf.tags.add(tag);
tag.setModified(true);
sourceSwf.clearImageCache();
targetSwf.clearImageCache();
mainPanel.refreshTree();
}
});