org.apache.poi.util.LittleEndian Java Examples

The following examples show how to use org.apache.poi.util.LittleEndian. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EscherBitmapBlip.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int serialize( int offset, byte[] data, EscherSerializationListener listener ) {
    listener.beforeRecordSerialize(offset, getRecordId(), this);

    LittleEndian.putShort( data, offset, getOptions() );
    LittleEndian.putShort( data, offset + 2, getRecordId() );
    LittleEndian.putInt( data, offset + 4, getRecordSize() - HEADER_SIZE );
    int pos = offset + HEADER_SIZE;

    System.arraycopy( field_1_UID, 0, data, pos, 16 );
    data[pos + 16] = field_2_marker;
    byte pd[] = getPicturedata();
    System.arraycopy( pd, 0, data, pos + 17, pd.length );

    listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this);
    return HEADER_SIZE + 16 + 1 + pd.length;
}
 
Example #2
Source File: EscherSpgrRecord.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
    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;
    }
 
Example #3
Source File: PropertySet.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks whether a byte array is in the Horrible Property Set Format.
 *
 * @param src The byte array to check.
 * @param offset The offset in the byte array.
 * @param length The significant number of bytes in the byte
 * array. Only this number of bytes will be checked.
 * @return {@code true} if the byte array is a property set
 * stream, {@code false} if not.
 */
public static boolean isPropertySetStream(final byte[] src, final int offset, final int length) {
    /* FIXME (3): Ensure that at most "length" bytes are read. */

    /*
     * Read the header fields of the stream. They must always be
     * there.
     */
    int o = offset;
    final int byteOrder = LittleEndian.getUShort(src, o);
    o += LittleEndianConsts.SHORT_SIZE;
    if (byteOrder != BYTE_ORDER_ASSERTION) {
        return false;
    }
    final int format = LittleEndian.getUShort(src, o);
    o += LittleEndianConsts.SHORT_SIZE;
    if (format != FORMAT_ASSERTION) {
        return false;
    }
    // final long osVersion = LittleEndian.getUInt(src, offset);
    o += LittleEndianConsts.INT_SIZE;
    // final ClassID classID = new ClassID(src, offset);
    o += ClassID.LENGTH;
    final long sectionCount = LittleEndian.getUInt(src, o);
    return (sectionCount >= 0);
}
 
Example #4
Source File: Property.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link Property} instance by reading its bytes
 * from the property set stream.
 *
 * @param id The property's ID.
 * @param src The bytes the property set stream consists of.
 * @param offset The property's type/value pair's offset in the
 * section.
 * @param length The property's type/value pair's length in bytes.
 * @param codepage The section's and thus the property's
 * codepage. It is needed only when reading string values.
 * @exception UnsupportedEncodingException if the specified codepage is not
 * supported.
 */
public Property(final long id, final byte[] src, final long offset, final int length, final int codepage)
throws UnsupportedEncodingException {
    this.id = id;

    /*
     * ID 0 is a special case since it specifies a dictionary of
     * property IDs and property names.
     */
    if (id == 0) {
        throw new UnsupportedEncodingException("Dictionary not allowed here");
    }

    int o = (int) offset;
    type = LittleEndian.getUInt(src, o);
    o += LittleEndianConsts.INT_SIZE;

    try {
        value = VariantSupport.read(src, o, length, (int) type, codepage);
    } catch (UnsupportedVariantTypeException ex) {
        VariantSupport.writeUnsupportedTypeMessage(ex);
        value = ex.getValue();
    }
}
 
Example #5
Source File: Property.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Writes the property to an output stream.
     *
     * @param out The output stream to write to.
     * @param codepage The codepage to use for writing non-wide strings
     * @return the number of bytes written to the stream
     *
     * @exception IOException if an I/O error occurs
     * @exception WritingNotSupportedException if a variant type is to be
     * written that is not yet supported
     */
    public int write(final OutputStream out, final int codepage)
    throws IOException, WritingNotSupportedException {
        int length = 0;
        long variantType = getType();

        /* Ensure that wide strings are written if the codepage is Unicode. */
//        if (codepage == CodePageUtil.CP_UNICODE && variantType == Variant.VT_LPSTR) {
//            variantType = Variant.VT_LPWSTR;
//        }

        if (variantType == Variant.VT_LPSTR && codepage != CodePageUtil.CP_UTF16) {
            String csStr = CodePageUtil.codepageToEncoding(codepage > 0 ? codepage : Property.DEFAULT_CODEPAGE);
            if (!Charset.forName(csStr).newEncoder().canEncode((String)value)) {
                variantType = Variant.VT_LPWSTR;
            }
        }

        LittleEndian.putUInt(variantType, out);
        length += LittleEndianConsts.INT_SIZE;
        length += VariantSupport.write(out, variantType, getValue(), codepage);
        return length;
    }
 
