예제 #1
0
        private static object ReadAConstantValue(LittleEndianInput in1)
        {
            byte grbit = (byte)in1.ReadByte();

            switch (grbit)
            {
            case TYPE_EMPTY:
                in1.ReadLong();     // 8 byte 'not used' field
                return(EMPTY_REPRESENTATION);

            case TYPE_NUMBER:
                return(in1.ReadDouble());

            case TYPE_STRING:
                return(StringUtil.ReadUnicodeString(in1));

            case TYPE_BOOLEAN:
                return(ReadBoolean(in1));

            case TYPE_ERROR_CODE:
                int errCode = in1.ReadUShort();
                // next 6 bytes are Unused
                in1.ReadUShort();
                in1.ReadInt();
                return(ErrorConstant.ValueOf(errCode));
            }
            throw new Exception("Unknown grbit value (" + grbit + ")");
        }
예제 #2
0
        /**
         * Reads <tt>size</tt> bytes of the input stream, to Create an array of <tt>Ptg</tt>s.
         * Extra data (beyond <tt>size</tt>) may be Read if and <tt>ArrayPtg</tt>s are present.
         */
        public static Ptg[] ReadTokens(int size, LittleEndianInput in1)
        {
		    ArrayList temp = new ArrayList(4 + size / 2);
		    int pos = 0;
		    ArrayList arrayPtgs = null;
		    while (pos < size) {
			    Ptg ptg = Ptg.CreatePtg( in1 );
			    if (ptg is ArrayPtg) {
				    if (arrayPtgs == null) {
					    arrayPtgs = new ArrayList(5);
				    }
				    arrayPtgs.Add(ptg);
				    pos += ArrayPtg.PLAIN_TOKEN_SIZE;
			    } else {
				    pos += ptg.Size;
			    }
			    temp.Add( ptg );
		    }
		    if(pos != size) {
			    throw new Exception("Ptg array size mismatch");
		    }
		    if (arrayPtgs != null) {
			    for (int i=0;i<arrayPtgs.Count;i++) {
				    ArrayPtg p = (ArrayPtg)arrayPtgs[i];
				    p.ReadTokenValues(in1);
			    }
		    }
		    return ToPtgArray(temp);
        }
예제 #3
0
 public UnknownSubRecord(LittleEndianInput in1, int sid, int size)
 {
     _sid = sid;
     byte[] buf = new byte[size];
     in1.ReadFully(buf);
     _data = buf;
 }
예제 #4
0
 protected void ReadCoordinates(LittleEndianInput in1)
 {
     field_1_first_row    = in1.ReadUShort();
     field_2_last_row     = in1.ReadUShort();
     field_3_first_column = in1.ReadUShort();
     field_4_last_column  = in1.ReadUShort();
 }
예제 #5
0
        public static SubRecord CreateSubRecord(LittleEndianInput in1, CommonObjectType cmoOt)
        {
            int sid          = in1.ReadUShort();
            int secondUShort = in1.ReadUShort(); // Often (but not always) the datasize for the sub-record


            switch (sid)
            {
            case CommonObjectDataSubRecord.sid:
                return(new CommonObjectDataSubRecord(in1, secondUShort));

            case EmbeddedObjectRefSubRecord.sid:
                return(new EmbeddedObjectRefSubRecord(in1, secondUShort));

            case GroupMarkerSubRecord.sid:
                return(new GroupMarkerSubRecord(in1, secondUShort));

            case EndSubRecord.sid:
                return(new EndSubRecord(in1, secondUShort));

            case NoteStructureSubRecord.sid:
                return(new NoteStructureSubRecord(in1, secondUShort));

            case LbsDataSubRecord.sid:
                return(new LbsDataSubRecord(in1, secondUShort, (int)cmoOt));

            case ScrollableObjectSubRecord.sid:
                return(new ScrollableObjectSubRecord(in1, secondUShort));

            default:
                return(new UnknownSubRecord(in1, sid, secondUShort));
            }
        }
예제 #6
0
        public static Ptg CreatePtg(LittleEndianInput in1)
        {
            byte id = (byte)in1.ReadByte();

            if (id < 0x20)
            {
                return(CreateBasePtg(id, in1));
            }

            Ptg retval = CreateClassifiedPtg(id, in1);

            if (id > 0x60)
            {
                retval.PtgClass = CLASS_ARRAY;
            }
            else if (id > 0x40)
            {
                retval.PtgClass = CLASS_VALUE;
            }
            else
            {
                retval.PtgClass = CLASS_REF;
            }

            return(retval);
        }
