mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-21 19:06:03 +00:00
AS3 p-code block ends like in RabcDasm
This commit is contained in:
@@ -1152,45 +1152,15 @@ public class AVM2Code implements Cloneable {
|
||||
|
||||
public String toASMSource(AVM2ConstantPool constants) {
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
|
||||
toASMSource(constants, null, null, null, new ArrayList<>(), ScriptExportMode.PCODE, writer);
|
||||
toASMSource(constants, null, null, new ArrayList<>(), ScriptExportMode.PCODE, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public GraphTextWriter toASMSource(AVM2ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, ScriptExportMode exportMode, GraphTextWriter writer) {
|
||||
return toASMSource(constants, trait, info, body, new ArrayList<>(), exportMode, writer);
|
||||
public GraphTextWriter toASMSource(AVM2ConstantPool constants, MethodInfo info, MethodBody body, ScriptExportMode exportMode, GraphTextWriter writer) {
|
||||
return toASMSource(constants, info, body, new ArrayList<>(), exportMode, writer);
|
||||
}
|
||||
|
||||
public GraphTextWriter toASMSource(AVM2ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, List<Integer> outputMap, ScriptExportMode exportMode, GraphTextWriter writer) {
|
||||
if (trait != null) {
|
||||
if (trait instanceof TraitFunction) {
|
||||
TraitFunction tf = (TraitFunction) trait;
|
||||
writer.appendNoHilight("trait ");
|
||||
writer.hilightSpecial("function ", HighlightSpecialType.TRAIT_TYPE);
|
||||
writer.hilightSpecial(constants.multinameToString(tf.name_index), HighlightSpecialType.TRAIT_NAME);
|
||||
writer.appendNoHilight(" slotid ");
|
||||
writer.hilightSpecial("" + tf.slot_id, HighlightSpecialType.SLOT_ID);
|
||||
writer.newLine();
|
||||
}
|
||||
if (trait instanceof TraitMethodGetterSetter) {
|
||||
TraitMethodGetterSetter tm = (TraitMethodGetterSetter) trait;
|
||||
writer.appendNoHilight("trait ");
|
||||
switch (tm.kindType) {
|
||||
case Trait.TRAIT_METHOD:
|
||||
writer.hilightSpecial("method ", HighlightSpecialType.TRAIT_TYPE);
|
||||
break;
|
||||
case Trait.TRAIT_GETTER:
|
||||
writer.hilightSpecial("getter ", HighlightSpecialType.TRAIT_TYPE);
|
||||
break;
|
||||
case Trait.TRAIT_SETTER:
|
||||
writer.hilightSpecial("setter ", HighlightSpecialType.TRAIT_TYPE);
|
||||
break;
|
||||
}
|
||||
writer.hilightSpecial(constants.multinameToString(tm.name_index), HighlightSpecialType.TRAIT_NAME);
|
||||
writer.appendNoHilight(" dispid ");
|
||||
writer.hilightSpecial("" + tm.disp_id, HighlightSpecialType.DISP_ID);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
public GraphTextWriter toASMSource(AVM2ConstantPool constants, MethodInfo info, MethodBody body, List<Integer> outputMap, ScriptExportMode exportMode, GraphTextWriter writer) {
|
||||
|
||||
if (info != null) {
|
||||
writer.appendNoHilight("method").newLine();
|
||||
@@ -1317,7 +1287,6 @@ public class AVM2Code implements Cloneable {
|
||||
|
||||
writer.newLine();
|
||||
writer.appendNoHilight("code").newLine();
|
||||
|
||||
int ip = 0;
|
||||
int largeLimit = 20000;
|
||||
boolean markOffsets = code.size() <= largeLimit;
|
||||
@@ -1362,6 +1331,13 @@ public class AVM2Code implements Cloneable {
|
||||
} else if (exportMode == ScriptExportMode.CONSTANTS) {
|
||||
writer.appendNoHilight("Constant export mode is not supported.").newLine();
|
||||
}
|
||||
writer.appendNoHilight("end ; code").newLine();
|
||||
if (body != null) {
|
||||
writer.appendNoHilight("end ; body").newLine();
|
||||
}
|
||||
if (info != null) {
|
||||
writer.appendNoHilight("end ; method").newLine();
|
||||
}
|
||||
|
||||
return writer;
|
||||
}
|
||||
|
||||
@@ -572,7 +572,8 @@ public class ASM3Parser {
|
||||
public static AVM2Code parse(ABC abc, Reader reader, Trait trait, MissingSymbolHandler missingHandler, MethodBody body, MethodInfo info) throws IOException, AVM2ParseException, InterruptedException {
|
||||
AVM2ConstantPool constants = abc.constants;
|
||||
AVM2Code code = new AVM2Code();
|
||||
|
||||
int openedBlocks = 0;
|
||||
boolean autoCloseBlocks = false;
|
||||
List<OffsetItem> offsetItems = new ArrayList<>();
|
||||
List<LabelItem> labelItems = new ArrayList<>();
|
||||
List<ABCException> exceptions = new ArrayList<>();
|
||||
@@ -594,9 +595,11 @@ public class ASM3Parser {
|
||||
do {
|
||||
symb = lexer.lex();
|
||||
if (Arrays.asList(ParsedSymbol.TYPE_KEYWORD_BODY, ParsedSymbol.TYPE_KEYWORD_CODE, ParsedSymbol.TYPE_KEYWORD_METHOD).contains(symb.type)) {
|
||||
openedBlocks++;
|
||||
continue;
|
||||
}
|
||||
if (symb.type == ParsedSymbol.TYPE_KEYWORD_TRAIT) {
|
||||
openedBlocks++;
|
||||
if (trait == null) {
|
||||
throw new AVM2ParseException("No trait expected", lexer.yyline());
|
||||
}
|
||||
@@ -790,6 +793,14 @@ public class ASM3Parser {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (symb.type == ParsedSymbol.TYPE_KEYWORD_END) {
|
||||
if (openedBlocks > 0) {
|
||||
openedBlocks--;
|
||||
} else {
|
||||
throw new AVM2ParseException("End block encountered but there is no block opened", lexer.yyline());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (symb.type == ParsedSymbol.TYPE_INSTRUCTION_NAME) {
|
||||
if (((String) symb.value).toLowerCase(Locale.ENGLISH).equals("exception")) {
|
||||
ParsedSymbol exIndex = lexer.lex();
|
||||
@@ -1055,6 +1066,10 @@ public class ASM3Parser {
|
||||
}
|
||||
} while (symb.type != ParsedSymbol.TYPE_EOF);
|
||||
|
||||
if (!autoCloseBlocks && openedBlocks > 0) {
|
||||
throw new AVM2ParseException("End of the block expected: " + openedBlocks + "x", lexer.yyline());
|
||||
}
|
||||
|
||||
code.compact();
|
||||
for (LabelItem li : labelItems) {
|
||||
int ind;
|
||||
|
||||
@@ -294,7 +294,7 @@ public final class MethodBody implements Cloneable {
|
||||
System.err.println("Decompiling " + path);
|
||||
}
|
||||
if (exportMode != ScriptExportMode.AS) {
|
||||
getCode().toASMSource(abc.constants, trait, abc.method_info.get(this.method_info), this, exportMode, writer);
|
||||
getCode().toASMSource(abc.constants, abc.method_info.get(this.method_info), this, exportMode, writer);
|
||||
} else {
|
||||
if ((DEBUG_FIXED != null && !path.endsWith(DEBUG_FIXED)) || (!Configuration.decompile.get())) {
|
||||
writer.appendNoHilight(Helper.getDecompilationSkippedComment()).newLine();
|
||||
@@ -347,7 +347,7 @@ public final class MethodBody implements Cloneable {
|
||||
|
||||
public GraphTextWriter toString(final String path, ScriptExportMode exportMode, final ABC abc, final Trait trait, final GraphTextWriter writer, final List<DottedChain> fullyQualifiedNames) throws InterruptedException {
|
||||
if (exportMode != ScriptExportMode.AS) {
|
||||
getCode().toASMSource(abc.constants, trait, abc.method_info.get(this.method_info), this, exportMode, writer);
|
||||
getCode().toASMSource(abc.constants, abc.method_info.get(this.method_info), this, exportMode, writer);
|
||||
} else {
|
||||
if ((DEBUG_FIXED != null && !path.endsWith(DEBUG_FIXED)) || (!Configuration.decompile.get())) {
|
||||
//writer.startMethod(this.method_info);
|
||||
|
||||
@@ -434,7 +434,7 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
writer.append("end ;metadata");
|
||||
writer.append("end ; metadata");
|
||||
}
|
||||
}
|
||||
return writer;
|
||||
|
||||
Reference in New Issue
Block a user