Example #6
Source File: EscherDump.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Dumps out a hex value by reading from a input stream.
 *
 * @param bytes     How many bytes this hex value consists of.
 * @param in        The stream to read the hex value from.
 * @param out       The stream to write the nicely formatted hex value to.
 */
private void outHex( int bytes, InputStream in, PrintStream out ) throws IOException, LittleEndian.BufferUnderrunException
{
    switch ( bytes )
    {
        case 1:
            out.print( HexDump.toHex( (byte) in.read() ) );
            break;
        case 2:
            out.print( HexDump.toHex( LittleEndian.readShort( in ) ) );
            break;
        case 4:
            out.print( HexDump.toHex( LittleEndian.readInt( in ) ) );
            break;
        default:
            throw new IOException( "Unable to output variable of that width" );
    }
}
 
Example #7
Source File: EscherPictBlip.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int serialize(int offset, byte[] data, EscherSerializationListener listener) {
    listener.beforeRecordSerialize(offset, getRecordId(), this);

    int pos = offset;
    LittleEndian.putShort( data, pos, getOptions() ); pos += 2;
    LittleEndian.putShort( data, pos, getRecordId() ); pos += 2;
    LittleEndian.putInt( data, 0, getRecordSize() - HEADER_SIZE ); pos += 4;

    System.arraycopy( field_1_UID, 0, data, pos, 16 ); pos += 16;
    LittleEndian.putInt( data, pos, field_2_cb ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_x1 ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_y1 ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_x2 ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_y2 ); pos += 4;
    LittleEndian.putInt( data, pos, field_4_ptSize_w ); pos += 4;
    LittleEndian.putInt( data, pos, field_4_ptSize_h ); pos += 4;
    LittleEndian.putInt( data, pos, field_5_cbSave ); pos += 4;
    data[pos] = field_6_fCompression; pos++;
    data[pos] = field_7_fFilter; pos++;

    System.arraycopy( raw_pictureData, 0, data, pos, raw_pictureData.length );

    listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this);
    return HEADER_SIZE + 16 + 1 + raw_pictureData.length;
}
 
Example #8
Source File: ImageHeaderWMF.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void write(OutputStream out) throws IOException {
    byte[] header = new byte[22];
    int pos = 0;
    LittleEndian.putInt(header, pos, APMHEADER_KEY); pos += LittleEndian.INT_SIZE; //header key
    LittleEndian.putUShort(header, pos, 0); pos += LittleEndian.SHORT_SIZE; //hmf
    LittleEndian.putUShort(header, pos, left); pos += LittleEndian.SHORT_SIZE; //left
    LittleEndian.putUShort(header, pos, top); pos += LittleEndian.SHORT_SIZE; //top
    LittleEndian.putUShort(header, pos, right); pos += LittleEndian.SHORT_SIZE; //right
    LittleEndian.putUShort(header, pos, bottom); pos += LittleEndian.SHORT_SIZE; //bottom
    LittleEndian.putUShort(header, pos, inch); pos += LittleEndian.SHORT_SIZE; //inch
    LittleEndian.putInt(header, pos, 0); pos += LittleEndian.INT_SIZE;  //reserved

    checksum = getChecksum();
    LittleEndian.putUShort(header, pos, checksum);

    out.write(header);
}
 
Example #9
Source File: BinaryRC4Decryptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected static Cipher initCipherForBlock(Cipher cipher, int block,
    EncryptionInfo encryptionInfo, SecretKey skey, int encryptMode)