예제 #7
0
        /**
         * Constructs a End record and Sets its fields appropriately.
         *
         * @param in the RecordInputstream to Read the record from
         */

        public EndSubRecord(LittleEndianInput in1, int size)
        {
            if ((size & 0xFF) != ENCODED_SIZE)
            { // mask out random crap in upper byte
                throw new RecordFormatException("Unexpected size (" + size + ")");
            }
        }
예제 #8
0
        public static SubRecord CreateSubRecord(LittleEndianInput in1, CommonObjectType cmoOt)
        {
            int sid = in1.ReadUShort();
            int secondUShort = in1.ReadUShort(); // Often (but not always) the datasize for the sub-record

            switch (sid)
            {
                case CommonObjectDataSubRecord.sid:
                    return new CommonObjectDataSubRecord(in1, secondUShort);
                case EmbeddedObjectRefSubRecord.sid:
                    return new EmbeddedObjectRefSubRecord(in1, secondUShort);
                case GroupMarkerSubRecord.sid:
                    return new GroupMarkerSubRecord(in1, secondUShort);
                case EndSubRecord.sid:
                    return new EndSubRecord(in1, secondUShort);
                case NoteStructureSubRecord.sid:
                    return new NoteStructureSubRecord(in1, secondUShort);
                case LbsDataSubRecord.sid:
                    return new LbsDataSubRecord(in1, secondUShort, (int)cmoOt);
                case ScrollableObjectSubRecord.sid:
                    return new ScrollableObjectSubRecord(in1, secondUShort);
                default:
                    return new UnknownSubRecord(in1, sid, secondUShort);
            }
        }
예제 #9
0
 /**
  * Constructs a End record and Sets its fields appropriately.
  *
  * @param in the RecordInputstream to Read the record from
  */
 public EndSubRecord(LittleEndianInput in1, int size)
 {
     if ((size & 0xFF) != ENCODED_SIZE)
     { // mask out random crap in upper byte
         throw new RecordFormatException("Unexpected size (" + size + ")");
     }
 }
예제 #10
0
 public static object[] Parse(LittleEndianInput in1, int nValues)
 {
     object[] result = new Object[nValues];
     for (int i = 0; i < result.Length; i++)
     {
         result.SetValue(ReadAConstantValue(in1),i);
     }
     return result;
 }
예제 #11
0
 public static object[] Parse(LittleEndianInput in1, int nValues)
 {
     object[] result = new Object[nValues];
     for (int i = 0; i < result.Length; i++)
     {
         result.SetValue(ReadAConstantValue(in1), i);
     }
     return(result);
 }
예제 #12
0
 public ArrayPtg(LittleEndianInput in1)
 {
     field_1_reserved = new byte[RESERVED_FIELD_LEN];
     // TODO - Add ReadFully method to RecordInputStream
     for (int i = 0; i < RESERVED_FIELD_LEN; i++)
     {
         field_1_reserved[i] = (byte)in1.ReadByte();
     }
 }
예제 #13
0
 public ArrayPtg(LittleEndianInput in1)
 {
     field_1_reserved = new byte[RESERVED_FIELD_LEN];
     // TODO - Add ReadFully method to RecordInputStream
     for (int i = 0; i < RESERVED_FIELD_LEN; i++)
     {
         field_1_reserved[i] = (byte)in1.ReadByte();
     }
 }
예제 #14
0
 public static String ReadUnicodeLE(LittleEndianInput in1, int nChars)
 {
     char[] buf = new char[nChars];
     for (int i = 0; i < buf.Length; i++)
     {
         buf[i] = (char)in1.ReadUShort();
     }
     return(new String(buf));
 }
 /**
  * Constructs a NoteStructureSubRecord and Sets its fields appropriately.
  *
  */
 public NoteStructureSubRecord(LittleEndianInput in1, int size)
 {
     if (size != ENCODED_SIZE) {
         throw new RecordFormatException("Unexpected size (" + size + ")");
     }
     //just grab the raw data
     byte[] buf = new byte[size];
     in1.ReadFully(buf);
     reserved = buf;
 }
예제 #16
0
        /**
         * InputStream <tt>in</tt> is expected to contain:
         * <ol>
         * <li>byte is16BitFlag</li>
         * <li>byte[]/char[] characterData</li>
         * </ol>
         * For this encoding, the is16BitFlag is always present even if nChars==0.
         * <br/>
         * This method should be used when the nChars field is <em>not</em> stored
         * as a ushort immediately before the is16BitFlag. Otherwise, {@link
         * #readUnicodeString(LittleEndianInput)} can be used.
         */
        public static String ReadUnicodeString(LittleEndianInput in1, int nChars)
        {
            byte is16Bit = (byte)in1.ReadByte();

            if ((is16Bit & 0x01) == 0)
            {
                return(ReadCompressedUnicode(in1, nChars));
            }
            return(ReadUnicodeLE(in1, nChars));
        }
