Added: #1383 AS Debugger - debugging nested SWFs

This commit is contained in:
Jindra Petřík
2024-08-05 11:17:25 +02:00
parent c3389dbfd1
commit 84d6ad8591
45 changed files with 1409 additions and 192 deletions
@@ -47,4 +47,18 @@ public class DebugAdapter implements DebugListener {
return null;
}
@Override
public void onLoaderURLInfo(String clientId, String url) {
}
@Override
public void onLoaderModifyBytes(String clientId, byte[] inputData, String url, DebugLoaderDataModified modifiedListener) {
modifiedListener.dataModified(inputData);
}
@Override
public boolean isModifyBytesSupported() {
return false;
}
}
@@ -25,6 +25,8 @@ public interface DebugListener {
public void onMessage(String clientId, String msg);
public void onLoaderURL(String clientId, String url);
public void onLoaderURLInfo(String clientId, String url);
public void onLoaderBytes(String clientId, byte[] data);
@@ -33,4 +35,8 @@ public interface DebugListener {
public void onFinish(String clientId);
public byte[] onRequestBytes(String clientId);
public void onLoaderModifyBytes(String clientId, byte[] inputData, String url, DebugLoaderDataModified modifiedListener);
public boolean isModifyBytesSupported();
}
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2010-2024 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.debugger;
/**
*
* @author JPEXS
*/
public interface DebugLoaderDataModified {
public void dataModified(byte[] data);
}
@@ -48,6 +48,10 @@ public class Debugger {
public static final int MSG_DUMP_BYTEARRAY = 3;
public static final int MSG_REQUEST_BYTEARRAY = 4;
public static final int MSG_LOADER_URL_INFO = 5;
public static final int MSG_LOADER_MODIFY_BYTES = 6;
private static final Set<DebugListener> listeners = new HashSet<>();
@@ -285,6 +289,62 @@ public class Debugger {
os.flush();
logger.finer("listeners checked");
break;
case MSG_LOADER_URL_INFO:
logger.finer("reading string...");
ret = readString(is);
logger.finer("informing listeners...");
for (DebugListener l : listeners) {
l.onLoaderURLInfo(clientName, ret);
}
logger.finer("listeners informed");
break;
case MSG_LOADER_MODIFY_BYTES:
logger.finer("reading url(string)...");
String url = readString(is);
logger.finer("reading bytes...");
byte[] inputBytes = readBytes(is);
logger.finer("checking listeners for data...");
boolean modifyDataFound = false;
for (DebugListener l : listeners) {
if (l.isModifyBytesSupported()) {
l.onLoaderModifyBytes(clientName, inputBytes, url, new DebugLoaderDataModified() {
@Override
public void dataModified(byte[] data) {
if (data != null) {
logger.finer("got modified data");
logger.log(Level.FINER, "writing data.length = {0}", data.length);
try {
writeBytes(os, data);
os.flush();
} catch (IOException ex) {
Logger.getLogger(Debugger.class.getName()).log(Level.SEVERE, null, ex);
}
logger.finer("data written");
} else {
logger.finer("got empty modified data, writing original array");
try {
writeBytes(os, inputBytes);
} catch (IOException ex) {
Logger.getLogger(Debugger.class.getName()).log(Level.SEVERE, null, ex);
}
logger.finer("data written");
}
}
});
modifyDataFound = true;
break;
}
}
if (!modifyDataFound) {
logger.finer("listener not found, writing original array");
writeBytes(os, inputBytes);
logger.finer("data written");
}
os.flush();
logger.finer("listeners checked");
break;
}
}
}