throws GeneralSecurityException {
    EncryptionVerifier ver = encryptionInfo.getVerifier();
    HashAlgorithm hashAlgo = ver.getHashAlgorithm();
    byte blockKey[] = new byte[4];
    LittleEndian.putUInt(blockKey, 0, block);
    byte encKey[] = CryptoFunctions.generateKey(skey.getEncoded(), hashAlgo, blockKey, 16);
    SecretKey key = new SecretKeySpec(encKey, skey.getAlgorithm());
    if (cipher == null) {
        EncryptionHeader em = encryptionInfo.getHeader();
        cipher = CryptoFunctions.getCipher(key, em.getCipherAlgorithm(), null, null, encryptMode);
    } else {
        cipher.init(encryptMode, key);
    }
    return cipher;
}
 
Example #10
Source File: EscherChildAnchorRecord.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
    int bytesRemaining = readHeader( data, offset );
    int pos            = offset + 8;
    int size           = 0;
    switch (bytesRemaining) {
    case 16: // RectStruct
        field_1_dx1 =  LittleEndian.getInt( data, pos + size );size+=4;
        field_2_dy1 =  LittleEndian.getInt( data, pos + size );size+=4;
        field_3_dx2 =  LittleEndian.getInt( data, pos + size );size+=4;
        field_4_dy2 =  LittleEndian.getInt( data, pos + size );size+=4;
        break;
    case 8: // SmallRectStruct
        field_1_dx1 =  LittleEndian.getShort( data, pos + size );size+=2;
        field_2_dy1 =  LittleEndian.getShort( data, pos + size );size+=2;
        field_3_dx2 =  LittleEndian.getShort( data, pos + size );size+=2;
        field_4_dy2 =  LittleEndian.getShort( data, pos + size );size+=2;
        break;
    default:
        throw new RuntimeException("Invalid EscherChildAnchorRecord - neither 8 nor 16 bytes.");
    }
        
    return 8 + size;
}
 
Example #11
Source File: StandardDecryptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver, int keySize) {
    HashAlgorithm hashAlgo = ver.getHashAlgorithm();

    byte pwHash[] = hashPassword(password, hashAlgo, ver.getSalt(), ver.getSpinCount());

    byte[] blockKey = new byte[4];
    LittleEndian.putInt(blockKey, 0, 0);

    byte[] finalHash = CryptoFunctions.generateKey(pwHash, hashAlgo, blockKey, hashAlgo.hashSize);
    byte x1[] = fillAndXor(finalHash, (byte) 0x36);
    byte x2[] = fillAndXor(finalHash, (byte) 0x5c);

    byte[] x3 = new byte[x1.length + x2.length];
    System.arraycopy(x1, 0, x3, 0, x1.length);
    System.arraycopy(x2, 0, x3, x1.length, x2.length);
    
    byte[] key = Arrays.copyOf(x3, keySize);

    SecretKey skey = new SecretKeySpec(key, ver.getCipherAlgorithm().jceId);
    return skey;
}
 
Example #12
Source File: EscherTextboxRecord.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int serialize( int offset, byte[] data, EscherSerializationListener listener )
{
    listener.beforeRecordSerialize( offset, getRecordId(), this );

    LittleEndian.putShort(data, offset, getOptions());
    LittleEndian.putShort(data, offset+2, getRecordId());
    int remainingBytes = thedata.length;
    LittleEndian.putInt(data, offset+4, remainingBytes);
    System.arraycopy(thedata, 0, data, offset+8, thedata.length);
    int pos = offset+8+thedata.length;

    listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this );
    int size = pos - offset;
    if (size != getRecordSize()) {
        throw new RecordFormatException(size + " bytes written but getRecordSize() reports " + getRecordSize());
    }
    return size;
}
 
Example #13
Source File: EscherSpRecord.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
     * This method serializes this escher record into a byte array.
     *
     * @param offset   The offset into <code>data</code> to start writing the record data to.
     * @param data     The byte array to serialize to.
     * @param listener A listener to retrieve start and end callbacks.  Use a <code>NullEscherSerailizationListener</code> to ignore these events.
     * @return The number of bytes written.
     *
     * @see NullEscherSerializationListener
     */
    @Override
    public int serialize( int offset, byte[] data, EscherSerializationListener listener )
    {
        listener.beforeRecordSerialize( offset, getRecordId(), this );
        LittleEndian.putShort( data, offset, getOptions() );
        LittleEndian.putShort( data, offset + 2, getRecordId() );
        int remainingBytes = 8;
        LittleEndian.putInt( data, offset + 4, remainingBytes );
        LittleEndian.putInt( data, offset + 8, field_1_shapeId );
        LittleEndian.putInt( data, offset + 12, field_2_flags );
//        System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
//        int pos = offset + 8 + 18 + remainingData.length;
        listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), getRecordSize(), this );
        return 8 + 8;
    }
 
