do not copy big byte arrays, store only references (ByteArrayRange) e.g in image tags

This commit is contained in:
2014-11-09 22:40:36 +01:00
parent 270cc40856
commit 3456d04d38
151 changed files with 2787 additions and 2512 deletions
@@ -18,7 +18,6 @@ package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.gui.hexview.HexView;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
@@ -27,7 +26,6 @@ import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
+12 -13
View File
@@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.console.CommandLineArgumentParser;
import com.jpexs.decompiler.flash.console.ContextMenuTools;
import static com.jpexs.decompiler.flash.console.ContextMenuTools.getAppDir;
import com.jpexs.decompiler.flash.gui.debugger.Debugger;
import com.jpexs.decompiler.flash.gui.proxy.ProxyFrame;
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
@@ -820,7 +819,7 @@ public class Main {
if (GraphicsEnvironment.isHeadless()) { //No GUI in OS
return;
}
if (!Configuration.locale.hasValue()){
if (!Configuration.locale.hasValue()) {
if (Platform.isWindows()) {
//Load from Installer
String uninstKey = "{E618D276-6596-41F4-8A98-447D442A77DB}_is1";
@@ -833,30 +832,30 @@ public class Main {
char buf[] = new char[9];
int cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO639LANGNAME, buf, 9);
String langCode = new String(buf, 0, cnt).trim().toLowerCase();
cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO3166CTRYNAME, buf, 9);
String countryCode = new String(buf, 0, cnt).trim().toLowerCase();
List<String> langs=Arrays.asList(SelectLanguageDialog.getAvailableLanguages());
for(int i=0;i<langs.size();i++){
List<String> langs = Arrays.asList(SelectLanguageDialog.getAvailableLanguages());
for (int i = 0; i < langs.size(); i++) {
langs.set(i, langs.get(i).toLowerCase());
}
String selectedLang = null;
if(langs.contains(langCode+"-"+countryCode)){
selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode+"-"+countryCode)];
}else if(langs.contains(langCode)){
if (langs.contains(langCode + "-" + countryCode)) {
selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode + "-" + countryCode)];
} else if (langs.contains(langCode)) {
selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode)];
}
if(selectedLang!=null){
if (selectedLang != null) {
Configuration.locale.set(selectedLang);
}
}
}
} catch (Exception ex) {
//ignore
}
}
}
}
Locale.setDefault(Locale.forLanguageTag(Configuration.locale.get()));
@@ -127,7 +127,6 @@ import com.jpexs.decompiler.flash.types.MATRIX;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.sound.SoundFormat;
import com.jpexs.decompiler.flash.xfl.FLAVersion;
import com.jpexs.helpers.Cache;
import com.jpexs.helpers.CancellableWorker;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.Path;
@@ -140,7 +139,6 @@ import java.awt.Component;
import java.awt.Desktop;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
@@ -2234,6 +2232,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}, Configuration.parallelSpeedUp.get());
bswf.fileTitle = "(SWF Data)";
binaryDataTag.innerSwf = bswf;
bswf.binaryData = binaryDataTag;
} catch (IOException | InterruptedException ex) {
//ignore
}
@@ -73,7 +73,7 @@ public class NewVersionDialog extends AppDialog implements ActionListener {
changesStr += "<hr />";
}
first = false;
changesStr += "<b>" + translate("version") + " " + v.versionName + (v.nightly ? " nightly":"") + "</b><br />";
changesStr += "<b>" + translate("version") + " " + v.versionName + (v.nightly ? " nightly" : "") + "</b><br />";
String releaseDate = v.releaseDate;
try {
Date date = serverFormatter.parse(releaseDate);
@@ -100,7 +100,7 @@ public class NewVersionDialog extends AppDialog implements ActionListener {
}
changesText.setContentType("text/html");
changesText.setText("<html>" + changesStr + "</html>");
JLabel newAvailableLabel = new JLabel("<html><b><center>" + translate("newversionavailable") + " " + latestVersion.appName + " " + translate("version") + " " + latestVersion.versionName + (latestVersion.nightly ? " nightly":"") + "</center></b></html>", SwingConstants.CENTER);
JLabel newAvailableLabel = new JLabel("<html><b><center>" + translate("newversionavailable") + " " + latestVersion.appName + " " + translate("version") + " " + latestVersion.versionName + (latestVersion.nightly ? " nightly" : "") + "</center></b></html>", SwingConstants.CENTER);
newAvailableLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
cnt.add(newAvailableLabel);
@@ -28,7 +28,6 @@ import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import jsyntaxpane.DefaultSyntaxKit;
/**
*
@@ -49,7 +48,6 @@ public class TextPanel extends JPanel implements ActionListener {
public TextPanel(MainPanel mainPanel) {
super(new BorderLayout());
this.mainPanel = mainPanel;
textSearchPanel = new SearchPanel<>(new FlowLayout(), mainPanel);
@@ -360,10 +360,10 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
Helper.emptyObject(this);
}
public ABCPanel(MainPanel mainPanel) {
public ABCPanel(MainPanel mainPanel) {
DefaultSyntaxKit.initKit();
this.mainPanel = mainPanel;
setLayout(new BorderLayout());
@@ -373,12 +373,12 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
@Override
public boolean isLink(Token token) {
return hasDeclaration(token.length==1?token.start:token.start+1);
return hasDeclaration(token.length == 1 ? token.start : token.start + 1);
}
@Override
public void handleLink(Token token) {
gotoDeclaration(token.length==1?token.start:token.start+1);
gotoDeclaration(token.length == 1 ? token.start : token.start + 1);
}
@Override
@@ -543,25 +543,24 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
}
private boolean hasDeclaration(int pos) {
SyntaxDocument sd = (SyntaxDocument)decompiledTextArea.getDocument();
SyntaxDocument sd = (SyntaxDocument) decompiledTextArea.getDocument();
Token t = sd.getTokenAt(pos);
if(t==null || (t.type != TokenType.IDENTIFIER && t.type!=TokenType.KEYWORD && t.type!=TokenType.REGEX)){
if (t == null || (t.type != TokenType.IDENTIFIER && t.type != TokenType.KEYWORD && t.type != TokenType.REGEX)) {
return false;
}
Reference<Integer> abcIndex=new Reference<>(0);
Reference<Integer> classIndex=new Reference<>(0);
Reference<Integer> traitIndex=new Reference<>(0);
Reference<Integer> multinameIndexRef=new Reference<>(0);
Reference<Boolean> classTrait=new Reference<>(false);
if(decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait,multinameIndexRef)){
Reference<Integer> abcIndex = new Reference<>(0);
Reference<Integer> classIndex = new Reference<>(0);
Reference<Integer> traitIndex = new Reference<>(0);
Reference<Integer> multinameIndexRef = new Reference<>(0);
Reference<Boolean> classTrait = new Reference<>(false);
if (decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef)) {
return true;
}
int multinameIndex = decompiledTextArea.getMultinameAtPos(pos);
if (multinameIndex > -1) {
if(multinameIndex == 0){
if (multinameIndex == 0) {
return false;
}
List<MultinameUsage> usages = abc.findMultinameDefinition(swf.abcList, multinameIndex);
@@ -585,21 +584,20 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
if (!usages.isEmpty()) {
return true;
}
}
}
return decompiledTextArea.getLocalDeclarationOfPos(pos,new Reference<>("")) != -1;
return decompiledTextArea.getLocalDeclarationOfPos(pos, new Reference<>("")) != -1;
}
private void gotoDeclaration(int pos) {
Reference<Integer> abcIndex=new Reference<>(0);
Reference<Integer> classIndex=new Reference<>(0);
Reference<Integer> traitIndex=new Reference<>(0);
Reference<Boolean> classTrait=new Reference<>(false);
Reference<Integer> multinameIndexRef=new Reference<>(0);
if(decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait,multinameIndexRef)){
UsageFrame.gotoUsage(ABCPanel.this, new TraitMultinameUsage(swf.abcList, swf.abcList.get(abcIndex.getVal()).getABC(), multinameIndexRef.getVal(),classIndex.getVal(), traitIndex.getVal(), classTrait.getVal(), null, -1) {
Reference<Integer> abcIndex = new Reference<>(0);
Reference<Integer> classIndex = new Reference<>(0);
Reference<Integer> traitIndex = new Reference<>(0);
Reference<Boolean> classTrait = new Reference<>(false);
Reference<Integer> multinameIndexRef = new Reference<>(0);
if (decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef)) {
UsageFrame.gotoUsage(ABCPanel.this, new TraitMultinameUsage(swf.abcList, swf.abcList.get(abcIndex.getVal()).getABC(), multinameIndexRef.getVal(), classIndex.getVal(), traitIndex.getVal(), classTrait.getVal(), null, -1) {
});
return;
}
@@ -632,12 +630,12 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
return;
}
}
int dpos = decompiledTextArea.getLocalDeclarationOfPos(pos,new Reference<>(""));
int dpos = decompiledTextArea.getLocalDeclarationOfPos(pos, new Reference<>(""));
if (dpos > -1) {
decompiledTextArea.setCaretPosition(dpos);
}
}
private class CtrlClickHandler extends KeyAdapter implements MouseListener, MouseMotionListener {
@@ -860,7 +858,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
}
setDecompiledEditMode(false);
reload();
View.showMessageDialog(this, AppStrings.translate("message.action.saved"));
View.showMessageDialog(this, AppStrings.translate("message.action.saved"));
} catch (AVM2ParseException ex) {
abc.script_info.get(oldIndex).delete(abc, false);
decompiledTextArea.gotoLine((int) ex.line);
@@ -241,34 +241,34 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
return getMultinameAtPos(getCaretPosition());
}
public int getLocalDeclarationOfPos(int pos,Reference<String> type) {
public int getLocalDeclarationOfPos(int pos, Reference<String> type) {
Highlighting sh = Highlighting.search(specialHighlights, pos);
Highlighting h = Highlighting.search(highlights, pos);
if (h == null) {
return -1;
}
List<Highlighting> tms = Highlighting.searchAll(methodHighlights, pos, null, null, -1, -1);
if (tms.isEmpty()) {
return -1;
}
for (Highlighting tm : tms) {
List<Highlighting> tm_tms = Highlighting.searchAll(methodHighlights, -1, "index", tm.getPropertyString("index"), -1, -1);
List<Highlighting> tm_tms = Highlighting.searchAll(methodHighlights, -1, "index", tm.getPropertyString("index"), -1, -1);
//is it already declaration?
if ("true".equals(h.getPropertyString("declaration")) || (sh != null && "true".equals(sh.getPropertyString("declaration")))) {
return -1; //no jump
}
String lname=h.getPropertyString("localName");
if("this".equals(lname)){
Highlighting ch= Highlighting.search(classHighlights, pos);
int cindex=(int)(long)ch.getPropertyLong("index");
type.setVal(abc.instance_info.get(cindex).getName(abc.constants).getNameWithNamespace(abc.constants, true));
String lname = h.getPropertyString("localName");
if ("this".equals(lname)) {
Highlighting ch = Highlighting.search(classHighlights, pos);
int cindex = (int) (long) ch.getPropertyLong("index");
type.setVal(abc.instance_info.get(cindex).getName(abc.constants).getNameWithNamespace(abc.constants, true));
return ch.startPos;
}
Map<String, String> search = h.getProperties();
search.remove("index");
search.remove("subtype");
@@ -293,50 +293,51 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
return -1;
}
public boolean getPropertyTypeAtPos(int pos, Reference<Integer> abcIndex,Reference<Integer> classIndex, Reference<Integer> traitIndex, Reference<Boolean> classTrait, Reference<Integer> multinameIndex){
int m = getMultinameAtPos(pos,true);
public boolean getPropertyTypeAtPos(int pos, Reference<Integer> abcIndex, Reference<Integer> classIndex, Reference<Integer> traitIndex, Reference<Boolean> classTrait, Reference<Integer> multinameIndex) {
int m = getMultinameAtPos(pos, true);
if (m <= 0) {
return false;
}
SyntaxDocument sd=(SyntaxDocument)getDocument();
Token t = sd.getTokenAt(pos+1);
SyntaxDocument sd = (SyntaxDocument) getDocument();
Token t = sd.getTokenAt(pos + 1);
Token lastToken = t;
Token prev = null;
while(t.type == TokenType.IDENTIFIER || t.type == TokenType.KEYWORD || t.type == TokenType.REGEX){
Token prev = null;
while (t.type == TokenType.IDENTIFIER || t.type == TokenType.KEYWORD || t.type == TokenType.REGEX) {
prev = sd.getPrevToken(t);
if(prev!=null){
if(!".".equals(prev.getString(sd))){
break;
if (prev != null) {
if (!".".equals(prev.getString(sd))) {
break;
}
t = sd.getPrevToken(prev);
}else{
} else {
break;
}
}
}
if(t.type != TokenType.IDENTIFIER && t.type != TokenType.KEYWORD || t.type == TokenType.REGEX){
if (t.type != TokenType.IDENTIFIER && t.type != TokenType.KEYWORD || t.type == TokenType.REGEX) {
return false;
}
Reference<String> locTypeRef = new Reference<>("");
getLocalDeclarationOfPos(t.start,locTypeRef);
String currentType=locTypeRef.getVal();
if(currentType.equals("*")){
return false;
}
boolean found=false;
Reference<String> locTypeRef = new Reference<>("");
getLocalDeclarationOfPos(t.start, locTypeRef);
String currentType = locTypeRef.getVal();
if (currentType.equals("*")) {
return false;
}
boolean found = false;
t = sd.getNextToken(t);
while(t!=lastToken && !currentType.equals("*")){
while (t != lastToken && !currentType.equals("*")) {
t = sd.getNextToken(t);
String ident=t.getString(sd);
String ident = t.getString(sd);
found = false;
loopi:for(int i=0;i<abcList.size();i++){
loopi:
for (int i = 0; i < abcList.size(); i++) {
ABC a = abcList.get(i).getABC();
int cindex=a.findClassByName(currentType);
if(cindex>-1){
int cindex = a.findClassByName(currentType);
if (cindex > -1) {
InstanceInfo ii = a.instance_info.get(cindex);
for(int j=0;j<ii.instance_traits.traits.size();j++){
for (int j = 0; j < ii.instance_traits.traits.size(); j++) {
Trait tr = ii.instance_traits.traits.get(j);
if(ident.equals(tr.getName(a).getName(a.constants, new ArrayList<String>(), false /*NOT RAW!*/))){
if (ident.equals(tr.getName(a).getName(a.constants, new ArrayList<String>(), false /*NOT RAW!*/))) {
classIndex.setVal(cindex);
abcIndex.setVal(i);
traitIndex.setVal(j);
@@ -347,11 +348,11 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
break loopi;
}
}
ClassInfo ci = a.class_info.get(cindex);
for(int j=0;j<ci.static_traits.traits.size();j++){
for (int j = 0; j < ci.static_traits.traits.size(); j++) {
Trait tr = ci.static_traits.traits.get(j);
if(ident.equals(tr.getName(a).getName(a.constants, new ArrayList<String>(), false /*NOT RAW!*/))){
if (ident.equals(tr.getName(a).getName(a.constants, new ArrayList<String>(), false /*NOT RAW!*/))) {
classIndex.setVal(cindex);
abcIndex.setVal(i);
traitIndex.setVal(j);
@@ -364,22 +365,22 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
}
}
}
if(!found){
if (!found) {
return false;
}
t = sd.getNextToken(t);
if(!".".equals(t.getString(sd))){
if (!".".equals(t.getString(sd))) {
break;
}
}
}
return true;
}
public int getMultinameAtPos(int pos) {
return getMultinameAtPos(pos, false);
}
public int getMultinameAtPos(int pos, boolean codeOnly) {
Highlighting tm = Highlighting.search(methodHighlights, pos);
Trait currentTrait = null;
@@ -408,11 +409,11 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
lastIns = ins;
}
if (selIns != null) {
if (!codeOnly && ((selIns.definition instanceof ConstructSuperIns) || (selIns.definition instanceof CallSuperIns)|| (selIns.definition instanceof CallSuperVoidIns))) {
if (!codeOnly && ((selIns.definition instanceof ConstructSuperIns) || (selIns.definition instanceof CallSuperIns) || (selIns.definition instanceof CallSuperVoidIns))) {
Highlighting tc = Highlighting.search(classHighlights, pos);
if(tc!=null){
int cindex = (int)(long)tc.getPropertyLong("index");
if(cindex>-1){
if (tc != null) {
int cindex = (int) (long) tc.getPropertyLong("index");
if (cindex > -1) {
return abc.instance_info.get(cindex).super_index;
}
}
@@ -425,21 +426,20 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
}
}
}
}
if(codeOnly){
}
if (codeOnly) {
return -1;
}
Highlighting ch = Highlighting.search(classHighlights, pos);
if(ch!=null){
if (ch != null) {
Highlighting th = Highlighting.search(traitHighlights, pos);
if (th != null) {
currentTrait = abc.findTraitByTraitId((int) (long) ch.getPropertyLong("index"), (int) (long) th.getPropertyLong("index"));
currentTrait = abc.findTraitByTraitId((int) (long) ch.getPropertyLong("index"), (int) (long) th.getPropertyLong("index"));
}
}
}
if (currentTrait instanceof TraitMethodGetterSetter) {
currentMethod = ((TraitMethodGetterSetter) currentTrait).method_info;
}
@@ -32,10 +32,10 @@ import jsyntaxpane.actions.ActionUtils;
public class MyMarkers {
/**
* Removes only our private highlights
* This is public so that we can remove the highlights when the editorKit
* is unregistered. SimpleMarker can be null, in which case all instances of
* our Markers are removed.
* Removes only our private highlights This is public so that we can remove
* the highlights when the editorKit is unregistered. SimpleMarker can be
* null, in which case all instances of our Markers are removed.
*
* @param component the text component whose markers are to be removed
* @param marker the SimpleMarker to remove
*/
@@ -152,7 +152,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
SyntaxDocument sDoc = ActionUtils.getSyntaxDocument(decompiledEditor);
if (sDoc != null) {
Token t = sDoc.getTokenAt(pos+1);
Token t = sDoc.getTokenAt(pos + 1);
String ident = null;
//It should be identifier or obfuscated identifier
if (t != null && (t.type == TokenType.IDENTIFIER || t.type == TokenType.REGEX)) {
@@ -167,11 +167,11 @@ public class TagTree extends JTree implements ActionListener {
public class TagTreeCellRenderer extends DefaultTreeCellRenderer {
private Font plainFont;
private Font boldFont;
private Map<TreeNodeType, Icon> icons;
private final Map<TreeNodeType, Icon> icons;
public TagTreeCellRenderer() {
setUI(new BasicLabelUI());
setOpaque(false);
@@ -187,7 +187,7 @@ public class TagTree extends JTree implements ActionListener {
}
}
}
@Override
public Component getTreeCellRendererComponent(
JTree tree,
@@ -204,7 +204,7 @@ public class TagTree extends JTree implements ActionListener {
hasFocus);
TreeItem val = (TreeItem) value;
TreeNodeType type = getTreeNodeType(val);
if (type == TreeNodeType.FOLDER && expanded) {
type = TreeNodeType.FOLDER_OPEN;
}