Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static List<Record> GetAll(Bytes stream)
        {
            int i = 0;
            List<Record> records = new List<Record>();
            Record lastNonContinue = Record.Empty;
            while (i < (stream.Length - 4))
            {
                byte[] rid = org.in2bits.MyXls.RID.ByteArray(stream.Get(i, 2).ByteArray);
                Bytes data = new Bytes();
                if (rid == MyXls.RID.Empty)
                    break;
                int length = BitConverter.ToUInt16(stream.Get(i + 2, 2).ByteArray, 0);
                data = stream.Get(i + 4, length);
                Record record = new Record(rid, data);
                i += (4 + length);
                if (rid == MyXls.RID.CONTINUE)
                {
                    if (lastNonContinue == Record.Empty)
                        throw new Exception("Found CONTINUE record without previous/parent record.");

                    lastNonContinue.Continues.Add(record);
                }
                else
                {
                    lastNonContinue = record;
                    records.Add(record);
                }
            }

            return records;
        }
Exemplo n.º 2
0
 public void AppendBytesObject()
 {
     Bytes bytes = new Bytes(new byte[] { sixteenBytes[0], sixteenBytes[1] });
     bytes.Append(new Bytes(new byte[] { sixteenBytes[2], sixteenBytes[3] }));
     Assert.AreEqual(4, bytes.Length);
     Assert.IsFalse(bytes.IsArray);
 }
Exemplo n.º 3
0
 public void ConvertArrayToList()
 {
     Bytes bytes = new Bytes(new byte[] { sixteenBytes[0], sixteenBytes[1] });
     Assert.IsTrue(bytes.IsArray);
     bytes.Append(new byte[] { sixteenBytes[2], sixteenBytes[3] });
     Assert.IsFalse(bytes.IsArray);
 }
