Debugger stub - TODO

This commit is contained in:
Jindra Petřík
2015-11-15 16:09:11 +01:00
parent 88ce1ed405
commit 668e1e2f14
11 changed files with 204 additions and 12 deletions
@@ -2802,7 +2802,7 @@ public class CommandLineArgumentParser {
FileInputStream fis = new FileInputStream(file);
SWF swf = new SWF(fis, Configuration.parallelSpeedUp.get());
fis.close();
swf.enableDebugging(injectas3);
swf.enableDebugging(injectas3, new File(outfile).getParentFile());
FileOutputStream fos = new FileOutputStream(outfile);
swf.saveTo(fos);
fos.close();
@@ -0,0 +1,104 @@
/*
* Copyright (C) 2015 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.gui;
import com.jpexs.debugger.flash.DebugConnectionListener;
import com.jpexs.debugger.flash.DebugMessageListener;
import com.jpexs.debugger.flash.Debugger;
import com.jpexs.debugger.flash.DebuggerCommands;
import com.jpexs.debugger.flash.DebuggerConnection;
import com.jpexs.debugger.flash.messages.in.InAskBreakpoints;
import com.jpexs.debugger.flash.messages.in.InBreakAt;
import com.jpexs.debugger.flash.messages.in.InNumScript;
import com.jpexs.debugger.flash.messages.in.InScript;
import com.jpexs.debugger.flash.messages.in.InSwfInfo;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.graph.DottedChain;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Jindra
*/
public class DebuggerHandler implements DebugConnectionListener {
@Override
public void connected(DebuggerConnection con) {
Level level = Level.FINER;
Logger rootLog = Logger.getLogger(Debugger.class.getName());
rootLog.setLevel(level);
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(level);
rootLog.addHandler(ch);
//rootLog.getHandlers()[0].setLevel(level);
final DebuggerCommands dc = new DebuggerCommands(con);
dc.stopWarning();
dc.setStopOnFault();
dc.setEnumerateOverride();
dc.setNotifyFailure();
dc.setInvokeSetters();
dc.setSwfLoadNotify();
dc.setGetterTimeout(1500);
dc.setSetterTimeout(5000);
dc.squelch(true);
List<InSwfInfo.SwfInfo> swfs = dc.getSwfInfo(1);
int numScript = con.getMessage(InNumScript.class).num;
final Map<Integer, String> moduleNames = new HashMap<>();
for (int i = 0; i < numScript; i++) {
InScript sc = con.getMessage(InScript.class);
System.out.println("" + sc.module + ":" + sc.name);
moduleNames.put(sc.module, sc.name);
}
final Map<Integer, ClassPath> modulePaths = new HashMap<>();
for (int mname : moduleNames.keySet()) {
String name = moduleNames.get(mname);
String[] parts = name.split(";");
if (parts.length == 3) {
String clsName = parts[2].replace(".as", "");
String pkg = parts[1];
modulePaths.put(mname, new ClassPath(DottedChain.parse(pkg), clsName));
}
}
con.getMessage(InAskBreakpoints.class);
//dc.addBreakPoint(15, 14);
dc.addBreakPoint(9, 26);
con.addMessageListener(new DebugMessageListener<InBreakAt>() {
@Override
public void message(InBreakAt message) {
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.WARNING, "break at {0}:{1}", new Object[]{moduleNames.get(message.file), message.line});
String cls = modulePaths.get(message.file).toString();
Main.getMainFrame().getPanel().debuggerBreakAt(Main.getMainFrame().getPanel().getCurrentSwf(), cls, message.line);
//dc.sendContinue();
}
});
dc.sendContinue();
}
}
+30 -1
View File
@@ -16,6 +16,16 @@
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.debugger.flash.DebugConnectionListener;
import com.jpexs.debugger.flash.DebugMessageListener;
import com.jpexs.debugger.flash.Debugger;
import com.jpexs.debugger.flash.DebuggerCommands;
import com.jpexs.debugger.flash.DebuggerConnection;
import com.jpexs.debugger.flash.messages.in.InAskBreakpoints;
import com.jpexs.debugger.flash.messages.in.InBreakAt;
import com.jpexs.debugger.flash.messages.in.InNumScript;
import com.jpexs.debugger.flash.messages.in.InScript;
import com.jpexs.debugger.flash.messages.in.InSwfInfo;
import com.jpexs.decompiler.flash.ApplicationInfo;
import com.jpexs.decompiler.flash.EventListener;
import com.jpexs.decompiler.flash.SWF;
@@ -79,8 +89,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
@@ -137,6 +149,8 @@ public class Main {
public static boolean shouldCloseWhenClosingLoadingDialog;
private static Debugger flashDebugger;
public static void ensureMainFrame() {
if (mainFrame == null) {
synchronized (Main.class) {
@@ -1001,6 +1015,22 @@ public class Main {
public void onFinish(String clientId) {
}
});
try {
/*Level level = Level.FINE;
Logger rootLog = Logger.getLogger("");
rootLog.setLevel(level);
rootLog.getHandlers()[0].setLevel(level);
*/
flashDebugger = new Debugger();
flashDebugger.addConnectionListener(new DebuggerHandler());
flashDebugger.start();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void showModeFrame() {
@@ -1203,7 +1233,6 @@ public class Main {
* @throws IOException On error
*/
public static void main(String[] args) throws IOException {
clearTemp();
try {
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFBundle;
import com.jpexs.decompiler.flash.SWFSourceInfo;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.RenameType;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
@@ -1526,6 +1527,32 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
}
public void gotoClassLine(SWF swf, String cls, int line) {
gotoClass(swf, cls);
if (abcPanel != null) {
abcPanel.decompiledTextArea.selectLine(line);
}
}
public void debuggerBreakAt(SWF swf, String cls, int line) {
gotoClassLine(swf, cls, line);
if (abcPanel != null) {
abcPanel.decompiledTextArea.setLineColor(line, Color.green);
}
}
public void gotoClass(SWF swf, String cls) {
if (swf == null) {
return;
}
List<ABCContainerTag> abcList = swf.getAbcList();
if (!abcList.isEmpty()) {
ABCPanel abcPanel = getABCPanel();
abcPanel.setAbc(abcList.get(0).getABC());
abcPanel.hilightScript(swf, cls);
}
}
public void gotoDocumentClass(SWF swf) {
if (swf == null) {
return;
@@ -32,6 +32,8 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.plaf.TextUI;
@@ -65,6 +67,15 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
private LinkHandler linkHandler = this;
private Map<Integer, Color> lineColors = new HashMap<>();
public void setLineColor(int line, Color color) {
lineColors.remove(line);
if (color != null) {
lineColors.put(line, color);
}
}
public int getLine() {
return lastLine;
}
@@ -358,10 +369,11 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
public void paint(Graphics g) {
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
FontMetrics fontMetrics = g.getFontMetrics();
int lh = fontMetrics.getHeight();
int d = fontMetrics.getDescent();
if (lastLine > 0) {
FontMetrics fontMetrics = g.getFontMetrics();
int lh = fontMetrics.getHeight();
int d = fontMetrics.getDescent();
if (error) {
g.setColor(new Color(255, 200, 200));
} else {
@@ -369,6 +381,10 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
}
g.fillRect(0, d + lh * lastLine - 1, getWidth(), lh);
}
for (int line : lineColors.keySet()) {
g.setColor(lineColors.get(line));
g.fillRect(0, d + lh * line - 1, getWidth(), lh);
}
super.paint(g);
}
}