Program: 61991
Project: 61991
Buggy source:
public static AVM2Code parse(InputStream is,ConstantPool constants,Trait trait,MissingSymbolHandler missingHandler,MethodBody body,MethodInfo info) throws IOException, ParseException {
  AVM2Code code=new AVM2Code();
  List<OffsetItem> offsetItems=new ArrayList<>();
  List<LabelItem> labelItems=new ArrayList<>();
  List<ABCException> exceptions=new ArrayList<>();
  List<Integer> exceptionIndices=new ArrayList<>();
  int offset=0;
  Flasm3Lexer lexer=new Flasm3Lexer(new InputStreamReader(is,"String_Node_Str"));
  ParsedSymbol symb;
  AVM2Instruction lastIns=null;
  List<String> exceptionsFrom=new ArrayList<>();
  List<String> exceptionsTo=new ArrayList<>();
  List<String> exceptionsTargets=new ArrayList<>();
  info.flags=0;
  info.name_index=0;
  List<Integer> paramTypes=new ArrayList<>();
  List<Integer> paramNames=new ArrayList<>();
  List<ValueKind> optional=new ArrayList<>();
  do {
    symb=lexer.lex();
    if (Arrays.asList(ParsedSymbol.TYPE_KEYWORD_BODY,ParsedSymbol.TYPE_KEYWORD_CODE,ParsedSymbol.TYPE_KEYWORD_METHOD).contains(symb.type)) {
      continue;
    }
    if (symb.type == ParsedSymbol.TYPE_KEYWORD_TRAIT) {
      if (trait == null) {
        throw new ParseException("String_Node_Str",lexer.yyline());
      }
      symb=lexer.lex();
switch (symb.type) {
case ParsedSymbol.TYPE_KEYWORD_METHOD:
case ParsedSymbol.TYPE_KEYWORD_GETTER:
case ParsedSymbol.TYPE_KEYWORD_SETTER:
        if (!(trait instanceof TraitMethodGetterSetter)) {
          throw new ParseException("String_Node_Str",lexer.yyline());
        }
      TraitMethodGetterSetter tm=(TraitMethodGetterSetter)trait;
switch (symb.type) {
case ParsedSymbol.TYPE_KEYWORD_METHOD:
      tm.kindType=Trait.TRAIT_METHOD;
    break;
case ParsedSymbol.TYPE_KEYWORD_GETTER:
  tm.kindType=Trait.TRAIT_GETTER;
break;
case ParsedSymbol.TYPE_KEYWORD_SETTER:
tm.kindType=Trait.TRAIT_SETTER;
break;
}
tm.name_index=parseMultiName(constants,lexer);
expected(ParsedSymbol.TYPE_KEYWORD_DISPID,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
tm.disp_id=(int)(long)(Long)symb.value;
break;
case ParsedSymbol.TYPE_KEYWORD_FUNCTION:
if (!(trait instanceof TraitFunction)) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_NAME) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_STRING,"String_Node_Str");
info.name_index=constants.getStringId((String)symb.value,true);
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_PARAM) {
paramTypes.add(parseMultiName(constants,lexer));
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_PARAMNAME) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_STRING,"String_Node_Str");
paramNames.add(constants.getStringId((String)symb.value,true));
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_OPTIONAL) {
optional.add(parseValue(constants,lexer));
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_MAXSTACK) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.max_stack=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_LOCALCOUNT) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.max_regs=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_INITSCOPEDEPTH) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.init_scope_depth=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_MAXSCOPEDEPTH) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.max_scope_depth=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_RETURNS) {
info.ret_type=parseMultiName(constants,lexer);
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_FLAG) {
symb=lexer.lex();
switch (symb.type) {
case ParsedSymbol.TYPE_KEYWORD_EXPLICIT:
info.setFlagExplicit();
break;
case ParsedSymbol.TYPE_KEYWORD_HAS_OPTIONAL:
info.setFlagHas_optional();
break;
case ParsedSymbol.TYPE_KEYWORD_HAS_PARAM_NAMES:
info.setFlagHas_paramnames();
break;
case ParsedSymbol.TYPE_KEYWORD_IGNORE_REST:
info.setFlagIgnore_Rest();
break;
case ParsedSymbol.TYPE_KEYWORD_NEED_ACTIVATION:
info.setFlagNeed_activation();
break;
case ParsedSymbol.TYPE_KEYWORD_NEED_ARGUMENTS:
info.setFlagNeed_Arguments();
break;
case ParsedSymbol.TYPE_KEYWORD_NEED_REST:
info.setFlagNeed_rest();
break;
case ParsedSymbol.TYPE_KEYWORD_SET_DXNS:
info.setFlagSetsdxns();
break;
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_TRY) {
expected(ParsedSymbol.TYPE_KEYWORD_FROM,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_IDENTIFIER,"String_Node_Str");
exceptionsFrom.add((String)symb.value);
expected(ParsedSymbol.TYPE_KEYWORD_TO,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_IDENTIFIER,"String_Node_Str");
exceptionsTo.add((String)symb.value);
expected(ParsedSymbol.TYPE_KEYWORD_TARGET,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_IDENTIFIER,"String_Node_Str");
exceptionsTargets.add((String)symb.value);
expected(ParsedSymbol.TYPE_KEYWORD_TYPE,"String_Node_Str",lexer);
ABCException ex=new ABCException();
ex.type_index=parseMultiName(constants,lexer);
expected(ParsedSymbol.TYPE_KEYWORD_NAME,"String_Node_Str",lexer);
ex.name_index=parseMultiName(constants,lexer);
exceptions.add(ex);
continue;
}
if (symb.type == ParsedSymbol.TYPE_EXCEPTION_START) {
int exIndex=(Integer)symb.value;
int listIndex=exceptionIndices.indexOf(exIndex);
if (listIndex == -1) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
exceptions.get(listIndex).start=offset;
continue;
}
if (symb.type == ParsedSymbol.TYPE_EXCEPTION_END) {
int exIndex=(Integer)symb.value;
int listIndex=exceptionIndices.indexOf(exIndex);
if (listIndex == -1) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
exceptions.get(listIndex).end=offset;
continue;
}
if (symb.type == ParsedSymbol.TYPE_EXCEPTION_TARGET) {
int exIndex=(Integer)symb.value;
int listIndex=exceptionIndices.indexOf(exIndex);
if (listIndex == -1) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
exceptions.get(listIndex).target=offset;
continue;
}
if (symb.type == ParsedSymbol.TYPE_EOF) {
break;
}
if (symb.type == ParsedSymbol.TYPE_COMMENT) {
if (lastIns != null) {
lastIns.comment=(String)symb.value;
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_INSTRUCTION_NAME) {
if (((String)symb.value).toLowerCase(Locale.ENGLISH).equals("String_Node_Str")) {
ParsedSymbol exIndex=lexer.lex();
if (exIndex.type != ParsedSymbol.TYPE_INTEGER) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ParsedSymbol exName=lexer.lex();
if (exName.type != ParsedSymbol.TYPE_MULTINAME) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ParsedSymbol exType=lexer.lex();
if (exType.type != ParsedSymbol.TYPE_MULTINAME) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ABCException ex=new ABCException();
ex.name_index=checkMultinameIndex(constants,(int)(long)(Long)exName.value,lexer.yyline());
ex.type_index=checkMultinameIndex(constants,(int)(long)(Long)exType.value,lexer.yyline());
exceptions.add(ex);
exceptionIndices.add((int)(long)(Long)exIndex.value);
continue;
}
boolean insFound=false;
for (InstructionDefinition def : AVM2Code.instructionSet) {
if (def.instructionName.equals((String)symb.value)) {
insFound=true;
List<Integer> operandsList=new ArrayList<>();
for (int i=0; i < def.operands.length; i++) {
ParsedSymbol parsedOperand=lexer.lex();
switch (def.operands[i]) {
case AVM2Code.DAT_MULTINAME_INDEX:
lexer.pushback(parsedOperand);
operandsList.add(parseMultiName(constants,lexer));
break;
case AVM2Code.DAT_STRING_INDEX:
if (parsedOperand.type == ParsedSymbol.TYPE_STRING) {
int sid=constants.getStringId((String)parsedOperand.value);
if (sid == 0) {
if ((missingHandler != null) && (missingHandler.missingString((String)parsedOperand.value))) {
sid=constants.addString((String)parsedOperand.value);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(sid);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.DAT_INT_INDEX:
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
long intVal=(Long)parsedOperand.value;
int iid=constants.getIntId(intVal);
if (iid == 0) {
if ((missingHandler != null) && (missingHandler.missingInt(intVal))) {
iid=constants.addInt(intVal);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(iid);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.DAT_UINT_INDEX:
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
long intVal=(Long)parsedOperand.value;
int iid=constants.getUIntId(intVal);
if (iid == 0) {
if ((missingHandler != null) && (missingHandler.missingUInt(intVal))) {
iid=constants.addUInt(intVal);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(iid);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.DAT_DOUBLE_INDEX:
if ((parsedOperand.type == ParsedSymbol.TYPE_INTEGER) || (parsedOperand.type == ParsedSymbol.TYPE_FLOAT)) {
double doubleVal=0;
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
doubleVal=(Long)parsedOperand.value;
}
if (parsedOperand.type == ParsedSymbol.TYPE_FLOAT) {
doubleVal=(Double)parsedOperand.value;
}
int did=constants.getDoubleId(doubleVal);
if (did == 0) {
if ((missingHandler != null) && (missingHandler.missingDouble(doubleVal))) {
did=constants.addDouble(doubleVal);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(did);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.DAT_OFFSET:
if (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) {
offsetItems.add(new OffsetItem((String)parsedOperand.value,code.code.size(),i));
operandsList.add(0);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.DAT_CASE_BASEOFFSET:
if (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) {
offsetItems.add(new CaseOffsetItem((String)parsedOperand.value,code.code.size(),i));
operandsList.add(0);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.OPT_CASE_OFFSETS:
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
int patCount=(int)(long)(Long)parsedOperand.value;
operandsList.add(patCount);
for (int c=0; c <= patCount; c++) {
parsedOperand=lexer.lex();
if (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) {
offsetItems.add(new CaseOffsetItem((String)parsedOperand.value,code.code.size(),i + (c + 1)));
operandsList.add(0);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
default :
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
operandsList.add((int)(long)(Long)parsedOperand.value);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
}
int[] operands=new int[operandsList.size()];
for (int i=0; i < operandsList.size(); i++) {
operands[i]=operandsList.get(i);
}
lastIns=new AVM2Instruction(offset,def,operands,new byte[0]);
code.code.add(lastIns);
offset+=lastIns.getBytes().length;
break;
}
}
if (symb.value.toString().toLowerCase().equals("String_Node_Str")) {
lastIns=new AVM2Instruction(offset,new DeobfuscatePopIns(),new int[0],new byte[0]);
code.code.add(lastIns);
offset+=lastIns.getBytes().length;
insFound=true;
}
if (!insFound) {
throw new ParseException("String_Node_Str" + (String)symb.value,lexer.yyline());
}
}
 else if (symb.type == ParsedSymbol.TYPE_LABEL) {
labelItems.add(new LabelItem((String)symb.value,offset));
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
 while (symb.type != ParsedSymbol.TYPE_EOF);
code.compact();
for (LabelItem li : labelItems) {
int ind;
ind=exceptionsFrom.indexOf(li.label);
if (ind > -1) {
exceptions.get(ind).start=li.offset;
}
ind=exceptionsTo.indexOf(li.label);
if (ind > -1) {
exceptions.get(ind).end=li.offset;
}
ind=exceptionsTargets.indexOf(li.label);
if (ind > -1) {
exceptions.get(ind).target=li.offset;
}
}
for (OffsetItem oi : offsetItems) {
for (LabelItem li : labelItems) {
if (oi.label.equals(li.label)) {
AVM2Instruction ins=code.code.get((int)oi.insPosition);
int relOffset;
if (oi instanceof CaseOffsetItem) {
relOffset=li.offset - (int)ins.offset;
}
 else {
relOffset=li.offset - ((int)ins.offset + ins.getBytes().length);
}
ins.operands[oi.insOperandIndex]=relOffset;
}
}
}
body.exceptions=new ABCException[exceptions.size()];
for (int e=0; e < exceptions.size(); e++) {
body.exceptions[e]=exceptions.get(e);
}
info.param_types=new int[paramTypes.size()];
for (int i=0; i < paramTypes.size(); i++) {
info.param_types[i]=paramTypes.get(i);
}
if (info.flagHas_paramnames()) {
info.paramNames=new int[paramNames.size()];
for (int i=0; i < paramNames.size(); i++) {
info.paramNames[i]=paramNames.get(i);
}
}
if (info.flagHas_optional()) {
info.optional=new ValueKind[optional.size()];
for (int i=0; i < optional.size(); i++) {
info.optional[i]=optional.get(i);
}
}
return code;
}

Fixed version (ground truth):
public static AVM2Code parse(InputStream is,ConstantPool constants,Trait trait,MissingSymbolHandler missingHandler,MethodBody body,MethodInfo info) throws IOException, ParseException {
  AVM2Code code=new AVM2Code();
  List<OffsetItem> offsetItems=new ArrayList<>();
  List<LabelItem> labelItems=new ArrayList<>();
  List<ABCException> exceptions=new ArrayList<>();
  List<Integer> exceptionIndices=new ArrayList<>();
  int offset=0;
  Flasm3Lexer lexer=new Flasm3Lexer(new InputStreamReader(is,"String_Node_Str"));
  ParsedSymbol symb;
  AVM2Instruction lastIns=null;
  List<String> exceptionsFrom=new ArrayList<>();
  List<String> exceptionsTo=new ArrayList<>();
  List<String> exceptionsTargets=new ArrayList<>();
  info.flags=0;
  info.name_index=0;
  List<Integer> paramTypes=new ArrayList<>();
  List<Integer> paramNames=new ArrayList<>();
  List<ValueKind> optional=new ArrayList<>();
  do {
    symb=lexer.lex();
    if (Arrays.asList(ParsedSymbol.TYPE_KEYWORD_BODY,ParsedSymbol.TYPE_KEYWORD_CODE,ParsedSymbol.TYPE_KEYWORD_METHOD).contains(symb.type)) {
      continue;
    }
    if (symb.type == ParsedSymbol.TYPE_KEYWORD_TRAIT) {
      if (trait == null) {
        throw new ParseException("String_Node_Str",lexer.yyline());
      }
      symb=lexer.lex();
switch (symb.type) {
case ParsedSymbol.TYPE_KEYWORD_METHOD:
case ParsedSymbol.TYPE_KEYWORD_GETTER:
case ParsedSymbol.TYPE_KEYWORD_SETTER:
        if (!(trait instanceof TraitMethodGetterSetter)) {
          throw new ParseException("String_Node_Str",lexer.yyline());
        }
      TraitMethodGetterSetter tm=(TraitMethodGetterSetter)trait;
switch (symb.type) {
case ParsedSymbol.TYPE_KEYWORD_METHOD:
      tm.kindType=Trait.TRAIT_METHOD;
    break;
case ParsedSymbol.TYPE_KEYWORD_GETTER:
  tm.kindType=Trait.TRAIT_GETTER;
break;
case ParsedSymbol.TYPE_KEYWORD_SETTER:
tm.kindType=Trait.TRAIT_SETTER;
break;
}
tm.name_index=parseMultiName(constants,lexer);
expected(ParsedSymbol.TYPE_KEYWORD_DISPID,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
tm.disp_id=(int)(long)(Long)symb.value;
break;
case ParsedSymbol.TYPE_KEYWORD_FUNCTION:
if (!(trait instanceof TraitFunction)) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_NAME) {
symb=lexer.lex();
if (symb.type == ParsedSymbol.TYPE_KEYWORD_NULL) {
info.name_index=0;
}
 else {
expected(symb,ParsedSymbol.TYPE_STRING,"String_Node_Str");
info.name_index=constants.getStringId((String)symb.value,true);
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_PARAM) {
paramTypes.add(parseMultiName(constants,lexer));
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_PARAMNAME) {
symb=lexer.lex();
if (symb.type == ParsedSymbol.TYPE_KEYWORD_NULL) {
paramNames.add(0);
}
 else {
expected(symb,ParsedSymbol.TYPE_STRING,"String_Node_Str");
paramNames.add(constants.getStringId((String)symb.value,true));
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_OPTIONAL) {
optional.add(parseValue(constants,lexer));
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_MAXSTACK) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.max_stack=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_LOCALCOUNT) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.max_regs=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_INITSCOPEDEPTH) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.init_scope_depth=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_MAXSCOPEDEPTH) {
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_INTEGER,"String_Node_Str");
body.max_scope_depth=(int)(long)(Long)symb.value;
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_RETURNS) {
info.ret_type=parseMultiName(constants,lexer);
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_FLAG) {
symb=lexer.lex();
switch (symb.type) {
case ParsedSymbol.TYPE_KEYWORD_EXPLICIT:
info.setFlagExplicit();
break;
case ParsedSymbol.TYPE_KEYWORD_HAS_OPTIONAL:
info.setFlagHas_optional();
break;
case ParsedSymbol.TYPE_KEYWORD_HAS_PARAM_NAMES:
info.setFlagHas_paramnames();
break;
case ParsedSymbol.TYPE_KEYWORD_IGNORE_REST:
info.setFlagIgnore_Rest();
break;
case ParsedSymbol.TYPE_KEYWORD_NEED_ACTIVATION:
info.setFlagNeed_activation();
break;
case ParsedSymbol.TYPE_KEYWORD_NEED_ARGUMENTS:
info.setFlagNeed_Arguments();
break;
case ParsedSymbol.TYPE_KEYWORD_NEED_REST:
info.setFlagNeed_rest();
break;
case ParsedSymbol.TYPE_KEYWORD_SET_DXNS:
info.setFlagSetsdxns();
break;
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_KEYWORD_TRY) {
expected(ParsedSymbol.TYPE_KEYWORD_FROM,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_IDENTIFIER,"String_Node_Str");
exceptionsFrom.add((String)symb.value);
expected(ParsedSymbol.TYPE_KEYWORD_TO,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_IDENTIFIER,"String_Node_Str");
exceptionsTo.add((String)symb.value);
expected(ParsedSymbol.TYPE_KEYWORD_TARGET,"String_Node_Str",lexer);
symb=lexer.lex();
expected(symb,ParsedSymbol.TYPE_IDENTIFIER,"String_Node_Str");
exceptionsTargets.add((String)symb.value);
expected(ParsedSymbol.TYPE_KEYWORD_TYPE,"String_Node_Str",lexer);
ABCException ex=new ABCException();
ex.type_index=parseMultiName(constants,lexer);
expected(ParsedSymbol.TYPE_KEYWORD_NAME,"String_Node_Str",lexer);
ex.name_index=parseMultiName(constants,lexer);
exceptions.add(ex);
continue;
}
if (symb.type == ParsedSymbol.TYPE_EXCEPTION_START) {
int exIndex=(Integer)symb.value;
int listIndex=exceptionIndices.indexOf(exIndex);
if (listIndex == -1) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
exceptions.get(listIndex).start=offset;
continue;
}
if (symb.type == ParsedSymbol.TYPE_EXCEPTION_END) {
int exIndex=(Integer)symb.value;
int listIndex=exceptionIndices.indexOf(exIndex);
if (listIndex == -1) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
exceptions.get(listIndex).end=offset;
continue;
}
if (symb.type == ParsedSymbol.TYPE_EXCEPTION_TARGET) {
int exIndex=(Integer)symb.value;
int listIndex=exceptionIndices.indexOf(exIndex);
if (listIndex == -1) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
exceptions.get(listIndex).target=offset;
continue;
}
if (symb.type == ParsedSymbol.TYPE_EOF) {
break;
}
if (symb.type == ParsedSymbol.TYPE_COMMENT) {
if (lastIns != null) {
lastIns.comment=(String)symb.value;
}
continue;
}
if (symb.type == ParsedSymbol.TYPE_INSTRUCTION_NAME) {
if (((String)symb.value).toLowerCase(Locale.ENGLISH).equals("String_Node_Str")) {
ParsedSymbol exIndex=lexer.lex();
if (exIndex.type != ParsedSymbol.TYPE_INTEGER) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ParsedSymbol exName=lexer.lex();
if (exName.type != ParsedSymbol.TYPE_MULTINAME) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ParsedSymbol exType=lexer.lex();
if (exType.type != ParsedSymbol.TYPE_MULTINAME) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ABCException ex=new ABCException();
ex.name_index=checkMultinameIndex(constants,(int)(long)(Long)exName.value,lexer.yyline());
ex.type_index=checkMultinameIndex(constants,(int)(long)(Long)exType.value,lexer.yyline());
exceptions.add(ex);
exceptionIndices.add((int)(long)(Long)exIndex.value);
continue;
}
boolean insFound=false;
for (InstructionDefinition def : AVM2Code.instructionSet) {
if (def.instructionName.equals((String)symb.value)) {
insFound=true;
List<Integer> operandsList=new ArrayList<>();
for (int i=0; i < def.operands.length; i++) {
ParsedSymbol parsedOperand=lexer.lex();
switch (def.operands[i]) {
case AVM2Code.DAT_MULTINAME_INDEX:
lexer.pushback(parsedOperand);
operandsList.add(parseMultiName(constants,lexer));
break;
case AVM2Code.DAT_STRING_INDEX:
if (parsedOperand.type == ParsedSymbol.TYPE_KEYWORD_NULL) {
operandsList.add(0);
}
 else {
if (parsedOperand.type == ParsedSymbol.TYPE_STRING) {
int sid=constants.getStringId((String)parsedOperand.value);
if (sid == 0) {
if ((missingHandler != null) && (missingHandler.missingString((String)parsedOperand.value))) {
sid=constants.addString((String)parsedOperand.value);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(sid);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
break;
case AVM2Code.DAT_INT_INDEX:
if (parsedOperand.type == ParsedSymbol.TYPE_KEYWORD_NULL) {
operandsList.add(0);
}
 else {
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
long intVal=(Long)parsedOperand.value;
int iid=constants.getIntId(intVal);
if (iid == 0) {
if ((missingHandler != null) && (missingHandler.missingInt(intVal))) {
iid=constants.addInt(intVal);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(iid);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
break;
case AVM2Code.DAT_UINT_INDEX:
if (parsedOperand.type == ParsedSymbol.TYPE_KEYWORD_NULL) {
operandsList.add(0);
}
 else {
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
long intVal=(Long)parsedOperand.value;
int iid=constants.getUIntId(intVal);
if (iid == 0) {
if ((missingHandler != null) && (missingHandler.missingUInt(intVal))) {
iid=constants.addUInt(intVal);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(iid);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
break;
case AVM2Code.DAT_DOUBLE_INDEX:
if (parsedOperand.type == ParsedSymbol.TYPE_KEYWORD_NULL) {
operandsList.add(0);
}
 else {
if ((parsedOperand.type == ParsedSymbol.TYPE_INTEGER) || (parsedOperand.type == ParsedSymbol.TYPE_FLOAT)) {
double doubleVal=0;
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
doubleVal=(Long)parsedOperand.value;
}
if (parsedOperand.type == ParsedSymbol.TYPE_FLOAT) {
doubleVal=(Double)parsedOperand.value;
}
int did=constants.getDoubleId(doubleVal);
if (did == 0) {
if ((missingHandler != null) && (missingHandler.missingDouble(doubleVal))) {
did=constants.addDouble(doubleVal);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
operandsList.add(did);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
break;
case AVM2Code.DAT_OFFSET:
if (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) {
offsetItems.add(new OffsetItem((String)parsedOperand.value,code.code.size(),i));
operandsList.add(0);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.DAT_CASE_BASEOFFSET:
if (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) {
offsetItems.add(new CaseOffsetItem((String)parsedOperand.value,code.code.size(),i));
operandsList.add(0);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case AVM2Code.OPT_CASE_OFFSETS:
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
int patCount=(int)(long)(Long)parsedOperand.value;
operandsList.add(patCount);
for (int c=0; c <= patCount; c++) {
parsedOperand=lexer.lex();
if (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) {
offsetItems.add(new CaseOffsetItem((String)parsedOperand.value,code.code.size(),i + (c + 1)));
operandsList.add(0);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
default :
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
operandsList.add((int)(long)(Long)parsedOperand.value);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
}
int[] operands=new int[operandsList.size()];
for (int i=0; i < operandsList.size(); i++) {
operands[i]=operandsList.get(i);
}
lastIns=new AVM2Instruction(offset,def,operands,new byte[0]);
code.code.add(lastIns);
offset+=lastIns.getBytes().length;
break;
}
}
if (symb.value.toString().toLowerCase().equals("String_Node_Str")) {
lastIns=new AVM2Instruction(offset,new DeobfuscatePopIns(),new int[0],new byte[0]);
code.code.add(lastIns);
offset+=lastIns.getBytes().length;
insFound=true;
}
if (!insFound) {
throw new ParseException("String_Node_Str" + (String)symb.value,lexer.yyline());
}
}
 else if (symb.type == ParsedSymbol.TYPE_LABEL) {
labelItems.add(new LabelItem((String)symb.value,offset));
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
}
 while (symb.type != ParsedSymbol.TYPE_EOF);
code.compact();
for (LabelItem li : labelItems) {
int ind;
ind=exceptionsFrom.indexOf(li.label);
if (ind > -1) {
exceptions.get(ind).start=li.offset;
}
ind=exceptionsTo.indexOf(li.label);
if (ind > -1) {
exceptions.get(ind).end=li.offset;
}
ind=exceptionsTargets.indexOf(li.label);
if (ind > -1) {
exceptions.get(ind).target=li.offset;
}
}
for (OffsetItem oi : offsetItems) {
for (LabelItem li : labelItems) {
if (oi.label.equals(li.label)) {
AVM2Instruction ins=code.code.get((int)oi.insPosition);
int relOffset;
if (oi instanceof CaseOffsetItem) {
relOffset=li.offset - (int)ins.offset;
}
 else {
relOffset=li.offset - ((int)ins.offset + ins.getBytes().length);
}
ins.operands[oi.insOperandIndex]=relOffset;
}
}
}
body.exceptions=new ABCException[exceptions.size()];
for (int e=0; e < exceptions.size(); e++) {
body.exceptions[e]=exceptions.get(e);
}
info.param_types=new int[paramTypes.size()];
for (int i=0; i < paramTypes.size(); i++) {
info.param_types[i]=paramTypes.get(i);
}
if (info.flagHas_paramnames()) {
info.paramNames=new int[paramNames.size()];
for (int i=0; i < paramNames.size(); i++) {
info.paramNames[i]=paramNames.get(i);
}
}
if (info.flagHas_optional()) {
info.optional=new ValueKind[optional.size()];
for (int i=0; i < optional.size(); i++) {
info.optional[i]=optional.get(i);
}
}
return code;
}