Exemplo n.º 4
0
 public void Instantiate()
 {
     Bytes bytes = new Bytes();
     Assert.IsTrue(bytes.IsEmpty);
     Assert.IsFalse(bytes.IsArray);
     Assert.IsNull(bytes._bytesList);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the Bytes class containing the same bytes as the
 /// provided Bytes object.
 /// </summary>
 /// <param name="bytes">Bytes class to initialize this Bytes instance.</param>
 public Bytes(Bytes bytes)
     : this()
 {
     CheckNewLength(bytes);
     _bytesList = new List<Bytes>();
     _bytesList.Add(bytes);
     _length = bytes.Length;
 }
Exemplo n.º 6
0
 public void GetByteArrayMultipleTimes()
 {
     byte[] a = new byte[]{0x01, 0x02};
     Bytes bytes = new Bytes(a);
     bytes.Append(new byte[] {0x03, 0x04, 0x05, 0x06});
     bytes.Append(new byte[] {0x07});
     Assert.AreEqual(7, bytes.ByteArray.Length);
     Assert.AreEqual(7, bytes.ByteArray.Length);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the Bits class from the given Bytes.
 /// </summary>
 /// <param name="bytes">The Bytes whose bits this Bits object will represent.</param>
 public Bits(Bytes bytes)
 {
     byte[] byteArray = bytes.ByteArray;
     _bits = new bool[byteArray.Length * 8];
     for (byte i = 0; i < byteArray.Length; i++)
     {
         SetBits(i, byteArray[i]);
     }
 }
Exemplo n.º 8
0
 internal Record(byte[] rid, Bytes data)
 {
     _rid = org.in2bits.MyXls.RID.ByteArray(rid);
     int offset = 0;
     int bytesRemaining = data.Length;
     int continueIndex = -1;
     while (bytesRemaining > 0)
     {
         int bytesToAppend = Math.Min(bytesRemaining, BIFF8.MaxDataBytesPerRecord);
         Bytes target;
         if (continueIndex == -1)
             _data = data.Get(offset, bytesToAppend);
         else
             _continues.Add(new Record(MyXls.RID.CONTINUE, data.Get(offset, bytesToAppend)));
         offset += bytesToAppend;
         bytesRemaining -= bytesToAppend;
         continueIndex++;
     }
 }
Exemplo n.º 9
0
        public void Test_Get()
        {
            Bytes bytes = new Bytes();

            Bytes newBytes = new Bytes();
            newBytes.Append(new byte[] { sixteenBytes[0], sixteenBytes[1] });
            newBytes.Append(new byte[] { sixteenBytes[2], sixteenBytes[3] });
            bytes.Append(newBytes);

            bytes.Append(new Bytes(new byte[] { sixteenBytes[4], sixteenBytes[5] }));

            newBytes = new Bytes();
            newBytes.Append(new byte[] { sixteenBytes[6], sixteenBytes[7], sixteenBytes[8] });
            newBytes.Append(new byte[] { sixteenBytes[9] });
            bytes.Append(newBytes);

            newBytes = new Bytes();
            newBytes.Append(new Bytes(new byte[] { sixteenBytes[10] }));
            newBytes.Append(new Bytes(new byte[] { sixteenBytes[11] }));
            bytes.Append(newBytes);

            newBytes = new Bytes();
            newBytes.Append(new Bytes(new byte[] { sixteenBytes[12] }));
            newBytes.Append(new Bytes(new byte[] { sixteenBytes[13], sixteenBytes[14] }));
            newBytes.Append(new Bytes(new byte[] { sixteenBytes[15] }));
            bytes.Append(newBytes);

            AssertArraysAreEqual(bytes.ByteArray, sixteenBytes);

            for (int offset = 0; offset < 16; offset++)
            {
                for (int length = 0; length <= (16 - offset); length++)
                {
                    AssertArraysAreEqual(Bytes.MidByteArray(sixteenBytes, offset, length), bytes.Get(offset, length).ByteArray);
                }
            }
        }
Exemplo n.º 10
0
 internal static void Write(string text, Bytes bytes)
 {
     ushort offset = 0;
     Write(text, bytes, ref offset);
 }
Exemplo n.º 11
0
        private Bytes WINDOW2()
        {
            Bytes window2 = new Bytes();

            //TODO: Implement options - excelfileformat.pdf pp.210-211
            if (_doc.Workbook.Worksheets.GetIndex(Name) == 0) //NOTE: This was == 1, but the base of the worksheets collection must have changed
                window2.Append(new byte[] { 0xB6, 0x06 });
            else
                window2.Append(new byte[] { 0xB6, 0x04 });
            window2.Append(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });

            return Record.GetBytes(RID.WINDOW2, window2);
        }
Exemplo n.º 12
0
        private Bytes INDEX(int baseLength)
        {
            Bytes index = new Bytes();

            //Not used
            index.Append(new byte[] { 0x00, 0x00, 0x00, 0x00 });

            //Index to first used row (0-based)
            index.Append(BitConverter.GetBytes(_rows.MinRow - 1));

            //Index to first row of unused tail of sheet(last row + 1, 0-based)
            index.Append(BitConverter.GetBytes(_rows.MaxRow));

            //Absolute stream position of the DEFCOLWIDTH record
            //TODO: Implement Worksheet.INDEX Absolute stream position of the DEFCOLWIDTH record (not necessary)
            index.Append(BitConverter.GetBytes((uint)0));

            for (int i = 1; i < _dbCellOffsets.Length; i++)
                index.Append(BitConverter.GetBytes((uint)(baseLength + _dbCellOffsets[i])));

            return Record.GetBytes(RID.INDEX, index);
        }
Exemplo n.º 13
0
 public void WithNullBytes_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => Bytes.Split(2, null));
 }
Exemplo n.º 14
0
        private static Bytes GetShortSectorBytes(Bytes fromShortSectorStream, int shortSectorSize, int sid)
        {
            int i = (int) Math.Pow(2, shortSectorSize);

            if (fromShortSectorStream.Length < (sid * i))
                throw new Exception(string.Format("Invalid SID [{0}] (EOF reached)", sid));

            //	        return fromShortSectorStream.Get((sid * i) + 1, i);
            return fromShortSectorStream.Get(sid * i, i);
        }
Exemplo n.º 15
0
 public void WithValidBytes_ReturnsTrimEndValue()
 {
     Assert.AreEqual(new byte[] { 21, 205, 91 }, Bytes.TrimEnd(7), "Get TrimEnd value");
 }
Exemplo n.º 16
0
 public void WithValidBytes_ReturnsTrimStartValue()
 {
     Assert.AreEqual(new byte[] { 205, 91, 7 }, Bytes.TrimStart(21), "Get TrimStart value");
 }
Exemplo n.º 17
0
 public void WithValidBytes_ReturnsTrimValue()
 {
     Assert.AreEqual(new byte[] { 21, 205, 91, 7 }, Bytes.Trim(205), "Get Trim value");
 }
