コード例 #1
0
ファイル: LVLFAbstractType.java プロジェクト: aw1621107/hacks
 protected void fillFields(byte[] data, int offset) {
   field_1_iStartAt = LittleEndian.getInt(data, 0x0 + offset);
   field_2_nfc = data[0x4 + offset];
   field_3_info = data[0x5 + offset];
   field_4_rgbxchNums = LittleEndian.getByteArray(data, 0x6 + offset, 9);
   field_5_ixchFollow = data[0xf + offset];
   field_6_dxaIndentSav = LittleEndian.getInt(data, 0x10 + offset);
   field_7_unused2 = LittleEndian.getInt(data, 0x14 + offset);
   field_8_cbGrpprlChpx = LittleEndian.getUByte(data, 0x18 + offset);
   field_9_cbGrpprlPapx = LittleEndian.getUByte(data, 0x19 + offset);
   field_10_ilvlRestartLim = LittleEndian.getUByte(data, 0x1a + offset);
   field_11_grfhic = new Grfhic(data, 0x1b + offset);
 }
コード例 #2
0
 public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
   int bytesRemaining = readHeader(data, offset);
   int pos = offset + 8;
   int size = 0;
   field_1_rectX1 = LittleEndian.getInt(data, pos + size);
   size += 4;
   field_2_rectY1 = LittleEndian.getInt(data, pos + size);
   size += 4;
   field_3_rectX2 = LittleEndian.getInt(data, pos + size);
   size += 4;
   field_4_rectY2 = LittleEndian.getInt(data, pos + size);
   size += 4;
   bytesRemaining -= size;
   if (bytesRemaining != 0)
     throw new RecordFormatException("Expected no remaining bytes but got " + bytesRemaining);
   //        remainingData  =  new byte[bytesRemaining];
   //        System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
   return 8 + size + bytesRemaining;
 }
コード例 #3
0
  private static int findText(byte[] tableStream, int complexOffset, ArrayList<WordTextPiece> text)
      throws IOException {
    // actual text
    int pos = complexOffset;
    int multiple = 2;
    // skips through the prms before we reach the piece table. These contain
    // data
    // for actual fast saved files
    while (tableStream[pos] == 1) {
      pos++;
      int skip = LittleEndian.getShort(tableStream, pos);
      pos += 2 + skip;
    }
    if (tableStream[pos] != 2) {
      throw new IOException("corrupted Word file");
    } else {
      // parse out the text pieces
      int pieceTableSize = LittleEndian.getInt(tableStream, ++pos);
      pos += 4;
      int pieces = (pieceTableSize - 4) / 12;
      for (int x = 0; x < pieces; x++) {
        int filePos = LittleEndian.getInt(tableStream, pos + ((pieces + 1) * 4) + (x * 8) + 2);
        boolean unicode = false;
        if ((filePos & 0x40000000) == 0) {
          unicode = true;
        } else {
          unicode = false;
          multiple = 1;
          filePos &= ~(0x40000000); // gives me FC in doc stream
          filePos /= 2;
        }
        int totLength =
            LittleEndian.getInt(tableStream, pos + (x + 1) * 4)
                - LittleEndian.getInt(tableStream, pos + (x * 4));

        WordTextPiece piece = new WordTextPiece(filePos, totLength, unicode);
        text.add(piece);
      }
    }
    return multiple;
  }
コード例 #4
0
 public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
   int bytesRemaining = readHeader(data, offset);
   int pos = offset + 8;
   int size = 0;
   field_1_shapeIdMax = LittleEndian.getInt(data, pos + size);
   size += 4;
   LittleEndian.getInt(data, pos + size);
   size += 4; // field_2_numIdClusters
   field_3_numShapesSaved = LittleEndian.getInt(data, pos + size);
   size += 4;
   field_4_drawingsSaved = LittleEndian.getInt(data, pos + size);
   size += 4;
   field_5_fileIdClusters =
       new FileIdCluster[(bytesRemaining - size) / 8]; // Can't rely on field_2_numIdClusters
   for (int i = 0; i < field_5_fileIdClusters.length; i++) {
     field_5_fileIdClusters[i] =
         new FileIdCluster(
             LittleEndian.getInt(data, pos + size), LittleEndian.getInt(data, pos + size + 4));
     maxDgId = Math.max(maxDgId, field_5_fileIdClusters[i].getDrawingGroupId());
     size += 8;
   }
   bytesRemaining -= size;
   if (bytesRemaining != 0)
     throw new RecordFormatException(
         "Expecting no remaining data but got " + bytesRemaining + " byte(s).");
   return 8 + size + bytesRemaining;
 }
