Added: #1383 AS Debugger - debugging nested SWFs

This commit is contained in:
Jindra Petřík
2024-08-04 22:26:00 +02:00
parent c3389dbfd1
commit 84d6ad8591
45 changed files with 1409 additions and 192 deletions

View File

@@ -3990,6 +3990,9 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
* P-code)
*/
public void injectAS3PcodeDebugInfo() throws InterruptedException {
injectAS3PcodeDebugInfo("main");
}
public void injectAS3PcodeDebugInfo(String swfHash) throws InterruptedException {
List<ScriptPack> packs = getAS3Packs();
int i = 0;
for (ScriptPack s : packs) {
@@ -4000,7 +4003,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
informListeners("inject_debuginfo", "" + i + "/" + packs.size() + ": " + s.getPath());
int abcIndex = s.allABCs.indexOf(s.abc);
if (s.isSimple) {
s.injectPCodeDebugInfo(abcIndex);
s.injectPCodeDebugInfo(abcIndex, swfHash);
}
}
}
@@ -4011,6 +4014,10 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
* @param decompileDir Directory to set file information paths
*/
public void injectAS3DebugInfo(File decompileDir) throws InterruptedException {
injectAS3DebugInfo(decompileDir, "main");
}
public void injectAS3DebugInfo(File decompileDir, String swfHash) throws InterruptedException {
List<ScriptPack> packs = getAS3Packs();
int i = 0;
for (ScriptPack s : packs) {
@@ -4021,7 +4028,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
informListeners("inject_debuginfo", "" + i + "/" + packs.size() + ": " + s.getPath());
if (s.isSimple) {
try {
s.injectDebugInfo(decompileDir);
s.injectDebugInfo(decompileDir, swfHash);
} catch (Throwable t) {
Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Errorr injecting debug info", t);
}
@@ -4072,12 +4079,17 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
* @param pcodeLevel inject Pcode lines instead of decompiled lines
*/
public void enableDebugging(boolean injectAS3Code, File decompileDir, boolean telemetry, boolean pcodeLevel) throws InterruptedException {
enableDebugging(injectAS3Code, decompileDir, telemetry, pcodeLevel, "main");
}
public void enableDebugging(boolean injectAS3Code, File decompileDir, boolean telemetry, boolean pcodeLevel, String swfHash) throws InterruptedException {
if (injectAS3Code) {
if (pcodeLevel) {
injectAS3PcodeDebugInfo();
injectAS3PcodeDebugInfo(swfHash);
} else {
injectAS3DebugInfo(decompileDir);
injectAS3DebugInfo(decompileDir, swfHash);
}
}
@@ -4156,6 +4168,10 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
}
public boolean generatePCodeSwdFile(File file, Map<String, Set<Integer>> breakpoints) throws IOException, InterruptedException {
return generatePCodeSwdFile(file, breakpoints, "main");
}
public boolean generatePCodeSwdFile(File file, Map<String, Set<Integer>> breakpoints, String swfHash) throws IOException, InterruptedException {
DebugIDTag dit = getDebugId();
if (dit == null) {
return false;
@@ -4180,7 +4196,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
}
informListeners("generate_swd", name);
moduleId++;
String sname = "#PCODE " + name;
String sname = swfHash + ":" + "#PCODE " + name;
int bitmap = SWD.bitmapAction;
items.add(new SWD.DebugScript(moduleId, bitmap, sname, ""));
@@ -4237,6 +4253,10 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
}
public boolean generateSwdFile(File file, Map<String, Set<Integer>> breakpoints) throws IOException {
return generateSwdFile(file, breakpoints, "main");
}
public boolean generateSwdFile(File file, Map<String, Set<Integer>> breakpoints, String swfHash) throws IOException {
DebugIDTag dit = getDebugId();
if (dit == null) {
return false;
@@ -4299,7 +4319,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
}
//final String NONAME = "[No instance name assigned]";
String sname = name;
String sname = swfHash + ":" + name;
int bitmap = SWD.bitmapAction;
/* Matcher m;
int bitmap = SWD.bitmapAction;

View File

@@ -396,6 +396,10 @@ public class ScriptPack extends AS3ClassTreeItem {
* http://securityevaluators.com/knowledge/flash/
*/
public void injectDebugInfo(File directoryPath) {
injectDebugInfo(directoryPath, "main");
}
public void injectDebugInfo(File directoryPath, String swfHash) {
Map<Integer, Map<Integer, Integer>> bodyToPosToLine = new HashMap<>();
Map<Integer, Map<Integer, Integer>> bodyLineToPos = new HashMap<>();
Map<Integer, Map<Integer, String>> bodyToRegToName = new HashMap<>();
@@ -517,6 +521,7 @@ public class ScriptPack extends AS3ClassTreeItem {
String cls = path.className;
String filename = new File(directoryPath, path.packageStr.toFilePath()).getPath().replace(";", "{{semicolon}}")
+ ";"
+ swfHash + ":"
+ pkg.replace(".", File.separator).replace(";", "{{semicolon}}")
+ ";"
+ cls.replace(";", "{{semicolon}}")
@@ -689,7 +694,7 @@ public class ScriptPack extends AS3ClassTreeItem {
((Tag) abc.parentTag).setModified(true);
}
public void injectPCodeDebugInfo(int abcIndex) {
public void injectPCodeDebugInfo(int abcIndex, String swfHash) {
Map<Integer, String> bodyToIdentifier = new HashMap<>();
@@ -765,7 +770,7 @@ public class ScriptPack extends AS3ClassTreeItem {
i -= 2;
}
}
String filename = "#PCODE " + bodyName + ";" + pkg.replace(".", File.separator) + ";" + cls + ".as";
String filename = swfHash + ":" + "#PCODE " + bodyName + ";" + pkg.replace(".", File.separator) + ";" + cls + ".as";
b.insertInstruction(0, new AVM2Instruction(0, AVM2Instructions.DebugFile, new int[]{abc.constants.getStringId(filename, true)}));
b.setModified();