예제 #1
0
파일: Local.java 프로젝트: slemur/SF3
 void read(DataInput in) throws IOException {
   setStartPc(in.readUnsignedShort());
   setLength(in.readUnsignedShort());
   setNameIndex(in.readUnsignedShort());
   setTypeIndex(in.readUnsignedShort());
   setLocal(in.readUnsignedShort());
 }
예제 #2
0
  static Attribute define(ConstantPool cp, String name, int length, DataInput din)
      throws IOException {

    LineNumberTableAttr lineNumbers = new LineNumberTableAttr(cp);

    int size = din.readUnsignedShort();
    for (int i = 0; i < size; i++) {
      int start_pc = din.readUnsignedShort();
      int line_number = din.readUnsignedShort();

      lineNumbers.addEntry(new FixedLocation(start_pc), line_number);
    }

    return lineNumbers;
  }
예제 #3
0
  static Attribute define(ConstantPool cp, String name, int length, DataInput din)
      throws IOException {

    InnerClassesAttr innerClasses = new InnerClassesAttr(cp);

    int size = din.readUnsignedShort();
    for (int i = 0; i < size; i++) {
      int inner_index = din.readUnsignedShort();
      int outer_index = din.readUnsignedShort();
      int name_index = din.readUnsignedShort();
      int af = din.readUnsignedShort();

      ConstantClassInfo inner;
      if (inner_index == 0) {
        inner = null;
      } else {
        inner = (ConstantClassInfo) cp.getConstant(inner_index);
      }

      ConstantClassInfo outer;
      if (outer_index == 0) {
        outer = null;
      } else {
        outer = (ConstantClassInfo) cp.getConstant(outer_index);
      }

      ConstantUTFInfo innerName;
      if (name_index == 0) {
        innerName = null;
      } else {
        innerName = (ConstantUTFInfo) cp.getConstant(name_index);
      }

      Info info = new Info(inner, outer, innerName, af);
      innerClasses.mInnerClasses.add(info);
    }

    return innerClasses;
  }
  public LocalVariableTable_attribute(ConstantPool constantPool, Visitable owner, DataInput in)
      throws IOException {
    super(constantPool, owner);

    int byteCount = in.readInt();
    Logger.getLogger(getClass()).debug("Attribute length: " + byteCount);

    int localVariableTableLength = in.readUnsignedShort();
    Logger.getLogger(getClass())
        .debug("Reading " + localVariableTableLength + " local variable(s) ...");
    for (int i = 0; i < localVariableTableLength; i++) {
      Logger.getLogger(getClass()).debug("Local variable " + i + ":");
      localVariables.add(new LocalVariable(this, in));
    }
  }
예제 #5
0
 private static int readPropertySize(int sizeType, DataInput dataInput) throws IOException {
   switch (sizeType) {
     case 0:
       return 1;
     case 1:
       return 2;
     case 2:
       return 4;
     case 3:
       return 12;
     case 4:
       return 16;
     case 5:
       return dataInput.readUnsignedByte();
     case 6:
       return dataInput.readUnsignedShort();
     case 7:
       return dataInput.readInt();
     default:
       throw new IllegalArgumentException();
   }
 }
