AS3 P-code: try has (optional) end keyword, and is located at the bottom after code.

setlocalx/getlocalx have aliases setlocal_x/getlocal_x
This commit is contained in:
Jindra Petřík
2021-02-08 20:15:19 +01:00
parent a8d1f2b293
commit ab3bb3b15e
7 changed files with 1398 additions and 1315 deletions
@@ -427,6 +427,26 @@ public class AVM2Code implements Cloneable {
}
private static final String[][] instructionAliasesArray = {
//first is original name, then aliases
{"getlocal0", "getlocal_0"},
{"getlocal1", "getlocal_1"},
{"getlocal2", "getlocal_2"},
{"getlocal3", "getlocal_3"},
{"setlocal0", "setlocal_0"},
{"setlocal1", "setlocal_1"},
{"setlocal2", "setlocal_2"},
{"setlocal3", "setlocal_3"},};
public static final Map<String, String> instructionAliases = new HashMap<>();
static {
for (String[] aliases : instructionAliasesArray) {
for (int s = 1; s < aliases.length; s++) {
instructionAliases.put(aliases[s], aliases[0]);
}
}
}
public static final InstructionDefinition[] instructionSet = new InstructionDefinition[256];
public static final InstructionDefinition[] allInstructionSet = new InstructionDefinition[]{
@@ -1262,30 +1282,6 @@ public class AVM2Code implements Cloneable {
writer.appendNoHilight(body.max_scope_depth);
writer.newLine();
for (int e = 0; e < body.exceptions.length; e++) {
ABCException exception = body.exceptions[e];
writer.appendNoHilight("try");
//Note: start and end address can be not on instruction boundary - call adr2pos( nearest=true) to make them legal
writer.appendNoHilight(" from ");
writer.appendNoHilight("ofs");
writer.appendNoHilight(Helper.formatAddress(pos2adr(adr2pos(exception.start, true))));
writer.appendNoHilight(" to ");
writer.appendNoHilight("ofs");
writer.appendNoHilight(Helper.formatAddress(pos2adr(adr2pos(exception.end, true))));
writer.appendNoHilight(" target ");
writer.appendNoHilight("ofs");
writer.appendNoHilight(Helper.formatAddress(exception.target));
writer.appendNoHilight(" type ");
writer.hilightSpecial(exception.type_index == 0 ? "null" : constants.getMultiname(exception.type_index).toString(constants, new ArrayList<>()), HighlightSpecialType.TRY_TYPE, e);
writer.appendNoHilight(" name ");
writer.hilightSpecial(exception.name_index == 0 ? "null" : constants.getMultiname(exception.name_index).toString(constants, new ArrayList<>()), HighlightSpecialType.TRY_NAME, e);
writer.newLine();
}
for (Trait t : body.traits.traits) {
t.convertTraitHeader(abc, writer);
writer.unindent().appendNoHilight("end ; trait").newLine();
@@ -1344,6 +1340,32 @@ public class AVM2Code implements Cloneable {
}
writer.unindent().appendNoHilight("end ; code").newLine();
if (body != null) {
for (int e = 0; e < body.exceptions.length; e++) {
ABCException exception = body.exceptions[e];
writer.appendNoHilight("try");
//Note: start and end address can be not on instruction boundary - call adr2pos( nearest=true) to make them legal
writer.appendNoHilight(" from ");
writer.appendNoHilight("ofs");
writer.appendNoHilight(Helper.formatAddress(pos2adr(adr2pos(exception.start, true))));
writer.appendNoHilight(" to ");
writer.appendNoHilight("ofs");
writer.appendNoHilight(Helper.formatAddress(pos2adr(adr2pos(exception.end, true))));
writer.appendNoHilight(" target ");
writer.appendNoHilight("ofs");
writer.appendNoHilight(Helper.formatAddress(exception.target));
writer.appendNoHilight(" type ");
writer.hilightSpecial(exception.type_index == 0 ? "null" : constants.getMultiname(exception.type_index).toString(constants, new ArrayList<>()), HighlightSpecialType.TRY_TYPE, e);
writer.appendNoHilight(" name ");
writer.hilightSpecial(exception.name_index == 0 ? "null" : constants.getMultiname(exception.name_index).toString(constants, new ArrayList<>()), HighlightSpecialType.TRY_NAME, e);
writer.appendNoHilight(" end");
writer.newLine();
}
writer.unindent().appendNoHilight("end ; body").newLine();
}
if (info != null) {
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.pcode;
import com.jpexs.decompiler.flash.abc.ABC;
@@ -778,6 +779,10 @@ public class ASM3Parser {
expected(ParsedSymbol.TYPE_KEYWORD_NAME, "Name", lexer);
ex.name_index = parseMultiName(constants, lexer);
exceptions.add(ex);
symb = lexer.lex();
if (symb.type != ParsedSymbol.TYPE_KEYWORD_END) {
lexer.pushback(symb);
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_EXCEPTION_START) {
@@ -845,9 +850,13 @@ public class ASM3Parser {
exceptionIndices.add((int) (long) (Long) exIndex.value);
continue;
}
String insName = (String) symb.value;
if (AVM2Code.instructionAliases.containsKey(insName)) {
insName = AVM2Code.instructionAliases.get(insName); //search original unaliased name
}
boolean insFound = false;
for (InstructionDefinition def : AVM2Code.instructionSet) {
if (def != null && !(def instanceof UnknownInstruction) && def.instructionName.equals((String) symb.value)) {
if (def != null && !(def instanceof UnknownInstruction) && def.instructionName.equals(insName)) {
insFound = true;
List<Integer> operandsList = new ArrayList<>();
File diff suppressed because it is too large Load Diff