예제 #17
0
        /**
         * InputStream <tt>in</tt> is expected to contain:
         * <ol>
         * <li>ushort nChars</li>
         * <li>byte is16BitFlag</li>
         * <li>byte[]/char[] characterData</li>
         * </ol>
         * For this encoding, the is16BitFlag is always present even if nChars==0.
         */
        public static String ReadUnicodeString(LittleEndianInput in1)
        {
            int  nChars = in1.ReadUShort();
            byte flag   = (byte)in1.ReadByte();

            if ((flag & 0x01) == 0)
            {
                return(ReadCompressedUnicode(in1, nChars));
            }
            return(ReadUnicodeLE(in1, nChars));
        }
예제 #18
0
 /**
  * Constructs a NoteStructureSubRecord and Sets its fields appropriately.
  *
  */
 public NoteStructureSubRecord(LittleEndianInput in1, int size)
 {
     if (size != ENCODED_SIZE)
     {
         throw new RecordFormatException("Unexpected size (" + size + ")");
     }
     //just grab the raw data
     byte[] buf = new byte[size];
     in1.ReadFully(buf);
     reserved = buf;
 }
예제 #19
0
 public LbsDropData(LittleEndianInput in1)
 {
     _wStyle = in1.ReadUShort();
     _cLine  = in1.ReadUShort();
     _dxMin  = in1.ReadUShort();
     _str    = StringUtil.ReadUnicodeString(in1);
     if (StringUtil.GetEncodedSize(_str) % 2 != 0)
     {
         _unused = (byte)in1.ReadByte();
     }
 }
예제 #20
0
        /**
         * Constructs a CommonObjectData record and Sets its fields appropriately.
         *
         * @param in the RecordInputstream to Read the record from
         */

        public CommonObjectDataSubRecord(LittleEndianInput in1, int size)
        {
            if (size != 18)
            {
                throw new RecordFormatException("Expected size 18 but got (" + size + ")");
            }
            field_1_objectType = in1.ReadShort();
            field_2_objectId   = in1.ReadShort();
            field_3_option     = in1.ReadShort();
            field_4_reserved1  = in1.ReadInt();
            field_5_reserved2  = in1.ReadInt();
            field_6_reserved3  = in1.ReadInt();
        }
예제 #21
0
 private static byte[] ReadRawData(LittleEndianInput in1, int size)
 {
     if (size < 0)
     {
         throw new ArgumentException("Negative size (" + size + ")");
     }
     if (size == 0)
     {
         return(EMPTY_BYTE_ARRAY);
     }
     byte[] result = new byte[size];
     in1.ReadFully(result);
     return(result);
 }
예제 #22
0
        /** Create a StringPtg from a stream */
        public StringPtg(LittleEndianInput in1)
        {
            int field_1_length = in1.ReadUByte();
			field_2_options = (byte)in1.ReadByte();
            _is16bitUnicode = (field_2_options & 0x01) != 0;
            if (_is16bitUnicode)
            {
                field_3_string = StringUtil.ReadUnicodeLE(in1, field_1_length);
            }
            else
            {
                field_3_string = StringUtil.ReadCompressedUnicode(in1, field_1_length);
            }
        }
예제 #23
0
        /**Creates new function pointer from a byte array
         * usually called while Reading an excel file.
         */
        public FuncPtg(LittleEndianInput in1)
        {
            //field_1_num_args = data[ offset + 0 ];
            field_2_fnc_index = in1.ReadShort();

            FunctionMetadata fm = FunctionMetadataRegistry.GetFunctionByIndex(field_2_fnc_index);
            if (fm == null)
            {
                throw new Exception("Invalid built-in function index (" + field_2_fnc_index + ")");
            }
            numParams = fm.MinParams;
            returnClass = fm.ReturnClassCode;
            paramClass = fm.ParameterClassCodes;
        }
예제 #24
0
        private static Object ReadBoolean(LittleEndianInput in1)
        {
            byte val = (byte)in1.ReadLong(); // 7 bytes 'not used'

            switch (val)
            {
            case FALSE_ENCODING:
                return(false);

            case TRUE_ENCODING:
                return(true);
            }
            // Don't tolerate Unusual bool encoded values (unless it becomes evident that they occur)
            throw new Exception("unexpected bool encoding (" + val + ")");
        }
        public Biff8DecryptingStream(Stream in1, int InitialOffSet, Biff8EncryptionKey key)
        {
            _rc4 = new Biff8RC4(InitialOffSet, key);

            if (in1 is LittleEndianInput)
            {
                // accessing directly is an optimisation
                _le = (LittleEndianInput)in1;
            }
            else
            {
                // less optimal, but should work OK just the same. Often occurs in junit tests.
                _le = new LittleEndianInputStream(in1);
            }
        }