コード例 #5
0
ファイル: EMF.java プロジェクト: aw1621107/hacks
 public NativeHeader(byte data[], int offset) {
   int type = (int) LittleEndian.getUInt(data, offset);
   offset += 4;
   if (type != 1) {
     throw new HSLFException("Invalid EMF picture");
   }
   // ignore header size
   offset += 4;
   int left = LittleEndian.getInt(data, offset);
   offset += 4;
   int top = LittleEndian.getInt(data, offset);
   offset += 4;
   int right = LittleEndian.getInt(data, offset);
   offset += 4;
   int bottom = LittleEndian.getInt(data, offset);
   offset += 4;
   deviceBounds = new Rectangle(left, top, right - left, bottom - top);
   // ignore frame bounds
   offset += 16;
   String signature = new String(data, offset, EMF_SIGNATURE.length(), LocaleUtil.CHARSET_1252);
   if (!EMF_SIGNATURE.equals(signature)) {
     throw new HSLFException("Invalid EMF picture");
   }
 }
コード例 #6
0
ファイル: FIBFieldHandler.java プロジェクト: chiyiangel/UXIN
 public FIBFieldHandler(
     byte mainStream[],
     int startOffset,
     byte tableStream[],
     HashSet offsetList,
     boolean areKnown) {
   _unknownMap = new HashMap();
   int numFields = LittleEndian.getShort(mainStream, startOffset);
   int offset = startOffset + 2;
   _fields = new int[numFields * 2];
   for (int x = 0; x < numFields; x++) {
     int fieldOffset = x * 8 + offset;
     int dsOffset = LittleEndian.getInt(mainStream, fieldOffset);
     fieldOffset += 4;
     int dsSize = LittleEndian.getInt(mainStream, fieldOffset);
     if (offsetList.contains(Integer.valueOf(x)) ^ areKnown && dsSize > 0)
       if (dsOffset + dsSize > tableStream.length) {
         log.log(
             POILogger.WARN,
             (new StringBuilder())
                 .append("Unhandled data structure points to outside the buffer. offset = ")
                 .append(dsOffset)
                 .append(", length = ")
                 .append(dsSize)
                 .append(", buffer length = ")
                 .append(tableStream.length)
                 .toString());
       } else {
         UnhandledDataStructure unhandled =
             new UnhandledDataStructure(tableStream, dsOffset, dsSize);
         _unknownMap.put(Integer.valueOf(x), unhandled);
       }
     _fields[x * 2] = dsOffset;
     _fields[x * 2 + 1] = dsSize;
   }
 }
コード例 #7
0
  /** For the TextHeader Atom */
  protected TextHeaderAtom(byte[] source, int start, int len) {
    // Sanity Checking - we're always 12 bytes long
    if (len < 12) {
      len = 12;
      if (source.length - start < 12) {
        throw new RuntimeException(
            "Not enough data to form a TextHeaderAtom (always 12 bytes long) - found "
                + (source.length - start));
      }
    }

    // Get the header
    _header = new byte[8];
    System.arraycopy(source, start, _header, 0, 8);

    // Grab the type
    textType = LittleEndian.getInt(source, start + 8);
  }