Example #14
Source File: Formula.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets the locator for the corresponding {@link org.apache.poi.hssf.record.SharedFormulaRecord},
    * {@link org.apache.poi.hssf.record.ArrayRecord} or {@link org.apache.poi.hssf.record.TableRecord}
    * if this formula belongs to such a grouping.  The {@link CellReference}
 * returned by this method will  match the top left corner of the range of that grouping.
 * The return value is usually not the same as the location of the cell containing this formula.
 *
 * @return the firstRow &amp; firstColumn of an array formula or shared formula that this formula
 * belongs to.  <code>null</code> if this formula is not part of an array or shared formula.
 */
public CellReference getExpReference() {
	byte[] data = _byteEncoding;
	if (data.length != 5) {
		// tExp and tTbl are always 5 bytes long, and the only ptg in the formula
		return null;
	}
	switch (data[0]) {
		case ExpPtg.sid:
			break;
		case TblPtg.sid:
			break;
		default:
			return null;
	}
	int firstRow = LittleEndian.getUShort(data, 1);
	int firstColumn = LittleEndian.getUShort(data, 3);
	return new CellReference(firstRow, firstColumn);
}
 
Example #15
Source File: BiffViewer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void fillNextBuffer() throws IOException {
	if (_innerHasReachedEOF) {
		return;
	}
	int b0 = _is.read();
	if (b0 == -1) {
		_innerHasReachedEOF = true;
		return;
	}
	_data[0] = (byte) b0;
	_is.readFully(_data, 1, 3);
	int len = LittleEndian.getShort(_data, 2);
	_is.readFully(_data, 4, len);
	_currentPos = 0;
	_currentSize = len + 4;
	_recordCounter++;
}
 
Example #16
Source File: EscherSpgrRecord.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
    public int serialize( int offset, byte[] data, EscherSerializationListener listener )
    {
        listener.beforeRecordSerialize( offset, getRecordId(), this );
        LittleEndian.putShort( data, offset, getOptions() );
        LittleEndian.putShort( data, offset + 2, getRecordId() );
        int remainingBytes = 16;
        LittleEndian.putInt( data, offset + 4, remainingBytes );
        LittleEndian.putInt( data, offset + 8, field_1_rectX1 );
        LittleEndian.putInt( data, offset + 12, field_2_rectY1 );
        LittleEndian.putInt( data, offset + 16, field_3_rectX2 );
        LittleEndian.putInt( data, offset + 20, field_4_rectY2 );
//        System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
//        int pos = offset + 8 + 18 + remainingData.length;
        listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), offset + getRecordSize(), this );
        return 8 + 16;
    }
 
Example #17
Source File: AbstractEscherHolderRecord.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int serialize(int offset, byte[] data)
{
    LittleEndian.putShort( data, 0 + offset, getSid() );
    LittleEndian.putShort( data, 2 + offset, (short) ( getRecordSize() - 4 ) );
    byte[] rawData = getRawData();
    if ( escherRecords.size() == 0 && rawData != null )
    {
        LittleEndian.putShort(data, 0 + offset, getSid());
        LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
        System.arraycopy( rawData, 0, data, 4 + offset, rawData.length);
        return rawData.length + 4;
    }
    LittleEndian.putShort(data, 0 + offset, getSid());
    LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));

    int pos = offset + 4;
    for (EscherRecord r : escherRecords) {
        pos += r.serialize( pos, data, new NullEscherSerializationListener() );
    }
    return getRecordSize();
}
 
Example #18
Source File: Biff8DecryptingStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public short readShort() {
       if (shouldSkipEncryptionOnCurrentRecord) {
           readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE);
           return LittleEndian.getShort(buffer);
       } else {
           return ccis.readShort();
       }
}
 
Example #19
Source File: EscherSpRecord.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
        /*int bytesRemaining =*/ readHeader( data, offset );
        int pos            = offset + 8;
        int size           = 0;
        field_1_shapeId    =  LittleEndian.getInt( data, pos + size );     size += 4;
        field_2_flags      =  LittleEndian.getInt( data, pos + size );     size += 4;
//        bytesRemaining -= size;
//        remainingData  =  new byte[bytesRemaining];
//        System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
        return getRecordSize();
    }
 