Exemplo n.º 18
0
 public void WithValidBytes_ReturnsArray()
 {
     Assert.AreEqual(Bytes, Bytes.DeepClone(), "Get DeepClone value");
 }
Exemplo n.º 19
0
        public void WithSequenceLongerThanBuffer_ReturnsNegativeOne()
        {
            var bytes = BitConverter.GetBytes(4815162342);

            Assert.AreEqual(-1, Bytes.GetIndexOf(bytes), "Get index of empty array is -1");
        }
Exemplo n.º 20
0
 public void WithNullSequence_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => Bytes.GetIndexOf(null));
 }
Exemplo n.º 21
0
 public void WithValidBytes_ReturnsNegativeOne()
 {
     Assert.AreEqual(-1, Bytes.GetIndexOf(new byte[0]), "Get index of empty array is -1");
 }
Exemplo n.º 22
0
        private static Bytes GetBytesLPSTR(object value)
        {
            Bytes lpstr = new Bytes();

            string theString = value as string;
            Encoder encoder = Encoding.UTF8.GetEncoder();
            char[] theChars = theString.ToCharArray();
            int paddedLength = theChars.Length + 1; //add one for terminating null
            paddedLength += (paddedLength % 4); //must be multiple of 4
            byte[] bytes = new byte[paddedLength];
            encoder.GetBytes(theChars, 0, theChars.Length, bytes, 0, true);
            lpstr.Append(BitConverter.GetBytes((uint) paddedLength));
            lpstr.Append(bytes);

            return lpstr;
        }
Exemplo n.º 23
0
        private static Bytes ROW(Row row)
        {
            Bytes bytes = new Bytes();

            //Index of this row
            bytes.Append(BitConverter.GetBytes((ushort)(row.RowIndex - 1)));

            //Index to column of the first cell which is described by a cell record
            bytes.Append(BitConverter.GetBytes((ushort)(row.MinCellCol - 1)));

            //Index to column of the last cell which is described by a cell record, + 1
            bytes.Append(BitConverter.GetBytes(row.MaxCellCol));

            //Height of row in twips, custom row height indicator
            //TODO: Implement Row height and custom height indicators (excelfileformat.pdf p.190)
            bytes.Append(new byte[] {0x08, 0x01});

            //Not used
            bytes.Append(new byte[] {0x00, 0x00});

            //Not used anymore in BIFF8 (DBCELL instead)
            bytes.Append(new byte[] {0x00, 0x00});

            //Option flags and default row formatting
            //TODO: Implement Row option flags and default row formatting (excelfileformat.pdf p.190)
            bytes.Append(new byte[] {0x00, 0x01, 0x0F, 0x00});

            return Record.GetBytes(RID.ROW, bytes);
        }
Exemplo n.º 24
0
 public void WithValidBytes_ReturnsStartsWithValue(bool expected, byte input)
 {
     Assert.AreEqual(expected, Bytes.StartsWith(input), "Get StartsWith value");
 }
Exemplo n.º 25
0
        internal static Bytes GetUnicodeString(string text, int lengthBits)
        {
            int textLength;
            int limit = lengthBits == 8 ? byte.MaxValue : ushort.MaxValue;
            byte[] binaryLength = new byte[0];
            byte[] compression;
            byte[] compressedText = new byte[0];

            textLength = text.Length;
            if (textLength > limit)
                text = text.Substring(0, limit); //NOTE: Should throw Exception here?

            if (limit == 255)
                binaryLength = new byte[1] { (byte)text.Length };
            else if (limit == 65535)
                binaryLength = BitConverter.GetBytes((ushort)text.Length);

            if (IsCompressible(text))
            {
                compression = new byte[1];
                char[] chars = text.ToCharArray();
                compressedText = new byte[chars.Length];
                for (int i = 0; i < chars.Length; i++)
                    compressedText[i] = (byte)chars[i];
            }
            else
            {
                compression = new byte[1] { 1 };
            }

            Bytes bytes = new Bytes();
            bytes.Append(binaryLength);
            bytes.Append(compression);
            if (compressedText.Length > 0)
                bytes.Append(compressedText);
            else
                bytes.Append(Encoding.Unicode.GetBytes(text));
            return bytes;
        }
