Example #1
0
  /** Parse the contents of the file - calling endABC at the end */
  public void parse() throws IOException {
    int minor = in.readUI16();
    int major = in.readUI16();
    abcFile.version(major, minor);

    readIntPool();
    readUIntPool();
    readDoublePool();
    readStringPool();
    readNamespacePool();
    readNSSetPool();
    readNamePool();
    readMethodInfos();
    readMetadata();

    int count = in.readVU30();
    ABC.ClassInfos classInfos = abcFile.classes(count);
    readInstanceInfos(classInfos, count);
    readClassInfos(classInfos, count);
    if (classInfos != null) classInfos.done();

    readScripts();
    readMethodBodies();

    abcFile.done();
  }
Example #2
0
 private void readUIntPool() throws IOException {
   int count = in.readVU30();
   if (count > 0) count--;
   long[] uints = new long[count];
   for (int i = 0; i < uints.length; i++) {
     uints[i] = in.readVU32();
   }
   abcFile.uintPool(uints);
 }
Example #3
0
 private void readIntPool() throws IOException {
   int count = in.readVU30();
   if (count > 0) count--;
   int[] ints = new int[count];
   for (int i = 0; i < ints.length; i++) {
     ints[i] = in.readVS32();
   }
   abcFile.intPool(ints);
 }
Example #4
0
 private void readDoublePool() throws IOException {
   int count = in.readVU30();
   if (count > 0) count--;
   double[] doubles = new double[count];
   for (int i = 0; i < doubles.length; i++) {
     doubles[i] = in.readDoubleLE();
   }
   abcFile.doublePool(doubles);
 }
Example #5
0
 private void readStringPool() throws IOException {
   int count = in.readVU30();
   if (count > 0) count--;
   String[] strings = new String[count];
   for (int i = 0; i < strings.length; i++) {
     strings[i] = in.readVU30String();
   }
   abcFile.stringPool(strings);
 }
Example #6
0
  private void readNamePool() throws IOException {
    int count = in.readVU30();

    ABC.Names names = abcFile.namePool(count);
    for (int i = 1; i < count; i++) {
      readName(names);
    }
    if (names != null) names.done();
  }
Example #7
0
  private void readNamespacePool() throws IOException {
    int count = in.readVU30();

    ABC.Namespaces namespaces = abcFile.namespacePool(count);

    for (int i = 1; i < count; i++) {
      NamespaceKind kind = NamespaceKind.parse(in);
      int index = in.readVU30();

      if (namespaces != null) namespaces.namespace(kind, index);
    }
    if (namespaces != null) namespaces.done();
  }
Example #8
0
  private void readScripts() throws IOException {
    int count = in.readVU30();

    ABC.Scripts scripts = abcFile.scripts(count);

    for (int i = 0; i < count; i++) {
      int initializerIndex = in.readVU30();
      int traitCount = in.readVU30();
      ABC.Traits traits = (scripts != null) ? scripts.script(initializerIndex, traitCount) : null;
      readTraits(traitCount, traits);
    }

    if (scripts != null) scripts.done();
  }
Example #9
0
  private void readNSSetPool() throws IOException {
    int count = in.readVU30();

    ABC.NamespaceSets sets = abcFile.namespaceSetPool(count);

    for (int i = 1; i < count; i++) {
      int cnt2 = in.readVU30();

      int[] nspaces = new int[cnt2];
      for (int j = 0; j < cnt2; j++) {
        nspaces[j] = in.readVU30();
      }

      if (sets != null) sets.namespaceSet(nspaces);
    }
    if (sets != null) sets.done();
  }