Example #20
Source File: EscherMetafileBlip.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int serialize(int offset, byte[] data, EscherSerializationListener listener) {
    listener.beforeRecordSerialize(offset, getRecordId(), this);

    int pos = offset;
    LittleEndian.putShort( data, pos, getOptions() ); pos += 2;
    LittleEndian.putShort( data, pos, getRecordId() ); pos += 2;
    LittleEndian.putInt( data, pos, getRecordSize() - HEADER_SIZE ); pos += 4;

    System.arraycopy( field_1_UID, 0, data, pos, field_1_UID.length ); pos += field_1_UID.length;
    if ((getOptions() ^ getSignature()) == 0x10) {
        System.arraycopy( field_2_UID, 0, data, pos, field_2_UID.length ); pos += field_2_UID.length;
    }
    LittleEndian.putInt( data, pos, field_2_cb ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_x1 ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_y1 ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_x2 ); pos += 4;
    LittleEndian.putInt( data, pos, field_3_rcBounds_y2 ); pos += 4;
    LittleEndian.putInt( data, pos, field_4_ptSize_w ); pos += 4;
    LittleEndian.putInt( data, pos, field_4_ptSize_h ); pos += 4;
    LittleEndian.putInt( data, pos, field_5_cbSave ); pos += 4;
    data[pos] = field_6_fCompression; pos++;
    data[pos] = field_7_fFilter; pos++;

    System.arraycopy( raw_pictureData, 0, data, pos, raw_pictureData.length ); pos += raw_pictureData.length;
    if(remainingData != null) {
        System.arraycopy( remainingData, 0, data, pos, remainingData.length ); pos += remainingData.length;
    }

    listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this);
    return getRecordSize();
}
 
Example #21
Source File: WriteAccessRecord.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public WriteAccessRecord(RecordInputStream in) {
	if (in.remaining() > DATA_SIZE) {
		throw new RecordFormatException("Expected data size (" + DATA_SIZE + ") but got ("
				+ in.remaining() + ")");
	}
	// The string is always 112 characters (padded with spaces), therefore
	// this record can not be continued.

	int nChars = in.readUShort();
	int is16BitFlag = in.readUByte();
	if (nChars > DATA_SIZE || (is16BitFlag & 0xFE) != 0) {
		// String header looks wrong (probably missing)
		// OOO doc says this is optional anyway.
		// reconstruct data
		byte[] data = new byte[3 + in.remaining()];
		LittleEndian.putUShort(data, 0, nChars);
		LittleEndian.putByte(data, 2, is16BitFlag);
		in.readFully(data, 3, data.length-3);
		String rawValue = new String(data, StringUtil.UTF8);
		setUsername(rawValue.trim());
		return;
	}

	String rawText;
	if ((is16BitFlag & 0x01) == 0x00) {
		rawText = StringUtil.readCompressedUnicode(in, nChars);
	} else {
		rawText = StringUtil.readUnicodeLE(in, nChars);
	}
	field_1_username = rawText.trim();

	// consume padding
	int padSize = in.remaining();
	while (padSize > 0) {
		// in some cases this seems to be garbage (non spaces)
		in.readUByte();
		padSize--;
	}
}
 
Example #22
Source File: Biff8DecryptingStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads an unsigned short value without decrypting
 */
@Override
   public int readDataSize() {
       readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE);
       int dataSize = LittleEndian.getUShort(buffer, 0);
       ccis.setNextRecordSize(dataSize);
	return dataSize;
}
 
Example #23
Source File: EscherColorRef.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public EscherColorRef(byte[] source, int start, int len) {
    assert(len == 4 || len == 6);
    
    int offset = start;
    if (len == 6) {
        opid = LittleEndian.getUShort(source, offset);
        offset += 2;
    }
    colorRef = LittleEndian.getInt(source, offset);
}
 
Example #24
Source File: BiffViewer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void formatBufferIfAtEndOfRec() {
	if (_currentPos != _currentSize) {
		return;
	}
	int dataSize = _currentSize-4;
	int sid = LittleEndian.getShort(_data, 0);
	int globalOffset = _overallStreamPos-_currentSize;
	_listener.processRecord(globalOffset, _recordCounter, sid, dataSize, _data);
}
 