Exemplo n.º 26
0
    public IntelHEXfile(string filename)
    {
        if (filename.ToLower().EndsWith(".hex") != true)
        {
            FileErrorMessages.Add("Файл имеет расширение отличное от hex");
        }

        try
        {
            StreamReader sr         = new StreamReader(filename);
            bool         eof        = false;
            int          lineNumber = 0;
            while (!eof)
            {
                lineNumber++;
                HEXline line = new HEXline(sr.ReadLine(), lineNumber);
                //if (ErrorMessage == "") ErrorMessage = line.ErrorMessages;
                FileErrorMessages.AddRange(line.LineErrorMessages);
                if (line.CriticalErrors == true)
                {
                    CriticalError = true;
                }

                switch (line.recordtype)
                {
                case HEXline.RecordType.DataRecord:
                    //data.AddRange(line.data);
                    ulong ij = 0;
                    foreach (byte bt in line.data)
                    {
                        AddressByteSorted.Add((ulong)(line.address + ij), line.data[ij]);
                        ij++;
                    }

                    break;

                case HEXline.RecordType.EndOfFile:
                    eof = true;
                    break;
                }
                if (sr.EndOfStream)
                {
                    eof = true;
                }
            }

            foreach (KeyValuePair <ulong, byte> dabs in AddressByteSorted)
            {
                Addresses.Add(dabs.Key);
                Bytes.Add(dabs.Value);
            }

            for (int i = 0; i < AddressByteSorted.Count; i++)
            {
                if (Addresses[i] < minAddress)
                {
                    minAddress = Addresses[i];
                }
            }

            for (int i = 0; i < AddressByteSorted.Count; i++)
            {
                if (Addresses[i] > maxAddress)
                {
                    maxAddress = Addresses[i];
                }
            }



            sr.Close();
            sr.Dispose();
        }
        catch (Exception ex)
        {
            ErrorMessage  = ex.Message;
            CriticalError = true;
        }
    }
Exemplo n.º 27
0
		public void Serialize (Bytes bytes)
		{
			Serialize ((byte[]) bytes);
		}
Exemplo n.º 28
0
        internal Worksheet(XlsDocument doc, Record boundSheet, List <Record> sheetRecords) : this(doc)
        {
            byte[] byteArray = boundSheet.Data.ByteArray;

            byte visibility = byteArray[4];
            if (visibility == 0x00)
            {
                _visibility = WorksheetVisibilities.Visible;
            }
            else if (visibility == 0x01)
            {
                _visibility = WorksheetVisibilities.Hidden;
            }
            else if (visibility == 0x02)
            {
                _visibility = WorksheetVisibilities.StrongHidden;
            }
            else
            {
                throw new ApplicationException(string.Format("Unknown Visibility {0}", visibility));
            }

            byte type = byteArray[5];
            if (type == 0x00)
            {
                _sheettype = WorksheetTypes.Worksheet;
            }
            else if (type == 0x02)
            {
                _sheettype = WorksheetTypes.Chart;
            }
            else if (type == 0x06)
            {
                _sheettype = WorksheetTypes.VBModule;
            }
            else
            {
                throw new ApplicationException(string.Format("Unknown Sheet Type {0}", type));
            }

            List <Record> rowRecords  = new List <Record>();
            List <Record> cellRecords = new List <Record>();

            for (int i = 0; i < sheetRecords.Count; i++)
            {
                Record record = sheetRecords[i];
                if (record.IsCellRecord())
                {
                    if (record.RID == RID.FORMULA)
                    {
                        Record formulaStringRecord = null;
                        if ((i + i) < sheetRecords.Count)
                        {
                            formulaStringRecord = sheetRecords[i + 1];
                            if (formulaStringRecord.RID != RID.STRING)
                            {
                                formulaStringRecord = null;
                            }
                        }
                        record = new FormulaRecord(record, formulaStringRecord);
                    }

                    cellRecords.Add(record);
                }
                else if (record.RID == RID.ROW)
                {
                    rowRecords.Add(record);
                }
            }

            //Add the Rows first so they exist for adding the Cells
            foreach (Record rowRecord in rowRecords)
            {
                Bytes  rowBytes        = rowRecord.Data;
                ushort rowIndex        = rowBytes.Get(0, 2).GetBits().ToUInt16();
                Row    row             = Rows.AddRow(rowIndex);
                bool   isDefaultHeight = rowBytes.Get(6, 2).GetBits().Values[15];
                ushort height          = 0;
                if (!isDefaultHeight)
                {
                    height = rowBytes.Get(6, 2).GetBits().Get(0, 14).ToUInt16();
                    //TODO: Set height on Row when reading (after Row Height implemented)
                }
                bool defaultsWritten = (rowBytes.Get(10, 1).ByteArray[0] == 0x01);
                if (defaultsWritten)
                {
                    //TODO: Read ROW record defaults
                }
            }

            foreach (Record record in cellRecords)
            {
                AddCells(record);
            }

            _name = UnicodeBytes.Read(boundSheet.Data.Get(6, boundSheet.Data.Length - 6), 8);
        }