예제 #26
0
 public RecordInputStream(Stream in1, Biff8EncryptionKey key, int initialOffset)
 {
     if (key == null)
     {
         _dataInput = SimpleHeaderInput.GetLEI(in1);
         _bhi       = new SimpleHeaderInput(in1);
     }
     else
     {
         Biff8DecryptingStream bds = new Biff8DecryptingStream(in1, initialOffset, key);
         _bhi       = bds;
         _dataInput = bds;
     }
     _nextSid = ReadNextSid();
 }
예제 #27
0
파일: FuncPtg.cs 프로젝트: thinhmascot/NPOI
        /**Creates new function pointer from a byte array
         * usually called while Reading an excel file.
         */
        public FuncPtg(LittleEndianInput in1)
        {
            //field_1_num_args = data[ offset + 0 ];
            field_2_fnc_index = in1.ReadShort();

            FunctionMetadata fm = FunctionMetadataRegistry.GetFunctionByIndex(field_2_fnc_index);

            if (fm == null)
            {
                throw new Exception("Invalid built-in function index (" + field_2_fnc_index + ")");
            }
            numParams   = fm.MinParams;
            returnClass = fm.ReturnClassCode;
            paramClass  = fm.ParameterClassCodes;
        }
예제 #28
0
        /**
         * @param ris the RecordInputstream to read the record from
         */
        public NameCommentRecord(RecordInputStream ris)
        {
            LittleEndianInput in1 = ris;

            field_1_record_type       = in1.ReadShort();
            field_2_frt_cell_ref_flag = in1.ReadShort();
            field_3_reserved          = in1.ReadLong();
            int field_4_name_length    = in1.ReadShort();
            int field_5_comment_length = in1.ReadShort();

            in1.ReadByte(); //spurious NUL
            field_6_name_text = StringUtil.ReadCompressedUnicode(in1, field_4_name_length);
            in1.ReadByte(); //spurious NUL
            field_7_comment_text = StringUtil.ReadCompressedUnicode(in1, field_5_comment_length);
        }
예제 #29
0
        /** Create a StringPtg from a stream */
        public StringPtg(LittleEndianInput in1)
        {
            int field_1_length = in1.ReadUByte();

            field_2_options = (byte)in1.ReadByte();
            _is16bitUnicode = (field_2_options & 0x01) != 0;
            if (_is16bitUnicode)
            {
                field_3_string = StringUtil.ReadUnicodeLE(in1, field_1_length);
            }
            else
            {
                field_3_string = StringUtil.ReadCompressedUnicode(in1, field_1_length);
            }
        }
예제 #30
0
        public Biff8DecryptingStream(Stream in1, int InitialOffSet, Biff8EncryptionKey key)
        {
            _rc4 = new Biff8RC4(InitialOffSet, key);

            if (in1 is LittleEndianInput)
            {
                // accessing directly is an optimisation
                _le = (LittleEndianInput)in1;
            }
            else
            {
                // less optimal, but should work OK just the same. Often occurs in junit tests.
                _le = new LittleEndianInputStream(in1);
            }
        }
 public ScrollableObjectSubRecord(LittleEndianInput in1, int size)
 {
     if (size !=this.DataSize)
     {
         throw new RecordFormatException(string.Format("Expected size {0} but got ({1})",this.DataSize,size));
     }
     in1.ReadInt();
     field_1_iVal=in1.ReadShort();
     field_2_iMin=in1.ReadShort();
     field_3_iMax=in1.ReadShort();
     field_4_dInc=in1.ReadShort();
     field_5_dPage=in1.ReadShort();
     field_6_fHoriz = in1.ReadShort();
     field_7_dxScroll = in1.ReadShort();
     field_8_options = in1.ReadShort();
 }
예제 #32
0
 public ScrollableObjectSubRecord(LittleEndianInput in1, int size)
 {
     if (size != this.DataSize)
     {
         throw new RecordFormatException(string.Format("Expected size {0} but got ({1})", this.DataSize, size));
     }
     in1.ReadInt();
     field_1_iVal     = in1.ReadShort();
     field_2_iMin     = in1.ReadShort();
     field_3_iMax     = in1.ReadShort();
     field_4_dInc     = in1.ReadShort();
     field_5_dPage    = in1.ReadShort();
     field_6_fHoriz   = in1.ReadShort();
     field_7_dxScroll = in1.ReadShort();
     field_8_options  = in1.ReadShort();
 }