Example #25
Source File: EscherSplitMenuColorsRecord.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
    int bytesRemaining = readHeader( data, offset );
    int pos            = offset + 8;
    int size           = 0;
    field_1_color1 =  LittleEndian.getInt( data, pos + size );size+=4;
    field_2_color2 =  LittleEndian.getInt( data, pos + size );size+=4;
    field_3_color3 =  LittleEndian.getInt( data, pos + size );size+=4;
    field_4_color4 =  LittleEndian.getInt( data, pos + size );size+=4;
    bytesRemaining -= size;
    if (bytesRemaining != 0) {
        throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
    }
    return 8 + size + bytesRemaining;
}
 
Example #26
Source File: BATBlock.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private byte[] serialize() {
   // Create the empty array
   byte[] data = new byte[ bigBlockSize.getBigBlockSize() ];
   
   // Fill in the values
   int offset = 0;
   for(int i=0; i<_values.length; i++) {
      LittleEndian.putInt(data, offset, _values[i]);
      offset += LittleEndian.INT_SIZE;
   }
   
   // Done
   return data;
}
 
Example #27
Source File: EscherDggRecord.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
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;
    // field_2_numIdClusters = LittleEndian.getInt( data, pos + size );
    size+=4; 
    field_3_numShapesSaved =  LittleEndian.getInt( data, pos + size );size+=4;
    field_4_drawingsSaved  =  LittleEndian.getInt( data, pos + size );size+=4;
    
    field_5_fileIdClusters.clear();
    // Can't rely on field_2_numIdClusters
    int numIdClusters = (bytesRemaining-size) / 8;
    
    for (int i = 0; i < numIdClusters; i++) {
        int drawingGroupId = LittleEndian.getInt( data, pos + size );
        int numShapeIdsUsed = LittleEndian.getInt( data, pos + size + 4 );
        FileIdCluster fic = new FileIdCluster(drawingGroupId, numShapeIdsUsed);
        field_5_fileIdClusters.add(fic);
        maxDgId = Math.max(maxDgId, drawingGroupId);
        size += 8;
    }
    bytesRemaining -= size;
    if (bytesRemaining != 0) {
        throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
    }
    return 8 + size;
}
 
Example #28
Source File: EscherArrayProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serializes the simple part of this property.  ie the first 6 bytes.
 *
 * Needs special code to handle the case when the size doesn't
 *  include the size of the header block
 */
@Override
public int serializeSimplePart(byte[] data, int pos) {
    LittleEndian.putShort(data, pos, getId());
    int recordSize = getComplexData().length;
    if(!sizeIncludesHeaderSize) {
        recordSize -= 6;
    }
    LittleEndian.putInt(data, pos + 2, recordSize);
    return 6;
}
 
Example #29
Source File: HeaderBlock.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the offsets to the first (up to) 109
 *  BAT sectors.
 * Any additional BAT sectors are held in the XBAT (DIFAT)
 *  sectors in a chain.
 * @return BAT offset array
 */
public int[] getBATArray() {
     // Read them in
	int[] result = new int[ Math.min(_bat_count,_max_bats_in_header) ];
	int offset = _bat_array_offset;
	for (int j = 0; j < result.length; j++) {
		result[ j ] = LittleEndian.getInt(_data, offset);
		offset     += LittleEndianConsts.INT_SIZE;
	}
	return result;
}
 
Example #30
Source File: BoundSheetRecord.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * UTF8: sid + len + bof + flags + len(str) + unicode + str 2 + 2 + 4 + 2 +
 * 1 + 1 + len(str)
 *
 * UNICODE: sid + len + bof + flags + len(str) + unicode + str 2 + 2 + 4 + 2 +
 * 1 + 1 + 2 * len(str)
 * 
 * @param in the record stream to read from
 */
public BoundSheetRecord(RecordInputStream in) {
    byte buf[] = new byte[LittleEndianConsts.INT_SIZE];
    in.readPlain(buf, 0, buf.length);
	field_1_position_of_BOF = LittleEndian.getInt(buf);
	field_2_option_flags = in.readUShort();
	int field_3_sheetname_length = in.readUByte();
	field_4_isMultibyteUnicode = in.readByte();

	if (isMultibyte()) {
		field_5_sheetname = in.readUnicodeLEString(field_3_sheetname_length);
	} else {
		field_5_sheetname = in.readCompressedUnicode(field_3_sheetname_length);
	}
}