more AS2 deobfuscation fixes & cleanup

This commit is contained in:
2014-09-21 00:07:04 +02:00
parent 60f7e5e36f
commit 824f40c803
40 changed files with 279 additions and 261 deletions
@@ -16,12 +16,7 @@
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.hexview.HexView;
import com.jpexs.decompiler.flash.gui.treenodes.SWFNode;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.treenodes.TagNode;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.awt.BorderLayout;
@@ -32,8 +27,6 @@ import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
@@ -51,7 +44,7 @@ public final class BinaryPanel extends JPanel implements ComponentListener {
private byte[] data;
private JPanel swfInsidePanel;
private TagNode node = null;
private MainPanel mainPanel;
private final MainPanel mainPanel;
public BinaryPanel(final MainPanel mainPanel) {
super(new BorderLayout());
@@ -65,7 +58,7 @@ public final class BinaryPanel extends JPanel implements ComponentListener {
add(bottomPanel, BorderLayout.SOUTH);
addComponentListener(this);
swfInsidePanel = new JPanel();
swfInsidePanel.setBackground(new Color(253,205,137));
swfInsidePanel.setBackground(new Color(253, 205, 137));
swfInsidePanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
swfInsidePanel.add(new JLabel(AppStrings.translate("binarydata.swfInside")));
swfInsidePanel.setFocusable(true);
@@ -90,7 +83,7 @@ public final class BinaryPanel extends JPanel implements ComponentListener {
hexEditor.setData(data, null, null);
if (node != null) {
if(node.subNodes.isEmpty() && data.length>8){
if (node.subNodes.isEmpty() && data.length > 8) {
try {
String signature = new String(data, 0, 3, Utf8Helper.charset);
if (Arrays.asList(
@@ -101,11 +94,11 @@ public final class BinaryPanel extends JPanel implements ComponentListener {
"CFX" //Compressed ScaleForm GFx
).contains(signature)) {
swfInsidePanel.setVisible(true);
}
}
} catch (Exception ex) {
swfInsidePanel.setVisible(false);
}
}else{
} else {
swfInsidePanel.setVisible(false);
}
} else {
@@ -64,6 +64,8 @@ public class LoadingDialog extends AppDialog implements ImageObserver {
/**
* Constructor
*
* @param owner
*/
public LoadingDialog(Window owner) {
super(owner);
+3 -4
View File
@@ -78,7 +78,6 @@ import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
@@ -184,7 +183,7 @@ public class Main {
}
public static void startWork(final String name, final int percent, final CancellableWorker worker) {
working = true;
working = true;
View.execInEventDispatchLater(new Runnable() {
@Override
public void run() {
@@ -508,8 +507,8 @@ public class Main {
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
if (Main.loadingDialog == null || Main.loadingDialog.getOwner() == null) {
Main.loadingDialog = new LoadingDialog(mainFrame==null?null:mainFrame.getWindow());
if (Main.loadingDialog == null || Main.loadingDialog.getOwner() == null) {
Main.loadingDialog = new LoadingDialog(mainFrame == null ? null : mainFrame.getWindow());
}
}
});
@@ -2224,37 +2224,37 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
public void loadFromBinaryTag(final TagNode node) {
if (Main.loadingDialog == null || Main.loadingDialog.getOwner() == null) {
Main.loadingDialog = new LoadingDialog(mainFrame==null?null:mainFrame.getWindow());
if (Main.loadingDialog == null || Main.loadingDialog.getOwner() == null) {
Main.loadingDialog = new LoadingDialog(mainFrame == null ? null : mainFrame.getWindow());
}
Main.loadingDialog.setVisible(true);
Main.startWork(AppStrings.translate("work.reading.swf") + "...");
new Thread(){
Main.startWork(AppStrings.translate("work.reading.swf") + "...");
new Thread() {
@Override
public void run() {
try {
SWF bswf = new SWF(new ByteArrayInputStream(((DefineBinaryDataTag)node.getItem()).binaryData),new ProgressListener() {
public void run() {
try {
SWF bswf = new SWF(new ByteArrayInputStream(((DefineBinaryDataTag) node.getItem()).binaryData), new ProgressListener() {
@Override
public void progress(int p) {
Main.loadingDialog.setPercent(p);
Main.loadingDialog.setPercent(p);
}
}, Configuration.parallelSpeedUp.get());
bswf.fileTitle = "(SWF Data)";
SWFNode snode = ((TagTreeModel) tagTree.getModel()).createSwfNode(bswf);
snode.binaryData = (DefineBinaryDataTag) node.getItem();
node.subNodes.add(snode);
node.subNodes.add(snode);
} catch (IOException | InterruptedException ex) {
//ignore
}
Main.loadingDialog.setVisible(false);
Main.stopWork();
}
}.start();
}
public void reload(boolean forceReload) {
@@ -425,14 +425,14 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
public void clear() {
imagePanel.stop();
binaryPanel.setBinaryData(null,null);
binaryPanel.setBinaryData(null, null);
genericTagPanel.clear();
fontPanel.clear();
}
public void showBinaryPanel(byte[] data,TagNode node) {
public void showBinaryPanel(byte[] data, TagNode node) {
showCardLeft(BINARY_TAG_CARD);
binaryPanel.setBinaryData(data,node);
binaryPanel.setBinaryData(data, node);
parametersPanel.setVisible(false);
}
@@ -72,9 +72,9 @@ public class SoundTagPlayer implements MediaDisplay {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
List<byte[]> soundData = tag.getRawSoundData();
SWF swf = ((Tag) tag).getSwf();
List<SWFInputStream> siss=new ArrayList<>();
for(byte[] data:soundData){
siss.add(new SWFInputStream(swf,data));
List<SWFInputStream> siss = new ArrayList<>();
for (byte[] data : soundData) {
siss.add(new SWFInputStream(swf, data));
}
tag.getSoundFormat().createWav(siss, baos);
player = new SoundPlayer(new ByteArrayInputStream(baos.toByteArray()));
@@ -17,7 +17,6 @@
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel;
import com.jpexs.decompiler.flash.gui.abc.treenodes.ClassesListNode;
import com.jpexs.decompiler.flash.gui.abc.treenodes.TreeElement;
@@ -26,7 +25,6 @@ import com.jpexs.decompiler.flash.gui.treenodes.SWFContainerNode;
import com.jpexs.decompiler.flash.gui.treenodes.SWFNode;
import com.jpexs.decompiler.flash.gui.treenodes.StringNode;
import com.jpexs.decompiler.flash.gui.treenodes.TagTreeRoot;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineSpriteTag;
import com.jpexs.decompiler.flash.tags.ShowFrameTag;
import com.jpexs.decompiler.flash.tags.SoundStreamBlockTag;
@@ -44,14 +42,10 @@ import com.jpexs.decompiler.flash.treenodes.FrameNode;
import com.jpexs.decompiler.flash.treenodes.HeaderNode;
import com.jpexs.decompiler.flash.treenodes.TagNode;
import com.jpexs.decompiler.flash.treenodes.TreeNode;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
@@ -106,17 +100,16 @@ public class TagTreeModel implements TreeModel {
return mainFrame.translate(key);
}
private List<TreeNode> getSoundStreams(DefineSpriteTag sprite){
List<TreeNode> ret=new ArrayList<>();
for(Tag t:sprite.subTags){
if(t instanceof SoundStreamHeadTypeTag){
private List<TreeNode> getSoundStreams(DefineSpriteTag sprite) {
List<TreeNode> ret = new ArrayList<>();
for (Tag t : sprite.subTags) {
if (t instanceof SoundStreamHeadTypeTag) {
ret.add(new TagNode(t));
}
}
return ret;
}
private List<TreeNode> createTagList(List<Tag> list, SWF swf, SWFNode swfNode, ClassesListTreeModel classTreeModel) {
boolean hasAbc = swf.abcList != null && !swf.abcList.isEmpty();
@@ -149,7 +142,7 @@ public class TagTreeModel implements TreeModel {
break;
case SPRITE:
sprites.add(new TagNode(t));
sounds.addAll(getSoundStreams((DefineSpriteTag)t));
sounds.addAll(getSoundStreams((DefineSpriteTag) t));
break;
case BUTTON:
buttons.add(new TagNode(t));
@@ -171,7 +164,7 @@ public class TagTreeModel implements TreeModel {
break;
case BINARY_DATA:
TagNode bt;
binaryData.add(bt = new TagNode(t));
binaryData.add(bt = new TagNode(t));
break;
default:
if (!actionScriptTags.contains(t) && t.getId() != ShowFrameTag.ID && !ShowFrameTag.isNestedTagType(t.getId())) {
@@ -51,7 +51,7 @@ public class TextPanel extends JPanel implements ActionListener {
super(new BorderLayout());
DefaultSyntaxKit.initKit();
this.mainPanel = mainPanel;
textSearchPanel = new SearchPanel<>(new FlowLayout(), mainPanel);
add(textSearchPanel, BorderLayout.NORTH);
@@ -122,7 +122,7 @@ public class NamespaceTableModel implements TableModel {
if (rowIndex == 0) {
return "-";
}
String val = abc.constants.getNamespace(rowIndex).getName(abc.constants,true);
String val = abc.constants.getNamespace(rowIndex).getName(abc.constants, true);
if (val == null) {
val = "-";
}
@@ -153,25 +153,25 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
SyntaxDocument sDoc = ActionUtils.getSyntaxDocument(decompiledEditor);
if (sDoc != null) {
Token t = sDoc.getTokenAt(pos);
String ident=null;
String ident = null;
//It should be identifier or obfuscated identifier
if (t != null && (t.type == TokenType.IDENTIFIER || t.type == TokenType.REGEX)) {
if (t != null && (t.type == TokenType.IDENTIFIER || t.type == TokenType.REGEX)) {
CharSequence tData = t.getText(sDoc);
ident=tData.toString();
ident = tData.toString();
//We need to get unescaped identifier, so we use our Lexer
ActionScriptLexer lex=new ActionScriptLexer(new StringReader(ident));
ActionScriptLexer lex = new ActionScriptLexer(new StringReader(ident));
try {
ParsedSymbol symb=lex.lex();
if(symb.type==SymbolType.IDENTIFIER){
ident = (String)symb.value;
}else{
ParsedSymbol symb = lex.lex();
if (symb.type == SymbolType.IDENTIFIER) {
ident = (String) symb.value;
} else {
ident = null;
}
} catch (IOException | ActionParseException ex) {
ident=null;
}
}
if(ident==null){
ident = null;
}
}
if (ident == null) {
Highlighting h = Highlighting.search(decompiledHilights, pos);
if (h != null) {
List<Action> list = lastCode;
@@ -206,11 +206,11 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
}
}
}else{
} else {
return ident;
}
}
return null;
return null;
}
private CachedScript getCached(ASMSource pack) {
@@ -32,8 +32,6 @@ import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;