예제 #33
0
 private static byte[] ReadTail(byte[] expectedTail, LittleEndianInput in1)
 {
     byte[] result = new byte[TAIL_SIZE];
     in1.ReadFully(result);
     //if (false)
     //{ // Quite a few examples in the unit tests which don't have the exact expected tail
     //    for (int i = 0; i < expectedTail.Length; i++)
     //    {
     //        if (expectedTail[i] != result[i])
     //        {
     //            Console.WriteLine("Mismatch in tail byte [" + i + "]"
     //                    + "expected " + (expectedTail[i] & 0xFF) + " but got " + (result[i] & 0xFF));
     //        }
     //    }
     //}
     return(result);
 }
예제 #34
0
 /**Creates new function pointer from a byte array
  * usually called while Reading an excel file.
  */
 public FuncVarPtg(LittleEndianInput in1)
 {
     field_1_num_args = (byte)in1.ReadByte();
     field_2_fnc_index = in1.ReadShort();
     FunctionMetadata fm = FunctionMetadataRegistry.GetFunctionByIndex(field_2_fnc_index);
     if (fm == null)
     {
         // Happens only as a result of a call to FormulaParser.Parse(), with a non-built-in function name
         returnClass = Ptg.CLASS_VALUE;
         paramClass = new byte[] { Ptg.CLASS_VALUE };
     }
     else
     {
         returnClass = fm.ReturnClassCode;
         paramClass = fm.ParameterClassCodes;
     }
 }
예제 #35
0
        private static Ptg CreateClassifiedPtg(byte id, LittleEndianInput in1)
        {
            int baseId = id & 0x1F | 0x20;

            switch (baseId)
            {
            case ArrayPtg.sid: return(new ArrayPtg(in1));                 // 0x20, 0x40, 0x60

            case FuncPtg.sid: return(new FuncPtg(in1));                   // 0x21, 0x41, 0x61

            case FuncVarPtg.sid: return(new FuncVarPtg(in1));             // 0x22, 0x42, 0x62

            case NamePtg.sid: return(new NamePtg(in1));                   // 0x23, 0x43, 0x63

            case RefPtg.sid: return(new RefPtg(in1));                     // 0x24, 0x44, 0x64

            case AreaPtg.sid: return(new AreaPtg(in1));                   // 0x25, 0x45, 0x65

            case MemAreaPtg.sid: return(new MemAreaPtg(in1));             // 0x26, 0x46, 0x66

            case MemErrPtg.sid: return(new MemErrPtg(in1));               // 0x27, 0x47, 0x67

            case MemFuncPtg.sid: return(new MemFuncPtg(in1));             // 0x29, 0x49, 0x69

            case RefErrorPtg.sid: return(new RefErrorPtg(in1));           // 0x2a, 0x4a, 0x6a

            case AreaErrPtg.sid: return(new AreaErrPtg(in1));             // 0x2b, 0x4b, 0x6b

            case RefNPtg.sid: return(new RefNPtg(in1));                   // 0x2c, 0x4c, 0x6c

            case AreaNPtg.sid: return(new AreaNPtg(in1));                 // 0x2d, 0x4d, 0x6d

            case NameXPtg.sid: return(new NameXPtg(in1));                 // 0x39, 0x49, 0x79

            case Ref3DPtg.sid: return(new Ref3DPtg(in1));                 // 0x3a, 0x5a, 0x7a

            case Area3DPtg.sid: return(new Area3DPtg(in1));               // 0x3b, 0x5b, 0x7b

            case DeletedRef3DPtg.sid: return(new DeletedRef3DPtg(in1));   // 0x3c, 0x5c, 0x7c

            case DeletedArea3DPtg.sid: return(new DeletedArea3DPtg(in1)); // 0x3d, 0x5d, 0x7d
            }
            throw new InvalidOperationException(" Unknown Ptg in Formula: 0x" +
                                                StringUtil.ToHexString(id) + " (" + (int)id + ")");
        }
예제 #36
0
        /**Creates new function pointer from a byte array
         * usually called while Reading an excel file.
         */
        public FuncVarPtg(LittleEndianInput in1)
        {
            field_1_num_args  = (byte)in1.ReadByte();
            field_2_fnc_index = in1.ReadShort();
            FunctionMetadata fm = FunctionMetadataRegistry.GetFunctionByIndex(field_2_fnc_index);

            if (fm == null)
            {
                // Happens only as a result of a call to FormulaParser.Parse(), with a non-built-in function name
                returnClass = Ptg.CLASS_VALUE;
                paramClass  = new byte[] { Ptg.CLASS_VALUE };
            }
            else
            {
                returnClass = fm.ReturnClassCode;
                paramClass  = fm.ParameterClassCodes;
            }
        }