Exemplo n.º 29
0
 public void WithValidBytes_ReturnsContainsValue(bool expected, byte input)
 {
     Assert.AreEqual(expected, Bytes.Contains(input), "Get Contains value");
 }
Exemplo n.º 30
0
 public SSEQTrackEvent(byte EventID, EndianBinaryReader er)
 {
     this.EventID = EventID;
     this.TrackNr = er.ReadByte();
     this.Offset  = (uint)Bytes.Read3BytesAsInt24(er.ReadBytes(3), 0);
 }
Exemplo n.º 31
0
 public byte[] GetBytes()
 {
     return(Bytes.ToArray());
 }
Exemplo n.º 32
0
 public void WithValidBytes_ReturnsTrue()
 {
     Assert.IsTrue(Bytes.IsEqualTo(Bytes), "Get IsEqualToTest value");
     Assert.IsTrue(Bytes.IsEqualTo(BitConverter.GetBytes(Value)), "Get IsEqualToTest value");
 }
Exemplo n.º 33
0
        private void AddCells(Record record)
        {
            Bytes  bytes        = record.Data;
            ushort rowIndex     = bytes.Get(0, 2).GetBits().ToUInt16();
            ushort colIndex     = bytes.Get(2, 2).GetBits().ToUInt16();
            ushort lastColIndex = colIndex;
            ushort offset       = 4;

            byte[] rid     = record.RID;
            bool   isMulti = false;

            if (rid == RID.MULBLANK)
            {
                isMulti = true;
                rid     = RID.BLANK;
            }
            else if (rid == RID.MULRK)
            {
                isMulti = true;
                rid     = RID.RK;
            }

            if (isMulti)
            {
                lastColIndex = bytes.Get(bytes.Length - 2, 2).GetBits().ToUInt16();
            }


            while (colIndex <= lastColIndex)
            {
                Cell   cell    = Cells.Add((ushort)(rowIndex + 1), (ushort)(colIndex + 1));
                ushort xfIndex = bytes.Get(offset, 2).GetBits().ToUInt16();
                offset += 2;

                Bytes data;
                if (rid == RID.BLANK)
                {
                    data = new Bytes();
                }
                else if (rid == RID.RK)
                {
                    data    = bytes.Get(offset, 4);
                    offset += 4;
                    cell.SetValue(rid, data);
                }
                else
                {
                    data = bytes.Get(offset, bytes.Length - offset);
                    if (rid == RID.FORMULA)
                    {
                        FormulaRecord formulaRecord = record as FormulaRecord;
                        cell.SetFormula(data, formulaRecord.StringRecord);
                    }
                    else
                    {
                        cell.SetValue(rid, data);
                    }
                }
                colIndex++;
            }
        }
Exemplo n.º 34
0
 public void WithValidBytes_ReturnsToTextValue()
 {
     Assert.AreEqual("�[", Bytes.ToText(), "Get ToText value");
 }
