Fixed Incorrect debugger line numbers when "Open loaded while playing" is enabled

Fixed AS3 debugger - Slow injecting debug info - now faster
Fixed AS3 debugger - obfuscated classes debugging
Fixed Delayed open loaded SWFs while playing
Fixed AS3 Direct editation - script initializer for main document class

Changed Wrong unicode escape `{invalid_utf8:xxx}` changed to `{invalid_utf8=xxx}` for compatibility with file names
This commit is contained in:
Jindra Petřík
2023-12-30 18:06:08 +01:00
parent e54973b761
commit bd6c953218
53 changed files with 325 additions and 80 deletions
@@ -1186,6 +1186,7 @@ public class AVM2Code implements Cloneable {
public String toASMSource(ABC abc, AVM2ConstantPool constants) {
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toASMSource(abc, constants, null, null, new ArrayList<>(), ScriptExportMode.PCODE, writer);
writer.finishHilights();
return writer.toString();
}
@@ -45,6 +45,7 @@ public class NewClassIns extends InstructionDefinition {
int clsIndex = ins.operands[0];
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
stack.pop().toString(writer, LocalData.create(localData.callStack /*??*/, localData.abcIndex, localData.abc, localData.localRegNames, localData.fullyQualifiedNames, new HashSet<>()));
writer.finishHilights();
String baseType = writer.toString();
ABC abc = localData.abc;
stack.push(new UnparsedAVM2Item(ins, localData.lineStartInstruction, "§§newclass(" + abc.constants.getMultiname(abc.instance_info.get(clsIndex).name_index).getName(localData.getConstants(), localData.fullyQualifiedNames, false, true) + "," + baseType + ")"));
@@ -841,6 +841,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
newlocalData.traitUsages = localData.traitUsages;
newlocalData.currentScript = localData.currentScript;
newlocalData.scriptIndex = localData.scriptIndex;
newlocalData.documentClass = localData.documentClass;
newlocalData.privateNs = localData.privateNs;
newlocalData.protectedNs = localData.protectedNs;
newlocalData.isStatic = isStatic;
@@ -1815,6 +1816,12 @@ public class AVM2SourceGenerator implements SourceGenerator {
mbCode.add(ins(AVM2Instructions.PushScope));
int traitScope = 1;
String documentClassStr = localData.documentClass;
DottedChain documentClass = null;
if (documentClassStr != null && !documentClassStr.isEmpty()) {
documentClass = DottedChain.parseNoSuffix(documentClassStr);
}
Map<Trait, Integer> initScopes = new HashMap<>();
@@ -1823,9 +1830,15 @@ public class AVM2SourceGenerator implements SourceGenerator {
TraitClass tc = (TraitClass) t;
DottedChain className = tc.getName(abc).getNameWithNamespace(abc.constants, true);
List<Integer> parents = new ArrayList<>();
int[] nsset = new int[]{constants.getMultiname(tc.name_index).namespace_index};
mbCode.add(ins(AVM2Instructions.FindPropertyStrict, constants.getMultinameId(Multiname.createMultiname(false, constants.getMultiname(tc.name_index).name_index, constants.getNamespaceSetId(nsset, true)), true)));
if (documentClass != null && documentClass.equals(className)) {
mbCode.add(ins(AVM2Instructions.GetScopeObject, 0));
} else {
int[] nsset = new int[]{constants.getMultiname(tc.name_index).namespace_index};
mbCode.add(ins(AVM2Instructions.FindPropertyStrict, constants.getMultinameId(Multiname.createMultiname(false, constants.getMultiname(tc.name_index).name_index, constants.getNamespaceSetId(nsset, true)), true)));
}
traitScope++;
if (abc.instance_info.get(tc.class_info).isInterface()) {
mbCode.add(ins(AVM2Instructions.PushNull));
@@ -2612,10 +2612,11 @@ public class ActionScript3Parser {
return ret;
}
public void addScriptFromTree(List<List<NamespaceItem>> allOpenedNamespaces, List<GraphTargetItem> items, int classPos) throws AVM2ParseException, CompilationException {
public void addScriptFromTree(List<List<NamespaceItem>> allOpenedNamespaces, List<GraphTargetItem> items, int classPos, String documentClass) throws AVM2ParseException, CompilationException {
AVM2SourceGenerator gen = new AVM2SourceGenerator(abcIndex);
SourceGeneratorLocalData localData = new SourceGeneratorLocalData(
new HashMap<>(), 0, Boolean.FALSE, 0);
localData.documentClass = documentClass;
ScriptInfo si = new ScriptInfo();
int scriptIndex = abcIndex.getSelectedAbc().script_info.size();
abcIndex.getSelectedAbc().script_info.add(si);
@@ -2629,10 +2630,10 @@ public class ActionScript3Parser {
abcIndex.getSelectedAbc().fireChanged();
}
public void addScript(String s, String fileName, int classPos, int scriptIndex) throws AVM2ParseException, IOException, CompilationException, InterruptedException {
public void addScript(String s, String fileName, int classPos, int scriptIndex, String documentClass) throws AVM2ParseException, IOException, CompilationException, InterruptedException {
List<List<NamespaceItem>> allOpenedNamespaces = new ArrayList<>();
List<GraphTargetItem> traits = scriptTraitsFromString(allOpenedNamespaces, s, fileName, scriptIndex);
addScriptFromTree(allOpenedNamespaces, traits, classPos);
addScriptFromTree(allOpenedNamespaces, traits, classPos, documentClass);
}
public ActionScript3Parser(AbcIndexing abcIndex) throws IOException, InterruptedException {
@@ -2641,14 +2642,14 @@ public class ActionScript3Parser {
this.abcIndex = abcIndex;
}
public static void compile(String src, ABC abc, AbcIndexing abcIndex, String fileName, int classPos, int scriptIndex, boolean air) throws AVM2ParseException, IOException, InterruptedException, CompilationException {
public static void compile(String src, ABC abc, AbcIndexing abcIndex, String fileName, int classPos, int scriptIndex, boolean air, String documentClass) throws AVM2ParseException, IOException, InterruptedException, CompilationException {
//List<ABC> parABCs = new ArrayList<>();
SWF.initPlayer();
ActionScript3Parser parser = new ActionScript3Parser(abcIndex);
boolean success = false;
ABC originalAbc = ((ABCContainerTag) ((Tag) abc.parentTag).cloneTag()).getABC();
try {
parser.addScript(src, fileName, classPos, scriptIndex);
parser.addScript(src, fileName, classPos, scriptIndex, documentClass);
success = true;
} finally {
if (!success) {
@@ -2673,7 +2674,7 @@ public class ActionScript3Parser {
AbcIndexing abcIndex = swf.getAbcIndex();
abcIndex.selectAbc(abc);
ActionScript3Parser parser = new ActionScript3Parser(abcIndex);
parser.addScript(new String(Helper.readFile(src), Utf8Helper.charset), src, classPos, scriptIndex);
parser.addScript(new String(Helper.readFile(src), Utf8Helper.charset), src, classPos, scriptIndex, swf.getDocumentClass());
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(dst)))) {
abc.saveToStream(fos);
}
@@ -434,6 +434,7 @@ public final class MethodBody implements Cloneable {
writer.indent().indent().indent();
toString(callStack, abcIndex, "", ScriptExportMode.AS, abc, null, writer, new ArrayList<>(), seenMethods);
writer.unindent().unindent().unindent();
writer.finishHilights();
return writer.toString();
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, null, ex);
@@ -73,6 +73,7 @@ public abstract class ConstVarMultinameUsage extends TraitMultinameUsage {
} catch (InterruptedException ex) {
// ignore
}
writer.finishHilights();
return writer.toString().trim();
}
@@ -90,6 +90,7 @@ public abstract class MethodMultinameUsage extends TraitMultinameUsage {
}
((TraitMethodGetterSetter) traits.traits.get(traitIndex)).toStringHeader(null, convertData, "", abc, traitsType == TRAITS_TYPE_CLASS, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList<>(), false, insideInterface);
}
writer.finishHilights();
return writer.toString().trim();
}