コード例 #8
0
ファイル: SttbUtils.java プロジェクト: feiwei9696/POI-Android
  static Sttb read(int cDataLength, byte[] buffer, int startOffset) {
    short ffff = LittleEndian.getShort(buffer, startOffset);
    int offset = startOffset + 2;

    if (ffff != (short) 0xffff) {
      // Non-extended character Pascal strings
      throw new UnsupportedOperationException(
          "Non-extended character Pascal strings are not supported right now. "
              + "Please, contact POI developers for update.");
    }
    // strings are extended character strings

    int cData =
        cDataLength == 2
            ? LittleEndian.getUShort(buffer, offset)
            : LittleEndian.getInt(buffer, offset);
    offset += cDataLength;

    Sttb sttb = new Sttb();
    sttb.cDataLength = cDataLength;
    sttb.cbExtra = LittleEndian.getUShort(buffer, offset);
    offset += 2;

    sttb.data = new String[cData];
    sttb.extraData = new byte[cData][];

    for (int i = 0; i < cData; i++) {
      int cchData = LittleEndian.getShort(buffer, offset);
      offset += 2;

      if (cchData < 0) continue;

      sttb.data[i] = StringUtil.getFromUnicodeLE(buffer, offset, cchData);
      offset += cchData * 2;

      sttb.extraData[i] = LittleEndian.getByteArray(buffer, offset, sttb.cbExtra);
      offset += sttb.cbExtra;
    }

    return sttb;
  }
コード例 #9
0
  public void testWrite() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();
    CFRuleRecord rr = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "5", "10");

    PatternFormatting patternFormatting = new PatternFormatting();
    patternFormatting.setFillPattern(PatternFormatting.BRICKS);
    rr.setPatternFormatting(patternFormatting);

    byte[] data = rr.serialize();
    assertEquals(26, data.length);
    assertEquals(3, LittleEndian.getShort(data, 6));
    assertEquals(3, LittleEndian.getShort(data, 8));

    int flags = LittleEndian.getInt(data, 10);
    assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
    assertEquals(
        "undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
    // check all remaining flag bits (some are not well understood yet)
    assertEquals(0x203FFFFF, flags);
  }
コード例 #10
0
ファイル: EscherRecord.java プロジェクト: aw1621107/hacks
 /**
  * Reads the 8 byte header information and populates the <code>options</code> and <code>recordId
  * </code> records.
  *
  * @param data the byte array to read from
  * @param offset the offset to start reading from
  * @return the number of bytes remaining in this record. This may include the children if this is
  *     a container.
  */
 protected int readHeader(byte[] data, int offset) {
   _options = LittleEndian.getShort(data, offset);
   _recordId = LittleEndian.getShort(data, offset + 2);
   int remainingBytes = LittleEndian.getInt(data, offset + 4);
   return remainingBytes;
 }
コード例 #11
0
  public String extractText(InputStream in) throws IOException {
    ArrayList<WordTextPiece> text = new ArrayList<WordTextPiece>();
    POIFSFileSystem fsys = new POIFSFileSystem(in);

    DocumentEntry headerProps = (DocumentEntry) fsys.getRoot().getEntry("WordDocument");
    DocumentInputStream din = fsys.createDocumentInputStream("WordDocument");
    byte[] header = new byte[headerProps.getSize()];

    din.read(header);
    din.close();
    // Prende le informazioni dall'header del documento
    int info = LittleEndian.getShort(header, 0xa);

    boolean useTable1 = (info & 0x200) != 0;

    // boolean useTable1 = true;

    // Prende informazioni dalla piece table
    int complexOffset = LittleEndian.getInt(header, 0x1a2);
    // int complexOffset = LittleEndian.getInt(header);

    String tableName = null;
    if (useTable1) {
      tableName = "1Table";
    } else {
      tableName = "0Table";
    }

    DocumentEntry table = (DocumentEntry) fsys.getRoot().getEntry(tableName);
    byte[] tableStream = new byte[table.getSize()];

    din = fsys.createDocumentInputStream(tableName);

    din.read(tableStream);
    din.close();

    din = null;
    fsys = null;
    table = null;
    headerProps = null;

    int multiple = findText(tableStream, complexOffset, text);

    StringBuffer sb = new StringBuffer();
    tableStream = null;

    for (int x = 0; x < text.size(); x++) {

      WordTextPiece nextPiece = (WordTextPiece) text.get(x);
      int start = nextPiece.getStart();
      int length = nextPiece.getLength();

      boolean unicode = nextPiece.usesUnicode();
      String toStr = null;
      if (unicode) {
        toStr = new String(header, start, length * multiple, "UTF-8");
      } else {
        toStr = new String(header, start, length, "big5");
      }
      sb.append(toStr).append(" ");
    }
    return sb.toString();
  }