예제 #37
0
        /**
         * Read in the actual token (array) values. This occurs
         * AFTER the last Ptg in the expression.
         * See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf
         */
        public void ReadTokenValues(LittleEndianInput in1)
        {
            short nColumns = (short)in1.ReadUByte();
            short nRows    = in1.ReadShort();

            //The token_1_columns and token_2_rows do not follow the documentation.
            //The number of physical rows and columns is actually +1 of these values.
            //Which is not explicitly documented.
            nColumns++;
            nRows++;

            token_1_columns = nColumns;
            token_2_rows    = nRows;

            int totalCount = nRows * nColumns;

            token_3_arrayValues = ConstantValueParser.Parse(in1, totalCount);
        }
예제 #38
0
 public AttrPtg(LittleEndianInput in1)
 {
     field_1_options = (byte)in1.ReadByte();
     field_2_data    = in1.ReadShort();
     if (IsOptimizedChoose)
     {
         int   nCases    = field_2_data;
         int[] jumpTable = new int[nCases];
         for (int i = 0; i < jumpTable.Length; i++)
         {
             jumpTable[i] = in1.ReadUShort();
         }
         _jumpTable        = jumpTable;
         _chooseFuncOffset = in1.ReadUShort();
     }
     else
     {
         _jumpTable        = null;
         _chooseFuncOffset = -1;
     }
 }
예제 #39
0
파일: AttrPtg.cs 프로젝트: babywzazy/Server
 public AttrPtg(LittleEndianInput in1)
 {
     field_1_options =(byte)in1.ReadByte();
     field_2_data = in1.ReadShort();
     if (IsOptimizedChoose)
     {
         int nCases = field_2_data;
         int[] jumpTable = new int[nCases];
         for (int i = 0; i < jumpTable.Length; i++)
         {
             jumpTable[i] = in1.ReadUShort();
         }
         _jumpTable = jumpTable;
         _chooseFuncOffset = in1.ReadUShort();
     }
     else
     {
         _jumpTable = null;
         _chooseFuncOffset = -1;
     }
 }
예제 #40
0
        /**
         * Reads <tt>size</tt> bytes of the input stream, to Create an array of <tt>Ptg</tt>s.
         * Extra data (beyond <tt>size</tt>) may be Read if and <tt>ArrayPtg</tt>s are present.
         */
        public static Ptg[] ReadTokens(int size, LittleEndianInput in1)
        {
            ArrayList temp      = new ArrayList(4 + size / 2);
            int       pos       = 0;
            ArrayList arrayPtgs = null;

            while (pos < size)
            {
                Ptg ptg = Ptg.CreatePtg(in1);
                if (ptg is ArrayPtg)
                {
                    if (arrayPtgs == null)
                    {
                        arrayPtgs = new ArrayList(5);
                    }
                    arrayPtgs.Add(ptg);
                    pos += ArrayPtg.PLAIN_TOKEN_SIZE;
                }
                else
                {
                    pos += ptg.Size;
                }
                temp.Add(ptg);
            }
            if (pos != size)
            {
                throw new Exception("Ptg array size mismatch");
            }
            if (arrayPtgs != null)
            {
                for (int i = 0; i < arrayPtgs.Count; i++)
                {
                    ArrayPtg p = (ArrayPtg)arrayPtgs[i];
                    p.ReadTokenValues(in1);
                }
            }
            return(ToPtgArray(temp));
        }
예제 #41
0
 private static object ReadAConstantValue(LittleEndianInput in1)
 {
     byte grbit = (byte)in1.ReadByte();
     switch (grbit)
     {
         case TYPE_EMPTY:
             in1.ReadLong(); // 8 byte 'not used' field
             return EMPTY_REPRESENTATION;
         case TYPE_NUMBER:
             return in1.ReadDouble();
         case TYPE_STRING:
             return StringUtil.ReadUnicodeString(in1);
         case TYPE_BOOLEAN:
             return ReadBoolean(in1);
         case TYPE_ERROR_CODE:
             int errCode = in1.ReadUShort();
             // next 6 bytes are Unused
             in1.ReadUShort();
             in1.ReadInt();
             return ErrorConstant.ValueOf(errCode);
     }
     throw new Exception("Unknown grbit value (" + grbit + ")");
 }