예제 #6
0
 protected void readInfo(DataInput din) throws IOException {
   u2nameIndex = din.readUnsignedShort();
   u2descriptorIndex = din.readUnsignedShort();
 }
  /**
   * Reads from the stream <code>in</code> a representation of a Unicode character string encoded in
   * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format; this string of characters is
   * then returned as a <code>String</code>. The details of the modified UTF-8 representation are
   * exactly the same as for the <code>readUTF</code> method of <code>DataInput</code>.
   *
   * @param in a data input stream.
   * @return a Unicode string.
   * @exception EOFException if the input stream reaches the end before all the bytes.
   * @exception IOException if an I/O error occurs.
   * @exception UTFDataFormatException if the bytes do not represent a valid modified UTF-8 encoding
   *     of a Unicode string.
   * @see java.io.DataInputStream#readUnsignedShort()
   */
  public static final String readUTF(DataInput in) throws IOException {
    int utflen = in.readUnsignedShort();
    byte[] bytearr = null;
    char[] chararr = null;
    if (in instanceof DataInputStream) {
      DataInputStream dis = (DataInputStream) in;
      if (dis.bytearr.length < utflen) {
        dis.bytearr = new byte[utflen * 2];
        dis.chararr = new char[utflen * 2];
      }
      chararr = dis.chararr;
      bytearr = dis.bytearr;
    } else {
      bytearr = new byte[utflen];
      chararr = new char[utflen];
    }

    int c, char2, char3;
    int count = 0;
    int chararr_count = 0;

    in.readFully(bytearr, 0, utflen);

    while (count < utflen) {
      c = (int) bytearr[count] & 0xff;
      if (c > 127) break;
      count++;
      chararr[chararr_count++] = (char) c;
    }

    while (count < utflen) {
      c = (int) bytearr[count] & 0xff;
      switch (c >> 4) {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
          /* 0xxxxxxx*/
          count++;
          chararr[chararr_count++] = (char) c;
          break;
        case 12:
        case 13:
          /* 110x xxxx   10xx xxxx*/
          count += 2;
          if (count > utflen)
            throw new UTFDataFormatException("malformed input: partial character at end");
          char2 = (int) bytearr[count - 1];
          if ((char2 & 0xC0) != 0x80)
            throw new UTFDataFormatException("malformed input around byte " + count);
          chararr[chararr_count++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
          break;
        case 14:
          /* 1110 xxxx  10xx xxxx  10xx xxxx */
          count += 3;
          if (count > utflen)
            throw new UTFDataFormatException("malformed input: partial character at end");
          char2 = (int) bytearr[count - 2];
          char3 = (int) bytearr[count - 1];
          if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
            throw new UTFDataFormatException("malformed input around byte " + (count - 1));
          chararr[chararr_count++] =
              (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
          break;
        default:
          /* 10xx xxxx,  1111 xxxx */
          throw new UTFDataFormatException("malformed input around byte " + count);
      }
    }
    // The number of chars produced may be less than utflen
    return new String(chararr, 0, chararr_count);
  }
예제 #8
0
 void readData(DataInput in) throws IOException {
   _classIndex = in.readUnsignedShort();
   _nameAndTypeIndex = in.readUnsignedShort();
 }
예제 #9
0
 protected void readInfo(DataInput din, ClassFile classFile) throws IOException {
   u2sourceFileIndex = din.readUnsignedShort();
 }
  @Test
  public void testRead3SPP16BPSLittleEndian() throws IOException {
    FastByteArrayOutputStream out = new FastByteArrayOutputStream(24);
    DataOutput dataOut = new LittleEndianDataOutputStream(out);
    dataOut.writeShort(0x0000);
    dataOut.writeShort(0x0000);
    dataOut.writeShort(0x0000);
    dataOut.writeShort(4660);
    dataOut.writeShort(30292);
    dataOut.writeShort(4660);
    dataOut.writeShort(4660);
    dataOut.writeShort(30292);
    dataOut.writeShort(4660);
    dataOut.writeShort(-9320);
    dataOut.writeShort(-60584);
    dataOut.writeShort(-9320);

    dataOut.writeShort(0x0000);
    dataOut.writeShort(0x0000);
    dataOut.writeShort(0x0000);
    dataOut.writeShort(30292);
    dataOut.writeShort(30292);
    dataOut.writeShort(30292);
    dataOut.writeShort(30292);
    dataOut.writeShort(30292);
    dataOut.writeShort(30292);
    dataOut.writeShort(-60584);
    dataOut.writeShort(-60584);
    dataOut.writeShort(-60584);

    InputStream in =
        new HorizontalDeDifferencingStream(
            out.createInputStream(), 4, 3, 16, ByteOrder.LITTLE_ENDIAN);
    DataInput dataIn = new LittleEndianDataInputStream(in);

    // Row 1
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(4660, dataIn.readUnsignedShort());
    assertEquals(30292, dataIn.readUnsignedShort());
    assertEquals(4660, dataIn.readUnsignedShort());
    assertEquals(9320, dataIn.readUnsignedShort());
    assertEquals(60584, dataIn.readUnsignedShort());
    assertEquals(9320, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());

    // Row 2
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(30292, dataIn.readUnsignedShort());
    assertEquals(30292, dataIn.readUnsignedShort());
    assertEquals(30292, dataIn.readUnsignedShort());
    assertEquals(60584, dataIn.readUnsignedShort());
    assertEquals(60584, dataIn.readUnsignedShort());
    assertEquals(60584, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());
    assertEquals(0, dataIn.readUnsignedShort());

    // EOF
    assertEquals(-1, in.read());
  }
예제 #11
0
  /**
   * Factory method for creating <tt>AttributeInfo</tt> structures.
   *
   * <p>An <tt>AttributeInfo</tt> of the appropriate subtype from the <tt>attributes</tt> package is
   * created unless the type of the attribute is unknown in which case an instance of
   * <tt>AttributeInfo</tt> is returned.
   *
   * <p>
   *
   * <p>Attributes are skipped if the environment variable <tt>SYSTEM_PROPERTY_SKIP_ATTRIBUTES</tt>
   * is set to true.
   *
   * @param in the <tt>DataInput</tt> from which to read the <tt>AttributeInfo</tt> structure
   * @param classFile the parent class file of the structure to be created
   * @return the new <tt>AttributeInfo</tt> structure
   * @throws InvalidByteCodeException if the byte code is invalid
   * @throws IOException if an exception occurs with the <tt>DataInput</tt>
   */
  public static AttributeInfo createOrSkip(DataInput in, ClassFile classFile)
      throws InvalidByteCodeException, IOException {

    AttributeInfo attributeInfo = null;

    if (Boolean.getBoolean(SYSTEM_PROPERTY_SKIP_ATTRIBUTES)) {
      in.skipBytes(2);
      in.skipBytes(in.readInt());
    } else {
      int attributeNameIndex = in.readUnsignedShort();
      int attributeLength = in.readInt();

      ConstantUtf8Info cpInfoName = classFile.getConstantPoolUtf8Entry(attributeNameIndex);
      String attributeName = null;

      if (cpInfoName == null) {
        return null;
      }

      attributeName = cpInfoName.getString();

      if (ConstantValueAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new ConstantValueAttribute();

      } else if (CodeAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new CodeAttribute();

      } else if (ExceptionsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new ExceptionsAttribute();

      } else if (InnerClassesAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new InnerClassesAttribute();

      } else if (SyntheticAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new SyntheticAttribute();

      } else if (SourceFileAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new SourceFileAttribute();

      } else if (LineNumberTableAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new LineNumberTableAttribute();

      } else if (LocalVariableTableAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new LocalVariableTableAttribute();

      } else if (DeprecatedAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new DeprecatedAttribute();

      } else if (EnclosingMethodAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new EnclosingMethodAttribute();

      } else if (SignatureAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new SignatureAttribute();

      } else if (LocalVariableTypeTableAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new LocalVariableTypeTableAttribute();

      } else if (RuntimeVisibleAnnotationsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new RuntimeVisibleAnnotationsAttribute();

      } else if (RuntimeInvisibleAnnotationsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new RuntimeInvisibleAnnotationsAttribute();

      } else if (AnnotationDefaultAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new AnnotationDefaultAttribute();

      } else if (BootstrapMethodsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new BootstrapMethodsAttribute(attributeLength);

      } else {
        attributeInfo = new AttributeInfo(attributeLength);
      }
      attributeInfo.setAttributeNameIndex(attributeNameIndex);
      attributeInfo.setClassFile(classFile);
      attributeInfo.read(in);
    }

    return attributeInfo;
  }