Exemplo n.º 35
0
        public (PrivateKey PrivateKey, Result Result) GetKey(Address address, SecureString password)
        {
            var serializedKey = ReadKey(address.ToString());

            if (serializedKey == null)
            {
                return(null, Result.Fail("Cannot find key"));
            }
            var keyStoreItem = _jsonSerializer.Deserialize <KeyStoreItem>(serializedKey);

            if (keyStoreItem?.Crypto == null)
            {
                return(null, Result.Fail("Cannot deserialize key"));
            }

            var validationResult = Validate(keyStoreItem);

            if (validationResult.ResultType != ResultType.Success)
            {
                return(null, validationResult);
            }

            byte[] mac    = Bytes.FromHexString(keyStoreItem.Crypto.MAC);
            byte[] iv     = Bytes.FromHexString(keyStoreItem.Crypto.CipherParams.IV);
            byte[] cipher = Bytes.FromHexString(keyStoreItem.Crypto.CipherText);
            byte[] salt   = Bytes.FromHexString(keyStoreItem.Crypto.KDFParams.Salt);

            var kdfParams = keyStoreItem.Crypto.KDFParams;
            var passBytes = password.ToByteArray(_keyStoreEncoding);

            byte[] derivedKey;
            var    kdf = keyStoreItem.Crypto.KDF.Trim();

            switch (kdf)
            {
            case "scrypt":
                derivedKey = SCrypt.ComputeDerivedKey(passBytes, salt, kdfParams.N, kdfParams.R, kdfParams.P, null, kdfParams.DkLen);
                break;

            case "pbkdf2":
                var deriveBytes = new Rfc2898DeriveBytes(passBytes, salt, kdfParams.C, HashAlgorithmName.SHA256);
                derivedKey = deriveBytes.GetBytes(256);
                break;

            default:
                return(null, Result.Fail($"Unsupported algoritm: {kdf}"));
            }

            var restoredMac = Keccak.Compute(derivedKey.Slice(kdfParams.DkLen - 16, 16).Concat(cipher).ToArray()).Bytes;

            if (!Bytes.AreEqual(mac, restoredMac))
            {
                return(null, Result.Fail("Incorrect MAC"));
            }

            var cipherType = keyStoreItem.Crypto.Cipher.Trim();

            byte[] decryptKey;
            if (kdf == "scrypt" && cipherType == "aes-128-cbc")
            {
                decryptKey = Keccak.Compute(derivedKey.Slice(0, 16)).Bytes.Slice(0, 16);
            }
            else
            {
                decryptKey = derivedKey.Slice(0, 16);
            }

            byte[] key = _symmetricEncrypter.Decrypt(cipher, decryptKey, iv, cipherType);
            if (key == null)
            {
                return(null, Result.Fail("Error during decryption"));
            }

            // TODO: maybe only allow to sign here so the key never leaves the area?
            return(new PrivateKey(key), Result.Success());
        }
Exemplo n.º 36
0
 public void WithValidBytes_ReturnsString(string expected, bool prefix)
 {
     Assert.AreEqual(expected, Bytes.ToUpperHex(prefix), "Get ToUpperHex value");
 }
Exemplo n.º 37
0
        private Bytes MERGEDCELLS()
        {
            Bytes mergedcells = new Bytes();

            int areaIndex = 0;
            int mergeAreaCount = _mergeAreas.Count;
            long areasPerRecord = 1027;
            int recordsRequired = (int)Math.Ceiling(_mergeAreas.Count/(double)areasPerRecord);
            for (int recordIndex = 0; recordIndex < recordsRequired; recordIndex++)
            {
                ushort blockAreaIndex = 0;
                Bytes rangeAddresses = new Bytes();
                while (areaIndex < mergeAreaCount && blockAreaIndex < areasPerRecord)
                {
                    rangeAddresses.Append(CellRangeAddress(_mergeAreas[areaIndex]));

                    blockAreaIndex++;
                    areaIndex++;
                }
                rangeAddresses.Prepend(BitConverter.GetBytes(blockAreaIndex));
                mergedcells.Append(Record.GetBytes(RID.MERGEDCELLS, rangeAddresses));
            }

            return mergedcells;
        }
Exemplo n.º 38
0
        public void WithValidParams_ReturnsSubArray(long startIndex, long length, int expected)
        {
            var sub = Bytes.SubArray(startIndex, length);

            Assert.AreEqual(expected, sub[0]);
        }
Exemplo n.º 39
0
 internal static string Read(Bytes bytes, int lengthBits)
 {
     Record record = new Record(RID.Empty, bytes);
     return Read(record, lengthBits, 0);
 }
Exemplo n.º 40
0
        public void WithInvalidParams_ReturnsEmpty(long startIndex, long length)
        {
            var sub = Bytes.SubArray(startIndex, length);

            Assert.IsEmpty(sub);
        }
Exemplo n.º 41
0
 internal static void Write(string text, Bytes bytes, ref ushort offset)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 42
0
 public void WithValidBytes_ReturnsString()
 {
     Assert.AreEqual("15-CD-5B-07", Bytes.ToDashedHex(), "Get ToDashedHex value");
 }
