diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index b1dbd4971..5aa048815 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -1099,7 +1099,7 @@ public final class SWF implements SWFContainerItem, Timelined { } } - getASMs(true); // Add scriptNames to ASMs + getASMs(true); // Add scriptNames to ASMs } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index a6a7ecefe..85e508837 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -974,7 +974,17 @@ public abstract class Action implements GraphSourceItem { ip++; continue; } - if (stack.isEmpty()) { + + //FunctionActionItem after DefineFunction(/2) are left on the stack. For linestart offsets we consider this kind of stack empty. + boolean isStackEmpty = true; + for (int i = 0; i < stack.size(); i++) { + if ((!(stack.get(i) instanceof FunctionActionItem))) { + isStackEmpty = false; + break; + } + } + + if (isStackEmpty) { localData.lineStartAction = action; fi.setVal(action); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java index a8ea89d42..1094d90f3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java @@ -30,7 +30,7 @@ import java.util.List; public class TraceActionItem extends ActionItem { public TraceActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem value) { - super(instruction, lineStartIns, PRECEDENCE_PRIMARY, value); + super(instruction, lineStartIns, PRECEDENCE_PRIMARY, value); } @Override diff --git a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java index 77239fb96..5e58fffc5 100644 --- a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java +++ b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java @@ -39,7 +39,9 @@ import com.jpexs.debugger.flash.messages.in.InVersion; import com.jpexs.debugger.flash.messages.out.OutGetBreakReason; import com.jpexs.debugger.flash.messages.out.OutGetSwd; import com.jpexs.debugger.flash.messages.out.OutGetSwf; +import com.jpexs.debugger.flash.messages.out.OutPlay; import com.jpexs.debugger.flash.messages.out.OutProcessedTag; +import com.jpexs.debugger.flash.messages.out.OutRewind; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.graph.DottedChain; import java.io.IOException; @@ -86,10 +88,16 @@ public class DebuggerHandler implements DebugConnectionListener { private String breakScriptName = null; public int getBreakIp() { + if (!isPaused()) { + return -1; + } return breakIp; } public String getBreakScriptName() { + if (!isPaused()) { + return "-"; + } return breakScriptName; } @@ -532,18 +540,18 @@ public class DebuggerHandler implements DebugConnectionListener { Logger.getLogger(DebuggerHandler.class.getName()).log(Level.FINE, "paused"); } - String newBreakScriptName = "unknown"; - if (modulePaths.containsKey(message.file)) { - newBreakScriptName = modulePaths.get(message.file); - } else { - Logger.getLogger(DebuggerCommands.class.getName()).log(Level.SEVERE, "Invalid file: " + message.file); - return; - } - try { breakInfo = con.getMessage(InBreakAtExt.class); breakReason = con.sendMessage(new OutGetBreakReason(con), InBreakReason.class); + String newBreakScriptName = "unknown"; + if (modulePaths.containsKey(message.file)) { + newBreakScriptName = modulePaths.get(message.file); + } else if (breakReason.reason != InBreakReason.REASON_SCRIPT_LOADED) { + Logger.getLogger(DebuggerCommands.class.getName()).log(Level.SEVERE, "Invalid file: " + message.file); + return; + } + final String[] reasonNames = new String[]{"unknown", "breakpoint", "watch", "fault", "stopRequest", "step", "halt", "scriptLoaded"}; String reason = breakReason.reason < reasonNames.length ? reasonNames[breakReason.reason] : reasonNames[0]; @@ -593,6 +601,8 @@ public class DebuggerHandler implements DebugConnectionListener { if (!isAS3) { Logger.getLogger(DebuggerHandler.class.getName()).log(Level.FINER, "End of connect - sending continue"); + con.writeMessage(new OutRewind(con)); + con.writeMessage(new OutPlay(con)); commands.sendContinue(); } diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 11235ab41..ed71890b2 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.ApplicationInfo; import com.jpexs.decompiler.flash.EventListener; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFBundle; +import com.jpexs.decompiler.flash.SWFCompression; import com.jpexs.decompiler.flash.SWFSourceInfo; import com.jpexs.decompiler.flash.SearchMode; import com.jpexs.decompiler.flash.SwfOpenException; @@ -179,7 +180,9 @@ public class Main { runProcess = null; } - mainFrame.getPanel().clearDebuggerColors(); + if (mainFrame != null && mainFrame.getPanel() != null) { + mainFrame.getPanel().clearDebuggerColors(); + } if (runProcessDebug) { Main.getDebugHandler().disconnect(); } @@ -310,6 +313,22 @@ public class Main { try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(tempFile))) { swf.saveTo(fos); } + + if (swf.isAS3() && Configuration.autoOpenLoadedSWFs.get()) { + SWF instrSWF = null; + try (FileInputStream fis = new FileInputStream(tempFile)) { + instrSWF = new SWF(fis, false, false); + } catch (InterruptedException ex) { + Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); + } + if (instrSWF != null) { + DebuggerTools.injectDebugLoader(instrSWF); + instrSWF.enableDebugging(true, new File(".")); + try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(tempFile))) { + instrSWF.saveTo(fos); + } + } + } } catch (IOException ex) { return; @@ -351,26 +370,34 @@ public class Main { try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(fTempFile))) { swf.saveTo(fos); } - //Inject Loader SWF instrSWF = null; try (FileInputStream fis = new FileInputStream(fTempFile)) { instrSWF = new SWF(fis, false, false); - } catch (InterruptedException ex) { - Logger.getLogger(MainFrameMenu.class - .getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); } if (instrSWF != null) { - if (instrSWF.isAS3()) { - instrSWF.enableDebugging(true, new File(".")); - } else { - instrSWF.enableDebugging(false, new File(".")); - File swdFile = new File(fTempFile.getAbsolutePath().replace(".swf", ".swd")); - instrSWF.generateSwdFile(swdFile, getPackBreakPoints(true)); + if (instrSWF.isAS3() && Configuration.autoOpenLoadedSWFs.get()) { + DebuggerTools.injectDebugLoader(instrSWF); } + instrSWF.enableDebugging(true, new File(".")); try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(fTempFile))) { instrSWF.saveTo(fos); } + if (!instrSWF.isAS3()) { + //Read again, because line file offsets changed with adding debug tags + //TODO: handle somehow without rereading? + instrSWF = null; + try (FileInputStream fis = new FileInputStream(fTempFile)) { + instrSWF = new SWF(fis, false, false); + } catch (InterruptedException ex) { + Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); + } + if (instrSWF != null) { + File swdFile = new File(fTempFile.getAbsolutePath().replace(".swf", ".swd")); + instrSWF.generateSwdFile(swdFile, getPackBreakPoints(true)); + } + } } return null; }