Skip to content

Commit 84d6ad8

Browse files
committed
Added: #1383 AS Debugger - debugging nested SWFs
1 parent c3389db commit 84d6ad8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1412
-195
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ All notable changes to this project will be documented in this file.
4646
- Optimized (faster) deleting items for large SWF trees
4747
- AS debugger - More varible flags
4848
- AS3 direct editation - edit files with native keyword
49+
- [#1383] AS Debugger - debugging nested SWFs (enable "Open loaded SWFs while playing")
4950

5051
### Fixed
5152
- Debugger - getting children of top level variables
@@ -3480,6 +3481,7 @@ Major version of SWF to XML export changed to 2.
34803481
[#1809]: https://www.free-decompiler.com/flash/issues/1809
34813482
[#873]: https://www.free-decompiler.com/flash/issues/873
34823483
[#1644]: https://www.free-decompiler.com/flash/issues/1644
3484+
[#1383]: https://www.free-decompiler.com/flash/issues/1383
34833485
[#2149]: https://www.free-decompiler.com/flash/issues/2149
34843486
[#2172]: https://www.free-decompiler.com/flash/issues/2172
34853487
[#2174]: https://www.free-decompiler.com/flash/issues/2174

lib/flashdebugger.jar

744 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.jpexs.decompiler.flash.debugger {
2+
import flash.events.Event;
3+
4+
public class DebugByteArrayLoadedEvent extends Event {
5+
6+
public DebugByteArrayLoadedEvent() {
7+
super("DebugByteArrayLoadedEvent");
8+
}
9+
}
10+
}

libsrc/debugswf/com/jpexs/decompiler/flash/debugger/DebugConnection.as

+21-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
private static var name:String;
1717
private static var failed:Boolean = false;
1818
private static var fillByteArrays = [];
19+
private static var fillByteArraysEvents = [];
1920
private static var lenBytes:Array = [
2021
-1, -1, -1, -1
2122
];
@@ -32,7 +33,8 @@
3233
public static const MSG_LOADER_BYTES = 2;
3334
public static const MSG_DUMP_BYTEARRAY = 3;
3435
public static const MSG_REQUEST_BYTEARRAY = 4;
35-
36+
public static const MSG_LOADER_URL_INFO = 5;
37+
public static const MSG_LOADER_MODIFY_BYTES = 6;
3638

3739
private static function sendQueue(){
3840
var qo = q;
@@ -125,7 +127,7 @@
125127

126128
private static function onSocketData(event:ProgressEvent):void {
127129
while (s.bytesAvailable > 0) {
128-
if (lenBytePos < 4) {
130+
if (lenBytePos < 4) {
129131
lenBytes[lenBytePos] = s.readUnsignedByte();
130132
lenBytePos++;
131133
if (lenBytePos == 4) {
@@ -136,9 +138,8 @@
136138
var readLen:int = s.bytesAvailable <= len ? s.bytesAvailable : len;
137139
s.readBytes(readBa, readBa.length, readLen);
138140
len -= readLen;
139-
140-
if (len == 0) {
141-
lenBytePos = 0;
141+
if (len == 0) {
142+
lenBytePos = 0;
142143
var ba:ByteArray = fillByteArrays.pop();
143144
var pos = ba.position;
144145
ba.position = 0;
@@ -149,6 +150,10 @@
149150
} else {
150151
ba.position = pos;
151152
}
153+
var onComplete = fillByteArraysEvents.pop();
154+
if (onComplete != null) {
155+
onComplete.call(onComplete);
156+
}
152157
}
153158
}
154159
}
@@ -163,6 +168,10 @@
163168
public static function writeLoaderBytes(data:ByteArray){
164169
writeMsg(data,MSG_LOADER_BYTES);
165170
}
171+
172+
public static function modifyLoaderBytesWithUrl(data:ByteArray, outputData:ByteArray, url:String, onComplete:Function){
173+
writeMsg({"inputData": data, "outputData": outputData, "url" : url, "onComplete" : onComplete},MSG_LOADER_MODIFY_BYTES);
174+
}
166175

167176
public static function writeCommaSeparatedToByteArray(s:String, ba:ByteArray) {
168177
var bytes:Array = s.split(",");
@@ -232,8 +241,14 @@
232241
writeBytes(msg);
233242
break;
234243
case MSG_REQUEST_BYTEARRAY:
235-
fillByteArrays.push(msg);
244+
fillByteArrays.push(msg);
236245
break;
246+
case MSG_LOADER_MODIFY_BYTES:
247+
writeString(msg["url"]);
248+
writeBytes(msg["inputData"]);
249+
fillByteArraysEvents.push(msg["onComplete"]);
250+
fillByteArrays.push(msg["outputData"]);
251+
break;
237252
}
238253
s.flush();
239254
}else{

libsrc/debugswf/com/jpexs/decompiler/flash/debugger/DebugLoader.as

+33-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,45 @@
44
import flash.net.URLRequest;
55
import flash.system.LoaderContext;
66
import flash.utils.ByteArray;
7+
import flash.net.URLLoader;
8+
import flash.net.URLLoaderDataFormat;
9+
import flash.net.URLRequest;
10+
import flash.events.Event;
711

8-
public class DebugLoader extends Loader {
9-
12+
public class DebugLoader extends Loader {
13+
14+
private var lastLoadedContext:LoaderContext = null;
15+
private var urlLoader:URLLoader = null;
16+
private var lastLoadedRequest:URLRequest = null;
17+
private var lastModifiedByteArray:ByteArray = null;
1018

1119
public override function load(request:URLRequest, context:LoaderContext = null):void {
12-
DebugConnection.writeLoaderURL(request.url);
13-
super.load(request,context);
20+
lastLoadedRequest = request;
21+
lastLoadedContext = context;
22+
23+
urlLoader = new URLLoader();
24+
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
25+
urlLoader.addEventListener(Event.COMPLETE, onURLLoaderComplete);
26+
urlLoader.load(request);
1427
}
28+
29+
private function onURLLoaderComplete(event:Event):void {
30+
var dataBytes:ByteArray = urlLoader.data as ByteArray;
31+
loadBytesInternal(dataBytes, lastLoadedContext, lastLoadedRequest.url);
32+
}
1533

34+
private function loadBytesInternal(bytes:ByteArray, context:LoaderContext = null, url:String = "") {
35+
lastModifiedByteArray = new ByteArray();
36+
lastLoadedContext = context;
37+
DebugConnection.modifyLoaderBytesWithUrl(bytes, lastModifiedByteArray, url, onModifiedDataLoaded);
38+
}
39+
40+
private function onModifiedDataLoaded() {
41+
super.loadBytes(lastModifiedByteArray, lastLoadedContext);
42+
}
43+
1644
public override function loadBytes(bytes:ByteArray, context:LoaderContext = null):void {
17-
DebugConnection.writeLoaderBytes(bytes);
18-
super.loadBytes(bytes,context);
45+
loadBytesInternal(bytes, context);
1946
}
2047

2148
public override function toString():String {

libsrc/debugswf/debug/DOMDocument.xml

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
</timelines>
1515
<PrinterSettings/>
1616
<publishHistory>
17+
<PublishItem publishSize="5725" publishTime="1722767505" publishDebug="true"/>
18+
<PublishItem publishSize="603" publishTime="1722767439" publishDebug="true"/>
19+
<PublishItem publishSize="597" publishTime="1722767379" publishDebug="true"/>
20+
<PublishItem publishSize="5809" publishTime="1722767145" publishDebug="true"/>
21+
<PublishItem publishSize="5782" publishTime="1722767021" publishDebug="true"/>
22+
<PublishItem publishSize="5735" publishTime="1722766846" publishDebug="true"/>
23+
<PublishItem publishSize="5724" publishTime="1722766620" publishDebug="true"/>
24+
<PublishItem publishSize="5722" publishTime="1722763327" publishDebug="true"/>
25+
<PublishItem publishSize="599" publishTime="1722763280" publishDebug="true"/>
26+
<PublishItem publishSize="597" publishTime="1722763257" publishDebug="true"/>
1727
<PublishItem publishSize="4021" publishTime="1700417069" publishDebug="true"/>
1828
<PublishItem publishSize="3974" publishTime="1700415286" publishDebug="true"/>
1929
<PublishItem publishSize="4206" publishTime="1700412219" publishDebug="true"/>
@@ -24,15 +34,5 @@
2434
<PublishItem publishSize="4175" publishTime="1700340276" publishDebug="true"/>
2535
<PublishItem publishSize="4162" publishTime="1700339789" publishDebug="true"/>
2636
<PublishItem publishSize="4121" publishTime="1700339614" publishDebug="true"/>
27-
<PublishItem publishSize="2956" publishTime="1700339539"/>
28-
<PublishItem publishSize="2952" publishTime="1700339469"/>
29-
<PublishItem publishSize="4122" publishTime="1700339049" publishDebug="true"/>
30-
<PublishItem publishSize="3019" publishTime="1700338890"/>
31-
<PublishItem publishSize="2950" publishTime="1700338133"/>
32-
<PublishItem publishSize="2943" publishTime="1700337952"/>
33-
<PublishItem publishSize="1631" publishTime="1414397031"/>
34-
<PublishItem publishSize="1625" publishTime="1414396836"/>
35-
<PublishItem publishSize="1620" publishTime="1414395905"/>
36-
<PublishItem publishSize="560" publishTime="1414395873"/>
3737
</publishHistory>
3838
</DOMDocument>

libsrc/debugswf/debug/META-INF/metadata.xml

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
xmlns:xmp="http://ns.adobe.com/xap/1.0/">
66
<xmp:CreatorTool>Adobe Flash Professional CS6 - build 537</xmp:CreatorTool>
77
<xmp:CreateDate>2014-10-26T15:59:21+01:00</xmp:CreateDate>
8-
<xmp:MetadataDate>2023-11-19T08:32:38-08:00</xmp:MetadataDate>
9-
<xmp:ModifyDate>2023-11-19T08:32:38-08:00</xmp:ModifyDate>
8+
<xmp:MetadataDate>2024-08-04T02:20:55-07:00</xmp:MetadataDate>
9+
<xmp:ModifyDate>2024-08-04T02:20:55-07:00</xmp:ModifyDate>
1010
</rdf:Description>
1111
<rdf:Description rdf:about=""
1212
xmlns:dc="http://purl.org/dc/elements/1.1/">
@@ -15,7 +15,7 @@
1515
<rdf:Description rdf:about=""
1616
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
1717
xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#">
18-
<xmpMM:InstanceID>xmp.iid:D4132A45B886EE11B43B9B2E6D6D7C97</xmpMM:InstanceID>
18+
<xmpMM:InstanceID>xmp.iid:C1FFFAAC2852EF1194768CEE75293134</xmpMM:InstanceID>
1919
<xmpMM:DocumentID>xmp.did:1476A545885CE411B13FACEEFCD7D43C</xmpMM:DocumentID>
2020
<xmpMM:OriginalDocumentID>xmp.did:1476A545885CE411B13FACEEFCD7D43C</xmpMM:OriginalDocumentID>
2121
<xmpMM:History>
@@ -56,6 +56,12 @@
5656
<stEvt:when>2014-10-26T15:59:21+01:00</stEvt:when>
5757
<stEvt:softwareAgent>Adobe Flash Professional CS6 - build 481</stEvt:softwareAgent>
5858
</rdf:li>
59+
<rdf:li rdf:parseType="Resource">
60+
<stEvt:action>created</stEvt:action>
61+
<stEvt:instanceID>xmp.iid:C1FFFAAC2852EF1194768CEE75293134</stEvt:instanceID>
62+
<stEvt:when>2014-10-26T15:59:21+01:00</stEvt:when>
63+
<stEvt:softwareAgent>Adobe Flash Professional CS6 - build 481</stEvt:softwareAgent>
64+
</rdf:li>
5965
</rdf:Seq>
6066
</xmpMM:History>
6167
</rdf:Description>

libsrc/debugswf/debug/PublishSettings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<PackagePaths></PackagePaths>
8080
<AS3PackagePaths>.</AS3PackagePaths>
8181
<AS3ConfigConst>CONFIG::FLASH_AUTHORING=&quot;true&quot;;</AS3ConfigConst>
82-
<DebuggingPermitted>1</DebuggingPermitted>
82+
<DebuggingPermitted>0</DebuggingPermitted>
8383
<DebuggingPassword></DebuggingPassword>
8484
<CompressMovie>1</CompressMovie>
8585
<CompressionType>0</CompressionType>
0 Bytes
Binary file not shown.

libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java

+26-6
Original file line numberDiff line numberDiff line change
@@ -3990,6 +3990,9 @@ public void itemDeobfuscated() {
39903990
* P-code)
39913991
*/
39923992
public void injectAS3PcodeDebugInfo() throws InterruptedException {
3993+
injectAS3PcodeDebugInfo("main");
3994+
}
3995+
public void injectAS3PcodeDebugInfo(String swfHash) throws InterruptedException {
39933996
List<ScriptPack> packs = getAS3Packs();
39943997
int i = 0;
39953998
for (ScriptPack s : packs) {
@@ -4000,7 +4003,7 @@ public void injectAS3PcodeDebugInfo() throws InterruptedException {
40004003
informListeners("inject_debuginfo", "" + i + "/" + packs.size() + ": " + s.getPath());
40014004
int abcIndex = s.allABCs.indexOf(s.abc);
40024005
if (s.isSimple) {
4003-
s.injectPCodeDebugInfo(abcIndex);
4006+
s.injectPCodeDebugInfo(abcIndex, swfHash);
40044007
}
40054008
}
40064009
}
@@ -4011,6 +4014,10 @@ public void injectAS3PcodeDebugInfo() throws InterruptedException {
40114014
* @param decompileDir Directory to set file information paths
40124015
*/
40134016
public void injectAS3DebugInfo(File decompileDir) throws InterruptedException {
4017+
injectAS3DebugInfo(decompileDir, "main");
4018+
}
4019+
4020+
public void injectAS3DebugInfo(File decompileDir, String swfHash) throws InterruptedException {
40144021
List<ScriptPack> packs = getAS3Packs();
40154022
int i = 0;
40164023
for (ScriptPack s : packs) {
@@ -4021,7 +4028,7 @@ public void injectAS3DebugInfo(File decompileDir) throws InterruptedException {
40214028
informListeners("inject_debuginfo", "" + i + "/" + packs.size() + ": " + s.getPath());
40224029
if (s.isSimple) {
40234030
try {
4024-
s.injectDebugInfo(decompileDir);
4031+
s.injectDebugInfo(decompileDir, swfHash);
40254032
} catch (Throwable t) {
40264033
Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Errorr injecting debug info", t);
40274034
}
@@ -4072,12 +4079,17 @@ public void enableDebugging(boolean injectAS3Code, File decompileDir, boolean te
40724079
* @param pcodeLevel inject Pcode lines instead of decompiled lines
40734080
*/
40744081
public void enableDebugging(boolean injectAS3Code, File decompileDir, boolean telemetry, boolean pcodeLevel) throws InterruptedException {
4082+
enableDebugging(injectAS3Code, decompileDir, telemetry, pcodeLevel, "main");
4083+
}
4084+
4085+
public void enableDebugging(boolean injectAS3Code, File decompileDir, boolean telemetry, boolean pcodeLevel, String swfHash) throws InterruptedException {
4086+
40754087

40764088
if (injectAS3Code) {
40774089
if (pcodeLevel) {
4078-
injectAS3PcodeDebugInfo();
4090+
injectAS3PcodeDebugInfo(swfHash);
40794091
} else {
4080-
injectAS3DebugInfo(decompileDir);
4092+
injectAS3DebugInfo(decompileDir, swfHash);
40814093
}
40824094
}
40834095

@@ -4156,6 +4168,10 @@ public DebugIDTag getOrAddDebugId() {
41564168
}
41574169

41584170
public boolean generatePCodeSwdFile(File file, Map<String, Set<Integer>> breakpoints) throws IOException, InterruptedException {
4171+
return generatePCodeSwdFile(file, breakpoints, "main");
4172+
}
4173+
4174+
public boolean generatePCodeSwdFile(File file, Map<String, Set<Integer>> breakpoints, String swfHash) throws IOException, InterruptedException {
41594175
DebugIDTag dit = getDebugId();
41604176
if (dit == null) {
41614177
return false;
@@ -4180,7 +4196,7 @@ public boolean generatePCodeSwdFile(File file, Map<String, Set<Integer>> breakpo
41804196
}
41814197
informListeners("generate_swd", name);
41824198
moduleId++;
4183-
String sname = "#PCODE " + name;
4199+
String sname = swfHash + ":" + "#PCODE " + name;
41844200
int bitmap = SWD.bitmapAction;
41854201
items.add(new SWD.DebugScript(moduleId, bitmap, sname, ""));
41864202

@@ -4237,6 +4253,10 @@ public boolean generatePCodeSwdFile(File file, Map<String, Set<Integer>> breakpo
42374253
}
42384254

42394255
public boolean generateSwdFile(File file, Map<String, Set<Integer>> breakpoints) throws IOException {
4256+
return generateSwdFile(file, breakpoints, "main");
4257+
}
4258+
4259+
public boolean generateSwdFile(File file, Map<String, Set<Integer>> breakpoints, String swfHash) throws IOException {
42404260
DebugIDTag dit = getDebugId();
42414261
if (dit == null) {
42424262
return false;
@@ -4299,7 +4319,7 @@ public boolean generateSwdFile(File file, Map<String, Set<Integer>> breakpoints)
42994319
}
43004320

43014321
//final String NONAME = "[No instance name assigned]";
4302-
String sname = name;
4322+
String sname = swfHash + ":" + name;
43034323
int bitmap = SWD.bitmapAction;
43044324
/* Matcher m;
43054325
int bitmap = SWD.bitmapAction;

libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ public Label(long addr) {
396396
* http://securityevaluators.com/knowledge/flash/
397397
*/
398398
public void injectDebugInfo(File directoryPath) {
399+
injectDebugInfo(directoryPath, "main");
400+
}
401+
402+
public void injectDebugInfo(File directoryPath, String swfHash) {
399403
Map<Integer, Map<Integer, Integer>> bodyToPosToLine = new HashMap<>();
400404
Map<Integer, Map<Integer, Integer>> bodyLineToPos = new HashMap<>();
401405
Map<Integer, Map<Integer, String>> bodyToRegToName = new HashMap<>();
@@ -517,6 +521,7 @@ public void injectDebugInfo(File directoryPath) {
517521
String cls = path.className;
518522
String filename = new File(directoryPath, path.packageStr.toFilePath()).getPath().replace(";", "{{semicolon}}")
519523
+ ";"
524+
+ swfHash + ":"
520525
+ pkg.replace(".", File.separator).replace(";", "{{semicolon}}")
521526
+ ";"
522527
+ cls.replace(";", "{{semicolon}}")
@@ -689,7 +694,7 @@ public void injectDebugInfo(File directoryPath) {
689694
((Tag) abc.parentTag).setModified(true);
690695
}
691696

692-
public void injectPCodeDebugInfo(int abcIndex) {
697+
public void injectPCodeDebugInfo(int abcIndex, String swfHash) {
693698

694699
Map<Integer, String> bodyToIdentifier = new HashMap<>();
695700

@@ -765,7 +770,7 @@ public void injectPCodeDebugInfo(int abcIndex) {
765770
i -= 2;
766771
}
767772
}
768-
String filename = "#PCODE " + bodyName + ";" + pkg.replace(".", File.separator) + ";" + cls + ".as";
773+
String filename = swfHash + ":" + "#PCODE " + bodyName + ";" + pkg.replace(".", File.separator) + ";" + cls + ".as";
769774

770775
b.insertInstruction(0, new AVM2Instruction(0, AVM2Instructions.DebugFile, new int[]{abc.constants.getStringId(filename, true)}));
771776
b.setModified();
15.8 KB
Binary file not shown.
571 Bytes
Binary file not shown.
3.65 KB
Binary file not shown.

0 commit comments

Comments
 (0)