Exemplo n.º 43
0
        private Bytes SectorBinData(int sectorIndex)
        {
            if (0 > sectorIndex || sectorIndex > SectorCount)
                throw new ArgumentOutOfRangeException(string.Format("sectorIndex must be >= 0 and <= SectorCount {0}", SectorCount));

            int satSectors, satSid0, startSector, stopSector;

            Bytes bytes = new Bytes();

            satSectors = _doc.SAT.SectorCount;
            satSid0 = _doc.SAT.SID0;

            if (sectorIndex == 0)
            {
                startSector = 1;
                stopSector = 109;
            }
            else
            {
                startSector = 110 + ((sectorIndex - 1)*127);
                stopSector = startSector + 126;
            }

            for (int i = startSector; i <= stopSector; i++)
            {
                if (i < (satSectors + 1))
                    bytes.Append(BitConverter.GetBytes((int) (satSid0 + (i - 1))));
                else
                    bytes.Append(BitConverter.GetBytes((int) -1));
            }

            if (sectorIndex > 0)
            {
                if (stopSector >= satSectors)
                    bytes.Append(BitConverter.GetBytes((int) -2));
                else
                    bytes.Append(BitConverter.GetBytes((int) (SID0 + sectorIndex)));
            }

            return bytes;
        }
Exemplo n.º 44
0
 public void WithValidBytes_ReturnsString()
 {
     Assert.AreEqual("Fc1bBw==", Bytes.ToBase64(), "Get ToBase64 value");
 }
Exemplo n.º 45
0
        private static Bytes DBCELL(ushort[] cOff)
        {
            Bytes dbcell = new Bytes();

            for (int i = 0; i < cOff.Length; i++)
            {
                if (i == 0)
                    dbcell.Append(BitConverter.GetBytes((uint) cOff[i]));
                else
                    dbcell.Append(BitConverter.GetBytes(cOff[i]));
            }

            return Record.GetBytes(RID.DBCELL, dbcell);
        }
 public void update(Bytes newBytes)
 {
     update((IList <byte>)newBytes);
 }
Exemplo n.º 47
0
        private Bytes GetStream(System.IO.Stream fromDocumentStream, int did, Dictionary<int, byte[]> dir, ushort sectorSize, int[] sat, ushort shortSectorSize, int[] ssat, uint minStandardStreamSize)
        {
            Bytes stream = new Bytes();
            Bytes fromBytes;
            int[] fromSAT;
            ushort fromSectorSize;
            int sidNext;
            string shortness;

            int streamLength = BitConverter.ToInt32(MidByteArray(dir[did], 120, 4), 0);

            Bytes streamBytes = null;

            if (did == 0 || (streamLength >= minStandardStreamSize))
            {
                byte[] streamByteArray;
                streamByteArray = new byte[fromDocumentStream.Length];
                fromDocumentStream.Position = 0;
                fromDocumentStream.Read(streamByteArray, 0, streamByteArray.Length);
                streamBytes = new Bytes(streamByteArray);
            }

            if (did == 0)
            {
                fromSectorSize = sectorSize;
                fromSAT = sat;
                shortness = string.Empty;
                fromBytes = streamBytes;
            }
            else if (streamLength < minStandardStreamSize)
            {
                fromSectorSize = shortSectorSize;
                fromSAT = ssat;
                shortness = "Short ";
                fromBytes = GetStream(fromDocumentStream, 0, dir, sectorSize, sat, shortSectorSize, ssat, minStandardStreamSize);
            }
            else
            {
                fromSectorSize = sectorSize;
                fromSAT = sat;
                shortness = string.Empty;
                fromBytes = streamBytes;
            }

            sidNext = BitConverter.ToInt32(MidByteArray(dir[did], 116, 4), 0);
            while (sidNext > -2)
            {
                Bytes sector;
                if (did > 0 && streamLength < minStandardStreamSize)
                    sector = GetShortSectorBytes(fromBytes, fromSectorSize, sidNext);
                else
                    sector = GetSectorBytes(fromBytes, fromSectorSize, sidNext);

                if (sector.Length == 0)
                    throw new Exception(string.Format("{0}Sector not found [SID{1}]", shortness, sidNext));

                stream.Append(sector);

                sidNext = fromSAT[sidNext];
            }

            return stream.Get(streamLength);
        }
 public static sha @new(Bytes data)
 {
     return(new sha((IList <byte>)data));
 }