Example #10
0
  private void readMethodInfos() throws IOException {
    int count = in.readVU30();

    ABC.MethodInfos infos = abcFile.methods(count);

    for (int i = 0; i < count; i++) {
      int paramCount = in.readVU30();
      int returnType = in.readVU30();

      int[] paramTypes = new int[paramCount];
      for (int j = 0; j < paramTypes.length; j++) {
        paramTypes[j] = in.readVU30();
      }

      int nameIndex = in.readVU30();
      int flags = in.readUI8();

      int optionalCount = 0;
      int[] optValues = null;
      int[] optValKinds = null;
      if (MethodInfoFlags.HasOptional.isSet(flags)) {
        optionalCount = in.readVU30();

        optValues = new int[optionalCount];
        optValKinds = new int[optionalCount];
        for (int j = 0; j < optionalCount; j++) {
          optValues[j] = in.readVU30();
          optValKinds[j] = in.readUI8();
        }
      }

      int[] paramNames = null;
      if (MethodInfoFlags.HasParamNames.isSet(flags)) {
        paramNames = new int[paramCount];
        for (int j = 0; j < paramNames.length; j++) {
          paramNames[j] = in.readVU30();
        }
      }

      if (infos != null)
        infos.methodInfo(
            nameIndex, flags, returnType, paramTypes, optValues, optValKinds, paramNames);
    }

    if (infos != null) infos.done();
  }
Example #11
0
  private void readMetadata() throws IOException {
    int count = in.readVU30();

    ABC.Metadata meta = abcFile.metadata(count);

    for (int i = 0; i < count; i++) {
      int nameIndex = in.readVU30();
      int valCount = in.readVU30();

      int[] keys = new int[valCount];
      int[] vals = new int[valCount];
      for (int j = 0; j < vals.length; j++) {
        keys[j] = in.readVU30();
        vals[j] = in.readVU30();
      }

      if (meta != null) meta.metadata(nameIndex, keys, vals);
    }

    if (meta != null) meta.done();
  }
Example #12
0
  private void readMethodBodies() throws IOException {
    int count = in.readVU30();

    ABC.MethodBodies bodies = abcFile.methodBodies(count);

    for (int i = 0; i < count; i++) {
      int methodInfo = in.readVU30();
      int maxStack = in.readVU30();
      int maxRegs = in.readVU30();
      int scopeDepth = in.readVU30();
      int maxScope = in.readVU30();

      ABC.MethodBody body =
          (bodies != null)
              ? bodies.methodBody(methodInfo, maxStack, maxRegs, scopeDepth, maxScope)
              : null;

      int codeLength = in.readVU30();
      byte[] code = in.read(codeLength);

      List<Instruction> instructionList = new ArrayList<Instruction>();
      Set<Integer> targetAddresses = new HashSet<Integer>();

      // build the instruction list
      ABC.Instructions instrs = (body != null) ? body.instructions(codeLength) : null;
      if (instrs != null && !(instrs instanceof ABC.RawBytecode)) {
        InStream in = new InStream(code);

        while (in.getBytesRead() < codeLength) {
          Instruction instr = Instruction.parse(in);
          targetAddresses.addAll(instr.getTargetAddresses());
          instructionList.add(instr);
        }
      }

      // gather the exception handlers
      int handlerCount = in.readVU30();
      List<int[]> handlerList = new ArrayList<int[]>();

      for (int j = 0; j < handlerCount; j++) {
        int start = in.readVU30();
        int end = in.readVU30();
        int target = in.readVU30();
        int typeIndex = in.readVU30();
        int nameIndex = in.readVU30();

        handlerList.add(new int[] {start, end, target, typeIndex, nameIndex});

        targetAddresses.add(start);
        targetAddresses.add(end);
        targetAddresses.add(target);
      }

      // pass the instructions
      if (instrs != null) {

        if (instrs instanceof ABC.RawBytecode) {
          instrs.bytecode(code);
        } else {
          for (Instruction in : instructionList) {

            // emit an address if the instruction is a target
            if (targetAddresses.contains(in.getOffset())) {
              instrs.target(in.getOffset());
            }

            in.write(instrs);
          }
        }

        instrs.done();
      }

      // pass the exception handlers
      ABC.ExceptionHandlers handlers = (body != null) ? body.exceptionHandlers(handlerCount) : null;
      if (handlers != null) {
        for (int[] handler : handlerList) {
          handlers.exceptionHandler(handler[0], handler[1], handler[2], handler[3], handler[4]);
        }

        handlers.done();
      }

      int traitCount = in.readVU30();
      ABC.Traits traits = (body != null) ? body.traits(traitCount) : null;
      readTraits(traitCount, traits);

      if (body != null) body.done();
    }

    if (bodies != null) bodies.done();
  }