예제 #42
0
        /**
         * Constructs an EmbeddedObjectRef record and Sets its fields appropriately.
         *
         * @param in the record input stream.
         */
        public EmbeddedObjectRefSubRecord(LittleEndianInput in1, int size)
        {
            // Much guess-work going on here due to lack of any documentation.
            // See similar source code in OOO:
            // http://lxr.go-oo.org/source/sc/sc/source/filter/excel/xiescher.cxx
            // 1223 void XclImpOleObj::ReadPictFmla( XclImpStream& rStrm, sal_uInt16 nRecSize )

            int streamIdOffset = in1.ReadShort(); // OOO calls this 'nFmlaLen'
            int remaining      = size - LittleEndianConstants.SHORT_SIZE;

            int dataLenAfterFormula = remaining - streamIdOffset;
            int formulaSize         = in1.ReadUShort();

            remaining          -= LittleEndianConstants.SHORT_SIZE;
            field_1_unknown_int = in1.ReadInt();
            remaining          -= LittleEndianConstants.INT_SIZE;
            byte[] formulaRawBytes = ReadRawData(in1, formulaSize);
            remaining     -= formulaSize;
            field_2_refPtg = ReadRefPtg(formulaRawBytes);
            if (field_2_refPtg == null)
            {
                // common case
                // field_2_n16 seems to be 5 here
                // The formula almost looks like tTbl but the row/column values seem like garbage.
                field_2_unknownFormulaData = formulaRawBytes;
            }
            else
            {
                field_2_unknownFormulaData = null;
            }


            int stringByteCount;

            if (remaining >= dataLenAfterFormula + 3)
            {
                int tag = in1.ReadByte();
                stringByteCount = LittleEndianConstants.BYTE_SIZE;
                if (tag != 0x03)
                {
                    throw new RecordFormatException("Expected byte 0x03 here");
                }
                int nChars = in1.ReadUShort();
                stringByteCount += LittleEndianConstants.SHORT_SIZE;
                if (nChars > 0)
                {
                    // OOO: the 4th way Xcl stores a unicode string: not even a Grbit byte present if Length 0
                    field_3_unicode_flag = (in1.ReadByte() & 0x01) != 0;
                    stringByteCount     += LittleEndianConstants.BYTE_SIZE;
                    if (field_3_unicode_flag)
                    {
                        field_4_ole_classname = StringUtil.ReadUnicodeLE(in1, nChars);
                        stringByteCount      += nChars * 2;
                    }
                    else
                    {
                        field_4_ole_classname = StringUtil.ReadCompressedUnicode(in1, nChars);
                        stringByteCount      += nChars;
                    }
                }
                else
                {
                    field_4_ole_classname = "";
                }
            }
            else
            {
                field_4_ole_classname = null;
                stringByteCount       = 0;
            }
            remaining -= stringByteCount;
            // Pad to next 2-byte boundary
            if (((stringByteCount + formulaSize) % 2) != 0)
            {
                int b = in1.ReadByte();
                remaining -= LittleEndianConstants.BYTE_SIZE;
                if (field_2_refPtg != null && field_4_ole_classname == null)
                {
                    field_4_unknownByte = (byte)b;
                }
            }
            int nUnexpectedPadding = remaining - dataLenAfterFormula;

            if (nUnexpectedPadding > 0)
            {
                Console.WriteLine("Discarding " + nUnexpectedPadding + " unexpected padding bytes ");
                ReadRawData(in1, nUnexpectedPadding);
                remaining -= nUnexpectedPadding;
            }

            // Fetch the stream ID
            if (dataLenAfterFormula >= 4)
            {
                field_5_stream_id = in1.ReadInt();
                remaining        -= LittleEndianConstants.INT_SIZE;
            }
            else
            {
                field_5_stream_id = null;
            }

            field_6_unknown = ReadRawData(in1, remaining);
        }
예제 #43
0
 public HWPFStream(Stream stream)
 {
     _le = new LittleEndianInputStream(stream);
 }
예제 #44
0
        /** 
         * Read in the actual token (array) values. This occurs 
         * AFTER the last Ptg in the expression.
         * See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf
         */
        public void ReadTokenValues(LittleEndianInput in1)
        {
            short nColumns = (short)in1.ReadUByte();
            short nRows = in1.ReadShort();
            //The token_1_columns and token_2_rows do not follow the documentation.
            //The number of physical rows and columns is actually +1 of these values.
            //Which is not explicitly documented.
            nColumns++;
            nRows++;

            token_1_columns = nColumns;
            token_2_rows = nRows;

            int totalCount = nRows * nColumns;
            token_3_arrayValues = ConstantValueParser.Parse(in1, totalCount);
        }
예제 #45
0
        /**Creates new function pointer from a byte array
         * usually called while Reading an excel file.
         */
        public MemFuncPtg(LittleEndianInput in1)
            : this(in1.ReadUShort())
        {

        }
예제 #46
0
 public SimpleHeaderInput(Stream in1)
 {
     _lei = GetLEI(in1);
 }