Exemplo n.º 49
0
 internal Bytes GetStandardOLE2Stream(Bytes bytes)
 {
     uint standardLength = _ole2Doc.StandardStreamMinBytes;
     uint padLength = standardLength = ((uint)bytes.Length % standardLength);
     if (padLength < standardLength)
         bytes.Append(new byte[padLength]);
     return bytes;
 }
Exemplo n.º 50
0
 private void AssertEip145(TestAllTracerWithOutput receipt, string result)
 {
     AssertEip145(receipt, Bytes.FromHexString(result));
 }
Exemplo n.º 51
0
		public ByteDeserializer (Bytes buf)
		{
			_buffer = new MemoryStream ((byte[]) buf);
		}
Exemplo n.º 52
0
 // Token: 0x0600018F RID: 399 RVA: 0x0000886D File Offset: 0x0000786D
 public Stream AddNamed(Bytes bytes, byte[] name)
 {
     return(this.AddNamed(bytes, name, false));
 }
Exemplo n.º 53
0
        internal static Bytes GetBytes(byte[] rid, Bytes data)
        {
            if (rid.Length != 2)
                throw new ArgumentException("must be 2 bytes", "rid");

            Bytes record = new Bytes();

            ushort offset = 0;
            ushort totalLength = (ushort)data.Length;
            do
            {
                ushort length = Math.Min((ushort) (totalLength - offset), BIFF8.MaxDataBytesPerRecord);

                if (offset == 0)
                {
                    record.Append(rid);
                    record.Append(BitConverter.GetBytes(length));
                    record.Append(data.Get(offset, length));
                }
                else
                {
                    record.Append(MyXls.RID.CONTINUE);
                    record.Append(BitConverter.GetBytes(length));
                    record.Append(data.Get(offset, length));
                }

                offset += length;
            } while (offset < totalLength);

            return record;
        }
Exemplo n.º 54
0
        private Bytes COLINFO_OPTION_FLAGS()
        {
            bool[] bits = new bool[16];
            bits[0] = _hidden;
            Bytes outlineBytes = new Bytes(_outlineLevel);
            bool[] outlineLevelBits = outlineBytes.GetBits().Get(3).Values;
            outlineLevelBits.CopyTo(bits, 8);
            bits[12] = _collapsed;

            return new Bytes.Bits(bits).GetBytes();
        }
Exemplo n.º 55
0
 public static HexPrefix Leaf(string path)
 {
     return(new HexPrefix(true, Bytes.FromHexString(path)));
 }
Exemplo n.º 56
0
        private void SetOptionsValue(Bytes bytes)
        {
            ushort options = BitConverter.ToUInt16(bytes.ByteArray, 0);

            if (options >= 8)
            {
                _struckOut = true;
                options -= 8;
            }
            else
                _struckOut = false;

            if (options >= 4)
            {
                _underlined = true;
                options -= 4;
            }
            else
                _underlined = false;

            if (options >= 2)
            {
                _italic = true;
            }
            else
                _italic = false;
        }
Exemplo n.º 57
0
 private void ReadBytes(Bytes bytes)
 {
     byte[] byteArray = bytes.ByteArray;
     _height = BitConverter.ToUInt16(byteArray, 0);
     SetOptionsValue(bytes.Get(2, 2));
     _color = _doc.Workbook.Palette.GetColor(BitConverter.ToUInt16(byteArray, 4));
     _weight = FontWeightConverter.Convert(BitConverter.ToUInt16(byteArray, 6));
     _escapement = (EscapementTypes) BitConverter.ToUInt16(byteArray, 8);
     _underline = (UnderlineTypes) byteArray[10];
     _fontFamily = (FontFamilies) byteArray[11];
     _characterSet = (CharacterSets) byteArray[12];
     //skip byte index 13
     _fontName = UnicodeBytes.Read(bytes.Get(14, bytes.Length - 14), 8);
 }
Exemplo n.º 58
0
 public static HexPrefix Extension(string path)
 {
     return(new HexPrefix(false, Bytes.FromHexString(path)));
 }
Exemplo n.º 59
0
 internal Font(XlsDocument doc, Bytes bytes)
     : this(doc)
 {
     ReadBytes(bytes);
 }
Exemplo n.º 60
0
        public void Can_Invoke_Blockhash()
        {
            var code = Bytes.FromHexString("0x60014000");

            Assert.Throws <NotImplementedException>(() => RunVirtualMachine(code));
        }