AS search moved to lib

This commit is contained in:
honfika@gmail.com
2016-12-24 22:00:27 +01:00
parent c3fc9785e3
commit 407d1c2235
7 changed files with 245 additions and 151 deletions

View File

@@ -14,7 +14,7 @@
* 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;
package com.jpexs.decompiler.flash.search;
import com.jpexs.decompiler.flash.abc.ScriptPack;
@@ -22,11 +22,11 @@ import com.jpexs.decompiler.flash.abc.ScriptPack;
*
* @author JPEXS
*/
public class ABCPanelSearchResult {
public class ABCSearchResult {
private final ScriptPack scriptPack;
public ABCPanelSearchResult(ScriptPack scriptPack) {
public ABCSearchResult(ScriptPack scriptPack) {
this.scriptPack = scriptPack;
}

View File

@@ -0,0 +1,188 @@
/*
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.search;
import com.jpexs.decompiler.flash.AppResources;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.cache.ScriptDecompiledListener;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.HighlightedText;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
/**
*
* @author JPEXS
*/
public class ActionScriptSearch {
public List<ActionSearchResult> searchAs2(SWF swf, final String txt, boolean ignoreCase, boolean regexp, boolean pcode, ScriptSearchListener listener) {
if (txt != null && !txt.isEmpty()) {
Map<String, ASMSource> asms = swf.getASMs(false);
final List<ActionSearchResult> found = new ArrayList<>();
Pattern pat = regexp
? Pattern.compile(txt, ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0)
: Pattern.compile(Pattern.quote(txt), ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0);
int pos = 0;
List<Future<HighlightedText>> futures = new ArrayList<>();
String workText = AppResources.translate("work.searching");
String decAdd = ", " + AppResources.translate("work.decompiling");
try {
for (Map.Entry<String, ASMSource> item : asms.entrySet()) {
pos++;
ASMSource asm = item.getValue();
if (pcode) {
//Main.startWork(workText + " \"" + txt + "\" - (" + pos + "/" + asms.size() + ") " + item.getKey() + "... ", worker);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
asm.getASMSource(ScriptExportMode.PCODE, writer, null);
String text = writer.toString();
if (pat.matcher(text).find()) {
found.add(new ActionSearchResult(asm, pcode, item.getKey()));
}
} else {
int fpos = pos;
Future<HighlightedText> text = SWF.getCachedFuture(asm, null, new ScriptDecompiledListener<HighlightedText>() {
@Override
public void onStart() {
if (listener != null) {
listener.onWork(workText + " \"" + txt + "\"" + decAdd + " - (" + fpos + "/" + asms.size() + ") " + item.getKey() + "... ");
}
}
@Override
public void onComplete(HighlightedText result) {
if (listener != null) {
listener.onWork(workText + " \"" + txt + "\"" + decAdd + " - (" + fpos + "/" + asms.size() + ") " + item.getKey() + "... ");
}
if (pat.matcher(result.text).find()) {
ActionSearchResult searchResult = new ActionSearchResult(asm, pcode, item.getKey());
found.add(searchResult);
}
}
});
futures.add(text);
}
}
} catch (InterruptedException ex) {
for (Future<HighlightedText> future : futures) {
future.cancel(true);
}
}
return found;
}
return null;
}
public List<ABCSearchResult> searchAs3(final SWF swf, final String txt, boolean ignoreCase, boolean regexp, boolean pcode, ScriptSearchListener listener) {
// todo: pcode seach
if (txt != null && !txt.isEmpty()) {
List<String> ignoredClasses = new ArrayList<>();
List<String> ignoredNss = new ArrayList<>();
if (Configuration._ignoreAdditionalFlexClasses.get()) {
swf.getFlexMainClass(ignoredClasses, ignoredNss);
}
final List<ABCSearchResult> found = new ArrayList<>();
List<ScriptPack> allpacks = swf.getAS3Packs();
final Pattern pat = regexp
? Pattern.compile(txt, ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0)
: Pattern.compile(Pattern.quote(txt), ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0);
int pos = 0;
List<Future<HighlightedText>> futures = new ArrayList<>();
String workText = AppResources.translate("work.searching");
String decAdd = ", " + AppResources.translate("work.decompiling");
try {
loop:
for (final ScriptPack pack : allpacks) {
pos++;
if (!pack.isSimple && Configuration.ignoreCLikePackages.get()) {
continue;
}
if (Configuration._ignoreAdditionalFlexClasses.get()) {
String fullName = pack.getClassPath().packageStr.add(pack.getClassPath().className, pack.getClassPath().namespaceSuffix).toRawString();
if (ignoredClasses.contains(fullName)) {
continue;
}
for (String ns : ignoredNss) {
if (fullName.startsWith(ns + ".")) {
continue loop;
}
}
}
int fpos = pos;
Future<HighlightedText> text = SWF.getCachedFuture(pack, new ScriptDecompiledListener<HighlightedText>() {
@Override
public void onStart() {
if (listener != null) {
listener.onWork(workText + " \"" + txt + "\"" + decAdd + " - (" + fpos + "/" + allpacks.size() + ") " + pack.getClassPath().toString() + "... ");
}
}
@Override
public void onComplete(HighlightedText result) {
if (listener != null) {
listener.onWork(workText + " \"" + txt + "\" - (" + fpos + "/" + allpacks.size() + ") " + pack.getClassPath().toString() + "... ");
}
if (pat.matcher(result.text).find()) {
ABCSearchResult searchResult = new ABCSearchResult(pack);
found.add(searchResult);
}
}
});
futures.add(text);
}
for (Future<HighlightedText> future : futures) {
try {
future.get();
} catch (ExecutionException ex) {
Logger.getLogger(ActionScriptSearch.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (InterruptedException ex) {
for (Future<HighlightedText> future : futures) {
future.cancel(true);
}
}
return found;
}
return null;
}
}

View File

@@ -14,7 +14,7 @@
* 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;
package com.jpexs.decompiler.flash.search;
import com.jpexs.decompiler.flash.tags.base.ASMSource;

View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.search;
/**
*
* @author JPEXS
*/
public interface ScriptSearchListener {
public void onWork(String message);
}

View File

@@ -77,12 +77,10 @@ import com.jpexs.decompiler.flash.exporters.swf.SwfJavaExporter;
import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter;
import com.jpexs.decompiler.flash.flexsdk.MxmlcAs3ScriptReplacer;
import com.jpexs.decompiler.flash.gui.abc.ABCPanel;
import com.jpexs.decompiler.flash.gui.abc.ABCPanelSearchResult;
import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel;
import com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane;
import com.jpexs.decompiler.flash.gui.abc.DeobfuscationDialog;
import com.jpexs.decompiler.flash.gui.action.ActionPanel;
import com.jpexs.decompiler.flash.gui.action.ActionSearchResult;
import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane;
import com.jpexs.decompiler.flash.gui.dumpview.DumpTree;
import com.jpexs.decompiler.flash.gui.dumpview.DumpTreeModel;
@@ -107,6 +105,8 @@ import com.jpexs.decompiler.flash.importers.SwfXmlImporter;
import com.jpexs.decompiler.flash.importers.SymbolClassImporter;
import com.jpexs.decompiler.flash.importers.TextImporter;
import com.jpexs.decompiler.flash.importers.svg.SvgImporter;
import com.jpexs.decompiler.flash.search.ABCSearchResult;
import com.jpexs.decompiler.flash.search.ActionSearchResult;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag;
@@ -1734,7 +1734,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
new CancellableWorker<Void>() {
@Override
protected Void doInBackground() throws Exception {
List<ABCPanelSearchResult> abcResult = null;
List<ABCSearchResult> abcResult = null;
List<ActionSearchResult> actionResult = null;
if (swf.isAS3()) {
abcResult = getABCPanel().search(swf, txt, ignoreCase, regexp, pCodeSearch, this);
@@ -1742,14 +1742,14 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
actionResult = getActionPanel().search(swf, txt, ignoreCase, regexp, pCodeSearch, this);
}
List<ABCPanelSearchResult> fAbcResult = abcResult;
List<ABCSearchResult> fAbcResult = abcResult;
List<ActionSearchResult> fActionResult = actionResult;
View.execInEventDispatch(() -> {
boolean found = false;
if (fAbcResult != null) {
found = true;
getABCPanel().searchPanel.setSearchText(txt);
SearchResultsDialog<ABCPanelSearchResult> sr = new SearchResultsDialog<>(getMainFrame().getWindow(), txt, getABCPanel());
SearchResultsDialog<ABCSearchResult> sr = new SearchResultsDialog<>(getMainFrame().getWindow(), txt, getABCPanel());
sr.setResults(fAbcResult);
sr.setVisible(true);
} else if (fActionResult != null) {

View File

@@ -44,7 +44,6 @@ import com.jpexs.decompiler.flash.action.parser.ActionParseException;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptLexer;
import com.jpexs.decompiler.flash.action.parser.script.ParsedSymbol;
import com.jpexs.decompiler.flash.action.parser.script.SymbolType;
import com.jpexs.decompiler.flash.cache.ScriptDecompiledListener;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.gui.AppDialog;
@@ -69,11 +68,13 @@ import com.jpexs.decompiler.flash.gui.abc.tablemodels.UIntTableModel;
import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane;
import com.jpexs.decompiler.flash.gui.editor.LinkHandler;
import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel;
import com.jpexs.decompiler.flash.helpers.HighlightedText;
import com.jpexs.decompiler.flash.importers.As3ScriptReplaceException;
import com.jpexs.decompiler.flash.importers.As3ScriptReplaceExceptionItem;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerInterface;
import com.jpexs.decompiler.flash.importers.FFDecAs3ScriptReplacer;
import com.jpexs.decompiler.flash.search.ABCSearchResult;
import com.jpexs.decompiler.flash.search.ActionScriptSearch;
import com.jpexs.decompiler.flash.search.ScriptSearchListener;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
@@ -102,11 +103,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.swing.AbstractAction;
import javax.swing.BoxLayout;
import javax.swing.JButton;
@@ -137,7 +135,7 @@ import jsyntaxpane.TokenType;
*
* @author JPEXS
*/
public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABCPanelSearchResult>, TagEditorPanel {
public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABCSearchResult>, TagEditorPanel {
private As3ScriptReplacerInterface scriptReplacer = null;
@@ -169,7 +167,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
public final JTabbedPane tabbedPane;
public final SearchPanel<ABCPanelSearchResult> searchPanel;
public final SearchPanel<ABCSearchResult> searchPanel;
private NewTraitDialog newTraitDialog;
@@ -191,84 +189,15 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
return mainPanel;
}
public List<ABCPanelSearchResult> search(final SWF swf, final String txt, boolean ignoreCase, boolean regexp, boolean pcode, CancellableWorker<Void> worker) {
// todo: pcode seach
List<String> ignoredClasses = new ArrayList<>();
List<String> ignoredNss = new ArrayList<>();
if (Configuration._ignoreAdditionalFlexClasses.get()) {
abc.getSwf().getFlexMainClass(ignoredClasses, ignoredNss);
}
public List<ABCSearchResult> search(final SWF swf, final String txt, boolean ignoreCase, boolean regexp, boolean pcode, CancellableWorker<Void> worker) {
if (txt != null && !txt.isEmpty()) {
searchPanel.setOptions(ignoreCase, regexp);
TagTreeModel ttm = (TagTreeModel) mainPanel.tagTree.getModel();
TreeItem scriptsNode = ttm.getScriptsNode(swf);
final List<ABCPanelSearchResult> found = new ArrayList<>();
if (scriptsNode instanceof ClassesListTreeModel) {
ClassesListTreeModel clModel = (ClassesListTreeModel) scriptsNode;
List<ScriptPack> allpacks = clModel.getList();
final Pattern pat = regexp
? Pattern.compile(txt, ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0)
: Pattern.compile(Pattern.quote(txt), ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0);
int pos = 0;
List<Future<HighlightedText>> futures = new ArrayList<>();
String workText = AppStrings.translate("work.searching");
String decAdd = ", " + AppStrings.translate("work.decompiling");
try {
loop:
for (final ScriptPack pack : allpacks) {
pos++;
if (!pack.isSimple && Configuration.ignoreCLikePackages.get()) {
continue;
}
if (Configuration._ignoreAdditionalFlexClasses.get()) {
String fullName = pack.getClassPath().packageStr.add(pack.getClassPath().className, pack.getClassPath().namespaceSuffix).toRawString();
if (ignoredClasses.contains(fullName)) {
continue;
}
for (String ns : ignoredNss) {
if (fullName.startsWith(ns + ".")) {
continue loop;
}
}
}
int fpos = pos;
Future<HighlightedText> text = SWF.getCachedFuture(pack, new ScriptDecompiledListener<HighlightedText>() {
@Override
public void onStart() {
Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + fpos + "/" + allpacks.size() + ") " + pack.getClassPath().toString() + "... ", worker);
}
@Override
public void onComplete(HighlightedText result) {
Main.startWork(workText + " \"" + txt + "\" - (" + fpos + "/" + allpacks.size() + ") " + pack.getClassPath().toString() + "... ", worker);
if (pat.matcher(result.text).find()) {
ABCPanelSearchResult searchResult = new ABCPanelSearchResult(pack);
found.add(searchResult);
}
}
});
futures.add(text);
}
for (Future<HighlightedText> future : futures) {
try {
future.get();
} catch (ExecutionException ex) {
Logger.getLogger(ABCPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (InterruptedException ex) {
for (Future<HighlightedText> future : futures) {
future.cancel(true);
}
return new ActionScriptSearch().searchAs3(swf, txt, ignoreCase, regexp, pcode, new ScriptSearchListener() {
@Override
public void onWork(String message) {
Main.startWork(message, worker);
}
}
return found;
});
}
return null;
@@ -1275,6 +1204,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
if (!item.isSimple && Configuration.ignoreCLikePackages.get()) {
continue;
}
ClassPath classPath = item.getClassPath();
// first check the className to avoid calling unnecessary toString
@@ -1283,6 +1213,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
break;
}
}
if (pack != null) {
hilightScript(pack);
}
@@ -1305,7 +1236,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
}
@Override
public void updateSearchPos(ABCPanelSearchResult item) {
public void updateSearchPos(ABCSearchResult item) {
ScriptPack pack = item.getScriptPack();
setAbc(pack.abc);
decompiledTextArea.setScript(pack, false);

View File

@@ -30,7 +30,6 @@ import com.jpexs.decompiler.flash.action.parser.script.ParsedSymbol;
import com.jpexs.decompiler.flash.action.parser.script.SymbolType;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ConstantIndex;
import com.jpexs.decompiler.flash.cache.ScriptDecompiledListener;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.gui.AppStrings;
@@ -53,6 +52,9 @@ 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.Highlighting;
import com.jpexs.decompiler.flash.search.ActionScriptSearch;
import com.jpexs.decompiler.flash.search.ActionSearchResult;
import com.jpexs.decompiler.flash.search.ScriptSearchListener;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.helpers.CancellableWorker;
@@ -64,16 +66,11 @@ import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
@@ -250,60 +247,12 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
public List<ActionSearchResult> search(SWF swf, final String txt, boolean ignoreCase, boolean regexp, boolean pcode, CancellableWorker<Void> worker) {
if (txt != null && !txt.isEmpty()) {
searchPanel.setOptions(ignoreCase, regexp);
Map<String, ASMSource> asms = swf.getASMs(false);
final List<ActionSearchResult> found = new ArrayList<>();
Pattern pat;
if (regexp) {
pat = Pattern.compile(txt, ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0);
} else {
pat = Pattern.compile(Pattern.quote(txt), ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0);
}
int pos = 0;
List<Future<HighlightedText>> futures = new ArrayList<>();
String workText = AppStrings.translate("work.searching");
String decAdd = ", " + AppStrings.translate("work.decompiling");
try {
for (Entry<String, ASMSource> item : asms.entrySet()) {
pos++;
ASMSource asm = item.getValue();
if (pcode) {
Main.startWork(workText + " \"" + txt + "\" - (" + pos + "/" + asms.size() + ") " + item.getKey() + "... ", worker);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
asm.getASMSource(ScriptExportMode.PCODE, writer, null);
String text = writer.toString();
if (pat.matcher(text).find()) {
found.add(new ActionSearchResult(asm, pcode, item.getKey()));
}
} else {
int fpos = pos;
Future<HighlightedText> text = SWF.getCachedFuture(asm, null, new ScriptDecompiledListener<HighlightedText>() {
@Override
public void onStart() {
Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + fpos + "/" + asms.size() + ") " + item.getKey() + "... ", worker);
}
@Override
public void onComplete(HighlightedText result) {
Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + fpos + "/" + asms.size() + ") " + item.getKey() + "... ", worker);
if (pat.matcher(result.text).find()) {
ActionSearchResult searchResult = new ActionSearchResult(asm, pcode, item.getKey());
found.add(searchResult);
}
}
});
futures.add(text);
}
return new ActionScriptSearch().searchAs2(swf, txt, ignoreCase, regexp, pcode, new ScriptSearchListener() {
@Override
public void onWork(String message) {
Main.startWork(message, worker);
}
} catch (InterruptedException ex) {
for (Future<HighlightedText> future : futures) {
future.cancel(true);
}
}
return found;
});
}
return null;