예제 #47
0
 public static String ReadUnicodeLE(LittleEndianInput in1, int nChars)
 {
     char[] buf = new char[nChars];
     for (int i = 0; i < buf.Length; i++)
     {
         buf[i] = (char)in1.ReadUShort();
     }
     return new String(buf);
 }
예제 #48
0
 /**
  * InputStream <tt>in</tt> is expected to contain:
  * <ol>
  * <li>byte is16BitFlag</li>
  * <li>byte[]/char[] characterData</li>
  * </ol>
  * For this encoding, the is16BitFlag is always present even if nChars==0.
  * <br/>
  * This method should be used when the nChars field is <em>not</em> stored 
  * as a ushort immediately before the is16BitFlag. Otherwise, {@link 
  * #readUnicodeString(LittleEndianInput)} can be used. 
  */
 public static String ReadUnicodeString(LittleEndianInput in1, int nChars)
 {
     byte is16Bit = (byte)in1.ReadByte();
     if ((is16Bit & 0x01) == 0)
     {
         return ReadCompressedUnicode(in1, nChars);
     }
     return ReadUnicodeLE(in1, nChars);
 }
예제 #49
0
 private static byte[] ReadTail(byte[] expectedTail, LittleEndianInput in1)
 {
     byte[] result = new byte[TAIL_SIZE];
     in1.ReadFully(result);
     //if (false)
     //{ // Quite a few examples in the unit tests which don't have the exact expected tail
     //    for (int i = 0; i < expectedTail.Length; i++)
     //    {
     //        if (expectedTail[i] != result[i])
     //        {
     //            Console.WriteLine("Mismatch in tail byte [" + i + "]"
     //                    + "expected " + (expectedTail[i] & 0xFF) + " but got " + (result[i] & 0xFF));
     //        }
     //    }
     //}
     return result;
 }
예제 #50
0
 public RefPtg(LittleEndianInput in1)
     : base(in1)
 {
 }
예제 #51
0
파일: NamePtg.cs 프로젝트: babywzazy/Server
 /** Creates new NamePtg */
 public NamePtg(LittleEndianInput in1)
 {
     field_1_label_index = in1.ReadShort();
     field_2_zero = in1.ReadShort();
 }
예제 #52
0
        /**
         * InputStream <tt>in</tt> is expected to contain:
         * <ol>
         * <li>ushort nChars</li>
         * <li>byte is16BitFlag</li>
         * <li>byte[]/char[] characterData</li>
         * </ol>
         * For this encoding, the is16BitFlag is always present even if nChars==0.
         */
        public static String ReadUnicodeString(LittleEndianInput in1)
        {

            int nChars = in1.ReadUShort();
            byte flag = (byte)in1.ReadByte();
            if ((flag & 0x01) == 0)
            {
                return ReadCompressedUnicode(in1, nChars);
            }
            return ReadUnicodeLE(in1, nChars);
        }
예제 #53
0
 /** Creates new DeletedRef3DPtg */
 public DeletedRef3DPtg(LittleEndianInput in1)
 {
     field_1_index_extern_sheet = in1.ReadUShort();
     unused1 = in1.ReadInt();
 }
예제 #54
0
 public RecordInputStream(Stream in1, Biff8EncryptionKey key, int initialOffset)
 {
     if (key == null)
     {
         _dataInput = SimpleHeaderInput.GetLEI(in1);
         _bhi = new SimpleHeaderInput(in1);
     }
     else
     {
         Biff8DecryptingStream bds = new Biff8DecryptingStream(in1, initialOffset, key);
         _bhi = bds;
         _dataInput = bds;
     }
     _nextSid = ReadNextSid();
 }
예제 #55
0
 public Ref3DPtg(LittleEndianInput in1)
 {
     field_1_index_extern_sheet = in1.ReadShort();
     ReadCoordinates(in1);
 }
예제 #56
0
 public AreaErrPtg(LittleEndianInput in1)
 {
     // 8 bytes unused:
     unused1 = in1.ReadInt();
     unused2 = in1.ReadInt();
 }
예제 #57
0
 /** Create a NumberPtg from a byte array Read from disk */
 public NumberPtg(LittleEndianInput in1)
 {
     field_1_value = in1.ReadDouble();
 }
예제 #58
0
 protected Ref2DPtgBase(LittleEndianInput in1)
 {
     ReadCoordinates(in1);
 }
예제 #59
0
        public RefPtg(LittleEndianInput in1)
            : base(in1)
        {

        }
예제 #60
0
        /** Creates new MemErrPtg */

        public MemErrPtg(LittleEndianInput in1)
            : base(in1)
        {
        
        }