Exemple #1
0
        public override String ToXml(String tab)
        {
            String        extraData = HexDump.ToHex(field_pictureData, 32);
            StringBuilder builder   = new StringBuilder();

            builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)))
            .Append(tab).Append("\t").Append("<ExtraData>").Append(extraData).Append("</ExtraData>\n");
            builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
            return(builder.ToString());
        }
 public void ConfirmInt(int expVal)
 {
     cmp(HexDump.IntToHex(expVal), HexDump.IntToHex(_bds.ReadInt()));
 }
Exemple #3
0
        /**
         * Adds a new OLE Package Shape
         *
         * @param anchor       the client anchor describes how this picture is
         *                     attached to the sheet.
         * @param storageId    the storageId returned by {@Link HSSFWorkbook.AddOlePackage}
         * @param pictureIndex the index of the picture (used as preview image) in the
         *                     workbook collection of pictures.
         *
         * @return newly Created shape
         */
        public HSSFObjectData CreateObjectData(HSSFClientAnchor anchor, int storageId, int pictureIndex)
        {
            ObjRecord obj = new ObjRecord();

            CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord();

            ftCmo.ObjectType = (/*setter*/ CommonObjectType.Picture);
            // ftCmo.ObjectId=(/*setter*/oleShape.ShapeId); ... will be Set by onCreate(...)
            ftCmo.IsLocked    = (/*setter*/ true);
            ftCmo.IsPrintable = (/*setter*/ true);
            ftCmo.IsAutoFill  = (/*setter*/ true);
            ftCmo.IsAutoline  = (/*setter*/ true);
            ftCmo.Reserved1   = (/*setter*/ 0);
            ftCmo.Reserved2   = (/*setter*/ 0);
            ftCmo.Reserved3   = (/*setter*/ 0);
            obj.AddSubRecord(ftCmo);

            // FtCf (pictFormat)
            FtCfSubRecord   ftCf     = new FtCfSubRecord();
            HSSFPictureData pictData = Sheet.Workbook.GetAllPictures()[(pictureIndex - 1)] as HSSFPictureData;

            switch ((PictureType)pictData.Format)
            {
            case PictureType.WMF:
            case PictureType.EMF:
                // this needs patch #49658 to be applied to actually work
                ftCf.Flags = (/*setter*/ FtCfSubRecord.METAFILE_BIT);
                break;

            case PictureType.DIB:
            case PictureType.PNG:
            case PictureType.JPEG:
            case PictureType.PICT:
                ftCf.Flags = (/*setter*/ FtCfSubRecord.BITMAP_BIT);
                break;
            }
            obj.AddSubRecord(ftCf);
            // FtPioGrbit (pictFlags)
            FtPioGrbitSubRecord ftPioGrbit = new FtPioGrbitSubRecord();

            ftPioGrbit.SetFlagByBit(FtPioGrbitSubRecord.AUTO_PICT_BIT, true);
            obj.AddSubRecord(ftPioGrbit);

            EmbeddedObjectRefSubRecord ftPictFmla = new EmbeddedObjectRefSubRecord();

            ftPictFmla.SetUnknownFormulaData(new byte[] { 2, 0, 0, 0, 0 });
            ftPictFmla.OLEClassName = (/*setter*/ "Paket");
            ftPictFmla.SetStorageId(storageId);

            obj.AddSubRecord(ftPictFmla);
            obj.AddSubRecord(new EndSubRecord());

            String         entryName = "MBD" + HexDump.ToHex(storageId);
            DirectoryEntry oleRoot;

            try
            {
                DirectoryNode dn = (_sheet.Workbook as HSSFWorkbook).RootDirectory;
                if (dn == null)
                {
                    throw new FileNotFoundException();
                }
                oleRoot = (DirectoryEntry)dn.GetEntry(entryName);
            }
            catch (FileNotFoundException e)
            {
                throw new InvalidOperationException("trying to add ole shape without actually Adding data first - use HSSFWorkbook.AddOlePackage first", e);
            }

            // create picture shape, which need to be minimal modified for oleshapes
            HSSFPicture shape = new HSSFPicture(null, anchor);

            shape.PictureIndex = (/*setter*/ pictureIndex);
            EscherContainerRecord spContainer = shape.GetEscherContainer();
            EscherSpRecord        spRecord    = spContainer.GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord;

            spRecord.Flags = (/*setter*/ spRecord.Flags | EscherSpRecord.FLAG_OLESHAPE);

            HSSFObjectData oleShape = new HSSFObjectData(spContainer, obj, oleRoot);

            AddShape(oleShape);
            OnCreate(oleShape);


            return(oleShape);
        }
Exemple #4
0
        public override String ToXml(String tab)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)))
            .Append(tab).Append("\t").Append("<RectX>").Append(field_1_rectX1).Append("</RectX>\n")
            .Append(tab).Append("\t").Append("<RectY>").Append(field_2_rectY1).Append("</RectY>\n")
            .Append(tab).Append("\t").Append("<RectWidth>").Append(field_3_rectX2).Append("</RectWidth>\n")
            .Append(tab).Append("\t").Append("<RectHeight>").Append(field_4_rectY2).Append("</RectHeight>\n");
            builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
            return(builder.ToString());
        }
 public void ConfirmByte(int expVal)
 {
     cmp(HexDump.ByteToHex(expVal), HexDump.ByteToHex(_bds.ReadUByte()));
 }
Exemple #6
0
 private static String LongToHex(long value)
 {
     return(new String(HexDump.LongToHex(value)));
 }
Exemple #7
0
 protected override void AppendValueText(StringBuilder sb)
 {
     sb.Append("  .sstIndex = ");
     sb.Append(HexDump.ShortToHex(XFIndex));
 }
Exemple #8
0
        //public override String ToString()
        //{
        //    return "propNum: " + PropertyNumber
        //            + ", complex: " + IsComplex
        //            + ", blipId: " + IsBlipId
        //            + ", value: " + (Value != 0);
        //}
        public override String ToXml(String tab)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(tab).Append("<").Append(GetType().Name).Append(" id=\"0x").Append(HexDump.ToHex(Id))
            .Append("\" name=\"").Append(Name).Append("\" simpleValue=\"").Append(PropertyValue).Append("\" blipId=\"")
            .Append(IsBlipId).Append("\" value=\"").Append(IsTrue).Append("\"").Append("/>\n");
            return(builder.ToString());
        }
Exemple #9
0
        public override string ToXml(string tab)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)))
            .Append(tab).Append("\t").Append("<BlipTypeWin32>").Append(field_1_blipTypeWin32).Append("</BlipTypeWin32>\n")
            .Append(tab).Append("\t").Append("<BlipTypeMacOS>").Append(field_2_blipTypeMacOS).Append("</BlipTypeMacOS>\n")
            .Append(tab).Append("\t").Append("<SUID>").Append(field_3_uid == null ? "" : HexDump.ToHex(field_3_uid)).Append("</SUID>\n")
            .Append(tab).Append("\t").Append("<Tag>").Append(field_4_tag).Append("</Tag>\n")
            .Append(tab).Append("\t").Append("<Size>").Append(field_5_size).Append("</Size>\n")
            .Append(tab).Append("\t").Append("<Ref>").Append(field_6_ref).Append("</Ref>\n")
            .Append(tab).Append("\t").Append("<Offset>").Append(field_7_offset).Append("</Offset>\n")
            .Append(tab).Append("\t").Append("<Usage>").Append(field_8_usage).Append("</Usage>\n")
            .Append(tab).Append("\t").Append("<Name>").Append(field_9_name).Append("</Name>\n")
            .Append(tab).Append("\t").Append("<Unused2>").Append(field_10_unused2).Append("</Unused2>\n")
            .Append(tab).Append("\t").Append("<Unused3>").Append(field_11_unused3).Append("</Unused3>\n");
            builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
            return(builder.ToString());
        }
Exemple #10
0
    void PanelOnPaint(object obj, PaintEventArgs pea)
    {
        Panel    panel = (Panel)obj;
        Graphics grfx  = pea.Graphics;
        Brush    brush = new SolidBrush(panel.ForeColor);

        if (radioChecked == null || !radioChecked.Enabled)
        {
            return;
        }

        IDataObject data = Clipboard.GetDataObject();

        object objClip = data.GetData((string)radioChecked.Tag);

        if (objClip == null)
        {
            return;
        }

        else if (objClip.GetType() == typeof(string))
        {
            grfx.DrawString((string)objClip, Font, brush,
                            panel.ClientRectangle);
        }
        else if (objClip.GetType() == typeof(string[]))     // FileDrop
        {
            string str = string.Join("\r\n", (string[])objClip);

            grfx.DrawString(str, Font, brush, panel.ClientRectangle);
        }
        else if (objClip.GetType() == typeof(Bitmap) ||
                 objClip.GetType() == typeof(Metafile) ||
                 objClip.GetType() == typeof(Image))
        {
            grfx.DrawImage((Image)objClip, 0, 0);
        }
        else if (objClip.GetType() == typeof(MemoryStream))
        {
            Stream stream    = (Stream)objClip;
            byte[] abyBuffer = new byte[16];
            long   lAddress  = 0;
            int    iCount;
            Font   font = new Font(FontFamily.GenericMonospace,
                                   Font.SizeInPoints);
            float y = 0;

            while ((iCount = stream.Read(abyBuffer, 0, 16)) > 0)
            {
                string str = HexDump.ComposeLine(lAddress, abyBuffer,
                                                 iCount);
                grfx.DrawString(str, font, brush, 0, y);
                lAddress += 16;
                y        += font.GetHeight(grfx);

                if (y > panel.Bottom)
                {
                    break;
                }
            }
        }
    }
Exemple #11
0
        public void PrivateHeaderBlock(byte[] data)
        {
            _data = data;

            long signature = LittleEndian.GetLong(_data, _signature_offset);

            if (signature != _signature)
            {
                if (cmp(POIFSConstants.OOXML_FILE_HEADER, data))
                {
                    throw new OfficeXmlFileException("The supplied data appears to be in the Office 2007+ XML. "
                                                     + "You are calling the part of POI that deals with OLE2 Office Documents. "
                                                     + "You need to call a different part of POI to process this data (eg XSSF instead of HSSF)");
                }

                if (cmp(POIFSConstants.RAW_XML_FILE_HEADER, data))
                {
                    throw new NotOLE2FileException("The supplied data appears to be a raw XML file. "
                                                   + "Formats such as Office 2003 XML are not supported");
                }

                // BIFF2 raw stream
                if (cmp(MAGIC_BIFF2, data))
                {
                    throw new OldExcelFormatException("The supplied data appears to be in BIFF2 format. "
                                                      + "HSSF only supports the BIFF8 format, try OldExcelExtractor");
                }

                // BIFF3 raw stream
                if (cmp(MAGIC_BIFF3, data))
                {
                    throw new OldExcelFormatException("The supplied data appears to be in BIFF3 format. "
                                                      + "HSSF only supports the BIFF8 format, try OldExcelExtractor");
                }

                // BIFF4 raw stream
                if (cmp(MAGIC_BIFF4a, data) || cmp(MAGIC_BIFF4b, data))
                {
                    throw new OldExcelFormatException("The supplied data appears to be in BIFF4 format. "
                                                      + "HSSF only supports the BIFF8 format, try OldExcelExtractor");
                }


                // Give a generic error if the OLE2 signature isn't found
                throw new NotOLE2FileException("Invalid header signature; read "
                                               + new String(HexDump.LongToHex(signature)) + ", expected "
                                               + new String(HexDump.LongToHex(_signature)) + " - Your file appears "
                                               + "not to be a valid OLE2 document");
            }

            if (_data[30] == 12)
            {
                bigBlockSize = POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS;
            }
            else if (_data[30] == 9)
            {
                bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
            }
            else
            {
                throw new IOException("Unsupported blocksize  (2^" + _data[30] + "). Expected 2^9 or 2^12.");
            }

            // Setup the fields to read and write the counts and starts
            _bat_count      = new IntegerField(HeaderBlockConstants._bat_count_offset, _data).Value;
            _property_start = new IntegerField(HeaderBlockConstants._property_start_offset, _data).Value;
            _sbat_start     = new IntegerField(HeaderBlockConstants._sbat_start_offset, _data).Value;
            _sbat_count     = new IntegerField(HeaderBlockConstants._sbat_block_count_offset, _data).Value;
            _xbat_start     = new IntegerField(HeaderBlockConstants._xbat_start_offset, _data).Value;
            _xbat_count     = new IntegerField(HeaderBlockConstants._xbat_count_offset, _data).Value;
        }
Exemple #12
0
 public void TestCreateKeyDigest()
 {
     byte[] docIdData = fromHex("17 F6 D1 6B 09 B1 5F 7B 4C 9D 03 B4 81 B5 B4 4A");
     byte[] keyDigest = Biff8EncryptionKey.CreateKeyDigest("MoneyForNothing", docIdData);
     byte[] expResult = fromHex("C2 D9 56 B2 6B");
     if (!Arrays.Equals(expResult, keyDigest))
     {
         throw new ComparisonFailure("keyDigest mismatch", HexDump.ToHex(expResult), HexDump.ToHex(keyDigest));
     }
 }
        public void TestFillFields()
        {
            String data = "01 00 00 00 24 00 00 00 05 05 01 02 03 04 " +
                          " 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00 01 00 00 00 " +
                          " 00 00 02 00 00 00 03 00 00 00 04 05 06 07";
            EscherBSERecord r            = new EscherBSERecord();
            int             bytesWritten = r.FillFields(HexRead.ReadFromString(data), 0, new DefaultEscherRecordFactory());

            Assert.AreEqual(44, bytesWritten);
            Assert.AreEqual((short)0x0001, r.Options);
            Assert.AreEqual(EscherBSERecord.BT_JPEG, r.BlipTypeWin32);
            Assert.AreEqual(EscherBSERecord.BT_JPEG, r.BlipTypeMacOS);
            Assert.AreEqual("[01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, ]", HexDump.ToHex(r.UID));
            Assert.AreEqual((short)1, r.Tag);
            Assert.AreEqual(2, r.Ref);
            Assert.AreEqual(3, r.Offset);
            Assert.AreEqual((byte)4, r.Usage);
            Assert.AreEqual((byte)5, r.Name);
            Assert.AreEqual((byte)6, r.Unused2);
            Assert.AreEqual((byte)7, r.Unused3);
            Assert.AreEqual(0, r.RemainingData.Length);
        }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IllegalVariantTypeException"/> class.
 /// </summary>
 /// <param name="variantType">The unsupported variant type</param>
 /// <param name="value">The value.</param>
 public IllegalVariantTypeException(long variantType,
                                    Object value) : this(variantType, value, "The variant type " + variantType + " (" +
                                                         Variant.GetVariantName(variantType) + ", " +
                                                         HexDump.ToHex(variantType) + ") is illegal in this context.")
 {
 }
Exemple #15
0
        public void TestFillFields()
        {
            EscherBlipWMFRecord r = new EscherBlipWMFRecord();

            r.FillFields(data, 0, new DefaultEscherRecordFactory());

            Assert.AreEqual(EscherBlipWMFRecord.RECORD_ID_START, r.RecordId);
            Assert.AreEqual(1, r.BoundaryLeft);
            Assert.AreEqual(2, r.BoundaryHeight);
            Assert.AreEqual(3, r.BoundaryTop);
            Assert.AreEqual(4, r.BoundaryWidth);
            Assert.AreEqual(5, r.CacheOfSavedSize);
            Assert.AreEqual(6, r.CacheOfSize);
            Assert.AreEqual(7, r.Filter);
            Assert.AreEqual(8, r.CompressionFlag);
            Assert.AreEqual("[01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]", HexDump.ToHex(r.SecondaryUID));
            Assert.AreEqual(10, r.Width);
            Assert.AreEqual(11, r.Height);
            Assert.AreEqual((short)5420, r.Options);
            Assert.AreEqual("[01, 02, ]", HexDump.ToHex(r.Data));
        }
Exemple #16
0
        /**
         * Read hyperlink from input stream
         *
         * @param in the stream to Read from
         */

        public HyperlinkRecord(RecordInputStream in1)
        {
            _range = new CellRangeAddress(in1);

            // 16-byte GUID
            _guid = new GUID(in1);

            /*
             * streamVersion (4 bytes): An unsigned integer that specifies the version number
             * of the serialization implementation used to save this structure. This value MUST equal 2.
             */
            int streamVersion = in1.ReadInt();

            if (streamVersion != 0x00000002)
            {
                throw new RecordFormatException("Stream Version must be 0x2 but found " + streamVersion);
            }
            _linkOpts = in1.ReadInt();

            if ((_linkOpts & HLINK_LABEL) != 0)
            {
                int label_len = in1.ReadInt();
                _label = in1.ReadUnicodeLEString(label_len);
            }
            if ((_linkOpts & HLINK_TARGET_FRAME) != 0)
            {
                int len = in1.ReadInt();
                _targetFrame = in1.ReadUnicodeLEString(len);
            }
            if ((_linkOpts & HLINK_URL) != 0 && (_linkOpts & HLINK_UNC_PATH) != 0)
            {
                _moniker = null;
                int nChars = in1.ReadInt();
                _address = in1.ReadUnicodeLEString(nChars);
            }
            if ((_linkOpts & HLINK_URL) != 0 && (_linkOpts & HLINK_UNC_PATH) == 0)
            {
                _moniker = new GUID(in1);

                if (URL_MONIKER.Equals(_moniker))
                {
                    int length = in1.ReadInt();

                    /*
                     * The value of <code>length<code> be either the byte size of the url field
                     * (including the terminating NULL character) or the byte size of the url field plus 24.
                     * If the value of this field is set to the byte size of the url field,
                     * then the tail bytes fields are not present.
                     */
                    int remaining = in1.Remaining;
                    if (length == remaining)
                    {
                        int nChars = length / 2;
                        _address = in1.ReadUnicodeLEString(nChars);
                    }
                    else
                    {
                        int nChars = (length - TAIL_SIZE) / 2;
                        _address = in1.ReadUnicodeLEString(nChars);

                        /*
                         * TODO: make sense of the remaining bytes
                         * According to the spec they consist of:
                         * 1. 16-byte  GUID: This field MUST equal
                         *    {0xF4815879, 0x1D3B, 0x487F, 0xAF, 0x2C, 0x82, 0x5D, 0xC4, 0x85, 0x27, 0x63}
                         * 2. Serial version, this field MUST equal 0 if present.
                         * 3. URI Flags
                         */
                        _uninterpretedTail = ReadTail(URL_uninterpretedTail, in1);
                    }
                }
                else if (FILE_MONIKER.Equals(_moniker))
                {
                    _fileOpts = in1.ReadShort();

                    int len = in1.ReadInt();
                    _shortFilename     = StringUtil.ReadCompressedUnicode(in1, len);
                    _uninterpretedTail = ReadTail(FILE_uninterpretedTail, in1);
                    int size = in1.ReadInt();
                    if (size > 0)
                    {
                        int charDataSize = in1.ReadInt();

                        //From the spec: An optional unsigned integer that MUST be 3 if present
                        // but some files has 4
                        int usKeyValue = in1.ReadUShort();
                        _address = StringUtil.ReadUnicodeLE(in1, charDataSize / 2);
                    }
                    else
                    {
                        _address = null;
                    }
                }
                else if (STD_MONIKER.Equals(_moniker))
                {
                    _fileOpts = in1.ReadShort();

                    int len = in1.ReadInt();

                    byte[] path_bytes = new byte[len];
                    in1.ReadFully(path_bytes);

                    _address = Encoding.UTF8.GetString(path_bytes);
                }
            }

            if ((_linkOpts & HLINK_PLACE) != 0)
            {
                int len = in1.ReadInt();
                _textMark = in1.ReadUnicodeLEString(len);
            }

            if (in1.Remaining > 0)
            {
                Console.WriteLine(HexDump.ToHex(in1.ReadRemainder()));
            }
        }
Exemple #17
0
        public override string ToXml(string tab)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name,
                                                             HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)));
            foreach (EscherProperty property in EscherProperties)
            {
                builder.Append(property.ToXml(tab + "\t"));
            }
            builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
            return(builder.ToString());
        }
Exemple #18
0
        protected override void DoRun()
        {
            List <VirtualDisk> disks = new List <VirtualDisk>();

            foreach (var path in _inFiles.Values)
            {
                VirtualDisk disk = VirtualDisk.OpenDisk(path, _diskType.IsPresent ? _diskType.Value : null, FileAccess.Read, UserName, Password);
                disks.Add(disk);

                Console.WriteLine();
                Console.WriteLine("DISK: " + path);
                Console.WriteLine();
                Console.WriteLine("       Capacity: {0:X16}", disk.Capacity);
                Console.WriteLine("       Geometry: {0}", disk.Geometry);
                Console.WriteLine("  BIOS Geometry: {0}", disk.BiosGeometry);
                Console.WriteLine("      Signature: {0:X8}", disk.Signature);
                if (disk.IsPartitioned)
                {
                    Console.WriteLine("           GUID: {0}", disk.Partitions.DiskGuid);
                }
                Console.WriteLine();

                if (!_hideExtents.IsPresent)
                {
                    Console.WriteLine();
                    Console.WriteLine("  Stored Extents");
                    Console.WriteLine();
                    foreach (var extent in disk.Content.Extents)
                    {
                        Console.WriteLine("    {0:X16} - {1:X16}", extent.Start, extent.Start + extent.Length);
                    }
                    Console.WriteLine();
                }


                if (_showBootCode.IsPresent)
                {
                    Console.WriteLine();
                    Console.WriteLine("  Master Boot Record (MBR)");
                    Console.WriteLine();
                    try
                    {
                        byte[] mbr = new byte[512];
                        disk.Content.Position = 0;
                        disk.Content.Read(mbr, 0, 512);
                        HexDump.Generate(mbr, Console.Out);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                    Console.WriteLine();
                }


                Console.WriteLine();
                Console.WriteLine("  Partitions");
                Console.WriteLine();
                if (disk.IsPartitioned)
                {
                    Console.WriteLine("    T   Start (bytes)     End (bytes)       Type");
                    Console.WriteLine("    ==  ================  ================  ==================");
                    foreach (var partition in disk.Partitions.Partitions)
                    {
                        Console.WriteLine("    {0:X2}  {1:X16}  {2:X16}  {3}", partition.BiosType, partition.FirstSector * 512, partition.LastSector * 512 + 512, partition.TypeAsString);

                        BiosPartitionInfo bpi = partition as BiosPartitionInfo;
                        if (bpi != null)
                        {
                            Console.WriteLine("        {0,-16}  {1}", bpi.Start.ToString(), bpi.End.ToString());
                            Console.WriteLine();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("    No partitions");
                    Console.WriteLine();
                }
            }


            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("VOLUMES");
            Console.WriteLine();
            VolumeManager volMgr = new VolumeManager();

            foreach (var disk in disks)
            {
                volMgr.AddDisk(disk);
            }

            try
            {
                Console.WriteLine();
                Console.WriteLine("  Physical Volumes");
                Console.WriteLine();
                foreach (var vol in volMgr.GetPhysicalVolumes())
                {
                    Console.WriteLine("  " + vol.Identity);
                    Console.WriteLine("    Type: " + vol.VolumeType);
                    Console.WriteLine("    BIOS Type: " + vol.BiosType.ToString("X2") + " [" + BiosPartitionTypes.ToString(vol.BiosType) + "]");
                    Console.WriteLine("    Size: " + vol.Length);
                    Console.WriteLine("    Disk Id: " + vol.DiskIdentity);
                    Console.WriteLine("    Disk Sig: " + vol.DiskSignature.ToString("X8"));
                    Console.WriteLine("    Partition: " + vol.PartitionIdentity);
                    Console.WriteLine("    Disk Geometry: " + vol.PhysicalGeometry);
                    Console.WriteLine("    BIOS Geometry: " + vol.BiosGeometry);
                    Console.WriteLine("    First Sector: " + vol.PhysicalStartSector);
                    Console.WriteLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            try
            {
                Console.WriteLine();
                Console.WriteLine("  Logical Volumes");
                Console.WriteLine();
                foreach (var vol in volMgr.GetLogicalVolumes())
                {
                    Console.WriteLine("  " + vol.Identity);
                    Console.WriteLine("    BIOS Type: " + vol.BiosType.ToString("X2") + " [" + BiosPartitionTypes.ToString(vol.BiosType) + "]");
                    Console.WriteLine("    Status: " + vol.Status);
                    Console.WriteLine("    Size: " + vol.Length);
                    Console.WriteLine("    Disk Geometry: " + vol.PhysicalGeometry);
                    Console.WriteLine("    BIOS Geometry: " + vol.BiosGeometry);
                    Console.WriteLine("    First Sector: " + vol.PhysicalStartSector);

                    if (vol.Status == LogicalVolumeStatus.Failed)
                    {
                        Console.WriteLine("    File Systems: <unknown - failed volume>");
                        Console.WriteLine();
                        continue;
                    }

                    DiscUtils.FileSystemInfo[] fileSystemInfos = FileSystemManager.DetectDefaultFileSystems(vol);
                    Console.WriteLine("    File Systems: " + string.Join <DiscUtils.FileSystemInfo>(", ", fileSystemInfos));

                    Console.WriteLine();

                    if (_showVolContent.IsPresent)
                    {
                        Console.WriteLine("    Binary Contents...");
                        try
                        {
                            using (Stream s = vol.Open())
                            {
                                HexDump.Generate(s, Console.Out);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        Console.WriteLine();
                    }

                    if (_showBootCode.IsPresent)
                    {
                        foreach (var fsi in fileSystemInfos)
                        {
                            Console.WriteLine("    Boot Code: {0}", fsi.Name);
                            try
                            {
                                using (DiscFileSystem fs = fsi.Open(vol))
                                {
                                    byte[] bootCode = fs.ReadBootCode();
                                    if (bootCode != null)
                                    {
                                        HexDump.Generate(bootCode, Console.Out);
                                    }
                                    else
                                    {
                                        Console.WriteLine("      <file system reports no boot code>");
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("      Unable to show boot code: " + e.Message);
                            }
                            Console.WriteLine();
                        }
                    }

                    if (_showFiles.IsPresent)
                    {
                        foreach (var fsi in fileSystemInfos)
                        {
                            using (DiscFileSystem fs = fsi.Open(vol))
                            {
                                Console.WriteLine("    {0} Volume Label: {1}", fsi.Name, fs.VolumeLabel);
                                Console.WriteLine("    Files ({0})...", fsi.Name);
                                ShowDir(fs.Root, 6);
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            try
            {
                bool foundDynDisk = false;
                DynamicDiskManager dynDiskManager = new DynamicDiskManager();
                foreach (var disk in disks)
                {
                    if (DynamicDiskManager.IsDynamicDisk(disk))
                    {
                        dynDiskManager.Add(disk);
                        foundDynDisk = true;
                    }
                }
                if (foundDynDisk)
                {
                    Console.WriteLine();
                    Console.WriteLine("  Logical Disk Manager Info");
                    Console.WriteLine();
                    dynDiskManager.Dump(Console.Out, "  ");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            if (_showContent.IsPresent)
            {
                foreach (var path in _inFiles.Values)
                {
                    VirtualDisk disk = VirtualDisk.OpenDisk(path, FileAccess.Read, UserName, Password);

                    Console.WriteLine();
                    Console.WriteLine("DISK CONTENTS ({0})", path);
                    Console.WriteLine();
                    HexDump.Generate(disk.Content, Console.Out);
                    Console.WriteLine();
                }
            }
        }
Exemple #19
0
        /**
         * Constructs a OBJ record and Sets its fields appropriately.
         *
         * @param in the RecordInputstream to Read the record from
         */

        public ObjRecord(RecordInputStream in1)
        {
            // TODO - problems with OBJ sub-records stream
            // MS spec says first sub-record is always CommonObjectDataSubRecord,
            // and last is
            // always EndSubRecord. OOO spec does not mention ObjRecord(0x005D).
            // Existing POI test data seems to violate that rule. Some test data
            // seems to contain
            // garbage, and a crash is only averted by stopping at what looks like
            // the 'EndSubRecord'

            //Check if this can be continued, if so then the
            //following wont work properly
            //int subSize = 0;
            byte[] subRecordData = in1.ReadRemainder();

            if (LittleEndian.GetUShort(subRecordData, 0) != CommonObjectDataSubRecord.sid)
            {
                // seems to occur in just one junit on "OddStyleRecord.xls" (file created by CrystalReports)
                // Excel tolerates the funny ObjRecord, and replaces it with a corrected version
                // The exact logic/reasoning is not yet understood
                _uninterpretedData = subRecordData;
                subrecords         = null;
                return;
            }
            //if (subRecordData.Length % 2 != 0)
            //{
            //    String msg = "Unexpected length of subRecordData : " + HexDump.ToHex(subRecordData);
            //    throw new RecordFormatException(msg);
            //}
            subrecords = new List <SubRecord>();
            using (MemoryStream bais = new MemoryStream(subRecordData))
            {
                LittleEndianInputStream   subRecStream = new LittleEndianInputStream(bais);
                CommonObjectDataSubRecord cmo          = (CommonObjectDataSubRecord)SubRecord.CreateSubRecord(subRecStream, 0);
                subrecords.Add(cmo);
                while (true)
                {
                    SubRecord subRecord = SubRecord.CreateSubRecord(subRecStream, cmo.ObjectType);
                    subrecords.Add(subRecord);
                    if (subRecord.IsTerminating)
                    {
                        break;
                    }
                }
                int nRemainingBytes = subRecStream.Available();
                if (nRemainingBytes > 0)
                {
                    // At present (Oct-2008), most unit test samples have (subRecordData.length % 2 == 0)
                    _isPaddedToQuadByteMultiple = subRecordData.Length % MAX_PAD_ALIGNMENT == 0;
                    if (nRemainingBytes >= (_isPaddedToQuadByteMultiple ? MAX_PAD_ALIGNMENT : NORMAL_PAD_ALIGNMENT))
                    {
                        if (!CanPaddingBeDiscarded(subRecordData, nRemainingBytes))
                        {
                            String msg = "Leftover " + nRemainingBytes
                                         + " bytes in subrecord data " + HexDump.ToHex(subRecordData);
                            throw new RecordFormatException(msg);
                        }
                        _isPaddedToQuadByteMultiple = false;
                    }
                }
                else
                {
                    _isPaddedToQuadByteMultiple = false;
                }
                _uninterpretedData = null;
            }
        }
Exemple #20
0
        /// <summary>
        /// This version of dump is a translation from the open office escher dump routine.
        /// </summary>
        /// <param name="maxLength">The number of bytes to Read</param>
        /// <param name="in1">An input stream to Read from.</param>
        public void DumpOld(long maxLength, Stream in1)
        {
            long          remainingBytes = maxLength;
            short         options;              // 4 bits for the version and 12 bits for the instance
            short         recordId;
            int           recordBytesRemaining; // including enclosing records
            StringBuilder stringBuf = new StringBuilder();
            short         nDumpSize;
            String        recordName;

            bool atEOF = false;

            while (!atEOF && (remainingBytes > 0))
            {
                stringBuf            = new StringBuilder();
                options              = LittleEndian.ReadShort(in1);
                recordId             = LittleEndian.ReadShort(in1);
                recordBytesRemaining = LittleEndian.ReadInt(in1);

                remainingBytes -= 2 + 2 + 4;

                switch (recordId)
                {
                case unchecked ((short)0xF000):
                    recordName = "MsofbtDggContainer";
                    break;

                case unchecked ((short)0xF006):
                    recordName = "MsofbtDgg";
                    break;

                case unchecked ((short)0xF016):
                    recordName = "MsofbtCLSID";
                    break;

                case unchecked ((short)0xF00B):
                    recordName = "MsofbtOPT";
                    break;

                case unchecked ((short)0xF11A):
                    recordName = "MsofbtColorMRU";
                    break;

                case unchecked ((short)0xF11E):
                    recordName = "MsofbtSplitMenuColors";
                    break;

                case unchecked ((short)0xF001):
                    recordName = "MsofbtBstoreContainer";
                    break;

                case unchecked ((short)0xF007):
                    recordName = "MsofbtBSE";
                    break;

                case unchecked ((short)0xF002):
                    recordName = "MsofbtDgContainer";
                    break;

                case unchecked ((short)0xF008):
                    recordName = "MsofbtDg";
                    break;

                case unchecked ((short)0xF118):
                    recordName = "MsofbtRegroupItem";
                    break;

                case unchecked ((short)0xF120):
                    recordName = "MsofbtColorScheme";
                    break;

                case unchecked ((short)0xF003):
                    recordName = "MsofbtSpgrContainer";
                    break;

                case unchecked ((short)0xF004):
                    recordName = "MsofbtSpContainer";
                    break;

                case unchecked ((short)0xF009):
                    recordName = "MsofbtSpgr";
                    break;

                case unchecked ((short)0xF00A):
                    recordName = "MsofbtSp";
                    break;

                case unchecked ((short)0xF00C):
                    recordName = "MsofbtTextbox";
                    break;

                case unchecked ((short)0xF00D):
                    recordName = "MsofbtClientTextbox";
                    break;

                case unchecked ((short)0xF00E):
                    recordName = "MsofbtAnchor";
                    break;

                case unchecked ((short)0xF00F):
                    recordName = "MsofbtChildAnchor";
                    break;

                case unchecked ((short)0xF010):
                    recordName = "MsofbtClientAnchor";
                    break;

                case unchecked ((short)0xF011):
                    recordName = "MsofbtClientData";
                    break;

                case unchecked ((short)0xF11F):
                    recordName = "MsofbtOleObject";
                    break;

                case unchecked ((short)0xF11D):
                    recordName = "MsofbtDeletedPspl";
                    break;

                case unchecked ((short)0xF005):
                    recordName = "MsofbtSolverContainer";
                    break;

                case unchecked ((short)0xF012):
                    recordName = "MsofbtConnectorRule";
                    break;

                case unchecked ((short)0xF013):
                    recordName = "MsofbtAlignRule";
                    break;

                case unchecked ((short)0xF014):
                    recordName = "MsofbtArcRule";
                    break;

                case unchecked ((short)0xF015):
                    recordName = "MsofbtClientRule";
                    break;

                case unchecked ((short)0xF017):
                    recordName = "MsofbtCalloutRule";
                    break;

                case unchecked ((short)0xF119):
                    recordName = "MsofbtSelection";
                    break;

                case unchecked ((short)0xF122):
                    recordName = "MsofbtUDefProp";
                    break;

                default:
                    if (recordId >= unchecked ((short)0xF018) && recordId <= unchecked ((short)0xF117))
                    {
                        recordName = "MsofbtBLIP";
                    }
                    else if ((options & (short)0x000F) == (short)0x000F)
                    {
                        recordName = "UNKNOWN container";
                    }
                    else
                    {
                        recordName = "UNKNOWN ID";
                    }
                    break;
                }

                stringBuf.Append("  ");
                stringBuf.Append(HexDump.ToHex(recordId));
                stringBuf.Append("  ").Append(recordName).Append(" [");
                stringBuf.Append(HexDump.ToHex(options));
                stringBuf.Append(',');
                stringBuf.Append(HexDump.ToHex(recordBytesRemaining));
                stringBuf.Append("]  instance: ");
                stringBuf.Append(HexDump.ToHex(((short)(options >> 4))));
                Console.WriteLine(stringBuf.ToString());


                if (recordId == (unchecked ((short)0xF007)) && 36 <= remainingBytes && 36 <= recordBytesRemaining)
                {       // BSE, FBSE
                    //                ULONG nP = pIn->GetRecPos();

                    byte n8;
                    //                short n16;
                    //                int n32;

                    stringBuf = new StringBuilder("    btWin32: ");
                    n8        = (byte)in1.ReadByte();
                    stringBuf.Append(HexDump.ToHex(n8));
                    stringBuf.Append(GetBlipType(n8));
                    stringBuf.Append("  btMacOS: ");
                    n8 = (byte)in1.ReadByte();
                    stringBuf.Append(HexDump.ToHex(n8));
                    stringBuf.Append(GetBlipType(n8));
                    Console.WriteLine(stringBuf.ToString());

                    Console.WriteLine("    rgbUid:");
                    HexDump.Dump(in1, 0, 16);

                    Console.Write("    tag: ");
                    OutHex(2, in1);
                    Console.WriteLine();
                    Console.Write("    size: ");
                    OutHex(4, in1);
                    Console.WriteLine();
                    Console.Write("    cRef: ");
                    OutHex(4, in1);
                    Console.WriteLine();
                    Console.Write("    offs: ");
                    OutHex(4, in1);
                    Console.WriteLine();
                    Console.Write("    usage: ");
                    OutHex(4, in1);
                    Console.WriteLine();
                    Console.Write("    cbName: ");
                    OutHex(4, in1);
                    Console.WriteLine();
                    Console.Write("    unused2: ");
                    OutHex(4, in1);
                    Console.WriteLine();
                    Console.Write("    unused3: ");
                    OutHex(4, in1);
                    Console.WriteLine();

                    // subtract the number of bytes we've Read
                    remainingBytes -= 36;
                    //n -= pIn->GetRecPos() - nP;
                    recordBytesRemaining = 0;           // loop to MsofbtBLIP
                }
                else if (recordId == unchecked ((short)0xF010) && 0x12 <= remainingBytes && 0x12 <= recordBytesRemaining)
                {       // ClientAnchor
                    //ULONG nP = pIn->GetRecPos();
                    //                short n16;

                    Console.Write("    Flag: ");
                    OutHex(2, in1);
                    Console.WriteLine();
                    Console.Write("    Col1: ");
                    OutHex(2, in1);
                    Console.Write("    dX1: ");
                    OutHex(2, in1);
                    Console.Write("    Row1: ");
                    OutHex(2, in1);
                    Console.Write("    dY1: ");
                    OutHex(2, in1);
                    Console.WriteLine();
                    Console.Write("    Col2: ");
                    OutHex(2, in1);
                    Console.Write("    dX2: ");
                    OutHex(2, in1);
                    Console.Write("    Row2: ");
                    OutHex(2, in1);
                    Console.Write("    dY2: ");
                    OutHex(2, in1);
                    Console.WriteLine();

                    remainingBytes       -= 18;
                    recordBytesRemaining -= 18;
                }
                else if (recordId == unchecked ((short)0xF00B) || recordId == unchecked ((short)0xF122))
                {       // OPT
                    int nComplex = 0;
                    Console.WriteLine("    PROPID        VALUE");
                    while (recordBytesRemaining >= 6 + nComplex && remainingBytes >= 6 + nComplex)
                    {
                        short n16;
                        int   n32;
                        n16 = LittleEndian.ReadShort(in1);
                        n32 = LittleEndian.ReadInt(in1);

                        recordBytesRemaining -= 6;
                        remainingBytes       -= 6;
                        Console.Write("    ");
                        Console.Write(HexDump.ToHex(n16));
                        Console.Write(" (");
                        int propertyId = n16 & (short)0x3FFF;
                        Console.Write(" " + propertyId);
                        if ((n16 & unchecked ((short)0x8000)) == 0)
                        {
                            if ((n16 & (short)0x4000) != 0)
                            {
                                Console.Write(", fBlipID");
                            }
                            Console.Write(")  ");

                            Console.Write(HexDump.ToHex(n32));

                            if ((n16 & (short)0x4000) == 0)
                            {
                                Console.Write(" (");
                                Console.Write(Dec1616(n32));
                                Console.Write(')');
                                Console.Write(" {" + PropertyName((short)propertyId) + "}");
                            }
                            Console.WriteLine();
                        }
                        else
                        {
                            Console.Write(", fComplex)  ");
                            Console.Write(HexDump.ToHex(n32));
                            Console.Write(" - Complex prop len");
                            Console.WriteLine(" {" + PropertyName((short)propertyId) + "}");

                            nComplex += n32;
                        }
                    }
                    // complex property data
                    while ((nComplex & remainingBytes) > 0)
                    {
                        nDumpSize = (nComplex > (int)remainingBytes) ? (short)remainingBytes : (short)nComplex;
                        HexDump.Dump(in1, 0, nDumpSize);
                        nComplex             -= nDumpSize;
                        recordBytesRemaining -= nDumpSize;
                        remainingBytes       -= nDumpSize;
                    }
                }
                else if (recordId == (unchecked ((short)0xF012)))
                {
                    Console.Write("    Connector rule: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("    ShapeID A: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("   ShapeID B: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("    ShapeID connector: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("   Connect pt A: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("   Connect pt B: ");
                    Console.WriteLine(LittleEndian.ReadInt(in1));

                    recordBytesRemaining -= 24;
                    remainingBytes       -= 24;
                }
                else if (recordId >= unchecked ((short)0xF018) && recordId < unchecked ((short)0xF117))
                {
                    Console.WriteLine("    Secondary UID: ");
                    HexDump.Dump(in1, 0, 16);
                    Console.WriteLine("    Cache of size: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary top: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary left: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary width: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary height: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    X: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Y: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Cache of saved size: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Compression Flag: " + HexDump.ToHex((byte)in1.ReadByte()));
                    Console.WriteLine("    Filter: " + HexDump.ToHex((byte)in1.ReadByte()));
                    Console.WriteLine("    Data (after decompression): ");

                    recordBytesRemaining -= 34 + 16;
                    remainingBytes       -= 34 + 16;

                    nDumpSize = (recordBytesRemaining > (int)remainingBytes) ? (short)remainingBytes : (short)recordBytesRemaining;


                    byte[] buf  = new byte[nDumpSize];
                    int    Read = in1.Read(buf, 0, buf.Length);
                    while (Read != -1 && Read < nDumpSize)
                    {
                        Read += in1.Read(buf, Read, buf.Length);
                    }

                    using (MemoryStream bin = new MemoryStream(buf))
                    {
                        using (ZlibStream in2 = new ZlibStream(bin, CompressionMode.Decompress, false))
                        {
                            int bytesToDump = -1;
                            HexDump.Dump(in2, 0, bytesToDump);

                            recordBytesRemaining -= nDumpSize;
                            remainingBytes       -= nDumpSize;
                        }
                    }
                }

                bool isContainer = (options & (short)0x000F) == (short)0x000F;
                if (isContainer && remainingBytes >= 0)
                {       // Container
                    if (recordBytesRemaining <= (int)remainingBytes)
                    {
                        Console.WriteLine("            completed within");
                    }
                    else
                    {
                        Console.WriteLine("            continued elsewhere");
                    }
                }
                else if (remainingBytes >= 0)     // -> 0x0000 ... 0x0FFF
                {
                    nDumpSize = (recordBytesRemaining > (int)remainingBytes) ? (short)remainingBytes : (short)recordBytesRemaining;

                    if (nDumpSize != 0)
                    {
                        HexDump.Dump(in1, 0, nDumpSize);
                        remainingBytes -= nDumpSize;
                    }
                }
                else
                {
                    Console.WriteLine(" >> OVERRUN <<");
                }
            }
        }
        /**
         * Just so there is no ambiguity.  The two double values have to be exactly equal
         */
        private static void assertDouble(double a, double b)
        {
            long bitsA = BitConverter.DoubleToInt64Bits(a);
            long bitsB = BitConverter.DoubleToInt64Bits(b);

            if (bitsA != bitsB)
            {
                throw new ComparisonFailure("value different to expected",
                                            new string(HexDump.LongToHex(bitsA)), new string(HexDump.LongToHex(bitsB)));
            }
        }
        public override String ToXml(String tab)
        {
            String extraData;

            //MemoryStream b = new MemoryStream();
            try
            {
                //HexDump.Dump(this.field_pictureData, 0, b, 0);
                extraData = HexDump.ToHex(this.field_pictureData);
            }
            catch (Exception e)
            {
                extraData = e.ToString();
            }
            StringBuilder builder = new StringBuilder();

            builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)))
            .Append(tab).Append("\t").Append("<UID>0x").Append(HexDump.ToHex(field_1_UID)).Append("</UID>\n")
            .Append(tab).Append("\t").Append("<Marker>0x").Append(HexDump.ToHex(field_2_marker)).Append("</Marker>\n")
            .Append(tab).Append("\t").Append("<ExtraData>").Append(extraData).Append("</ExtraData>\n");
            builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
            return(builder.ToString());
        }
Exemple #23
0
        public override string ToXml(string tab)
        {
            string        theDumpHex = HexDump.ToHex(_thedata, 32);
            StringBuilder builder    = new StringBuilder();

            builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)))
            .Append(tab).Append("\t").Append("<IsContainer>").Append(IsContainerRecord).Append("</IsContainer>\n")
            .Append(tab).Append("\t").Append("<Numchildren>").Append(HexDump.ToHex(_childRecords.Count)).Append("</Numchildren>\n");
            for (IEnumerator <EscherRecord> iterator = _childRecords.GetEnumerator(); iterator.MoveNext();)
            {
                EscherRecord record = iterator.Current;
                builder.Append(record.ToXml(tab + "\t"));
            }
            builder.Append(theDumpHex).Append("\n");
            builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
            return(builder.ToString());
        }
Exemple #24
0
        public void TestSerialize()
        {
            UnknownEscherRecord r = new UnknownEscherRecord();

            r.Options  = (short)0x123F;
            r.RecordId = unchecked ((short)0xF112);
            byte[] data = new byte[8];
            r.Serialize(0, data);

            Assert.AreEqual("[3F, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.ToHex(data));

            EscherRecord childRecord = new UnknownEscherRecord();

            childRecord.Options  = unchecked ((short)0x9999);
            childRecord.RecordId = unchecked ((short)0xFF01);
            r.AddChildRecord(childRecord);
            data = new byte[16];
            r.Serialize(0, data);

            Assert.AreEqual("[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.ToHex(data));
        }
 public void Confirmshort(int expVal)
 {
     cmp(HexDump.ShortToHex(expVal), HexDump.ShortToHex(_bds.ReadUShort()));
 }
Exemple #26
0
        /**
         * Creates an instance and Fills the fields based on the data in the given buffer.
         *
         * @param data   The buffer Containing the Ole10Native record
         * @param offset The start offset of the record in the buffer
         * @param plain Specified 'plain' format without filename
         * @throws Ole10NativeException on invalid or unexcepted data format
         */
        public Ole10Native(byte[] data, int offset, bool plain)
        {
            int ofs = offset;        // current offset, Initialized to start

            if (data.Length < offset + 2)
            {
                throw new Ole10NativeException("data is too small");
            }

            totalSize = LittleEndian.GetInt(data, ofs);
            ofs      += LittleEndianConsts.INT_SIZE;

            if (plain)
            {
                dataBuffer = new byte[totalSize - 4];
                Array.Copy(data, 4, dataBuffer, 0, dataBuffer.Length);
                dataSize = totalSize - 4;

                byte[] oleLabel = new byte[8];
                Array.Copy(dataBuffer, 0, oleLabel, 0, Math.Min(dataBuffer.Length, 8));
                label    = "ole-" + HexDump.ToHex(oleLabel);
                fileName = label;
                command  = label;
            }
            else
            {
                flags1 = LittleEndian.GetShort(data, ofs);
                ofs   += LittleEndianConsts.SHORT_SIZE;
                int len = GetStringLength(data, ofs);
                label    = StringUtil.GetFromCompressedUnicode(data, ofs, len - 1);
                ofs     += len;
                len      = GetStringLength(data, ofs);
                fileName = StringUtil.GetFromCompressedUnicode(data, ofs, len - 1);
                ofs     += len;
                flags2   = LittleEndian.GetShort(data, ofs);
                ofs     += LittleEndianConsts.SHORT_SIZE;
                len      = LittleEndian.GetUnsignedByte(data, ofs);
                unknown1 = new byte[len];
                ofs     += len;
                len      = 3;
                unknown2 = new byte[len];
                ofs     += len;
                len      = GetStringLength(data, ofs);
                command  = StringUtil.GetFromCompressedUnicode(data, ofs, len - 1);
                ofs     += len;

                if (totalSize + LittleEndianConsts.INT_SIZE - ofs > LittleEndianConsts.INT_SIZE)
                {
                    dataSize = LittleEndian.GetInt(data, ofs);
                    ofs     += LittleEndianConsts.INT_SIZE;

                    if (dataSize > totalSize || dataSize < 0)
                    {
                        throw new Ole10NativeException("Invalid Ole10Native");
                    }

                    dataBuffer = new byte[dataSize];
                    Array.Copy(data, ofs, dataBuffer, 0, dataSize);
                    ofs += dataSize;

                    if (unknown1.Length > 0)
                    {
                        flags3 = LittleEndian.GetShort(data, ofs);
                        ofs   += LittleEndianConsts.SHORT_SIZE;
                    }
                    else
                    {
                        flags3 = 0;
                    }
                }
                else
                {
                    throw new Ole10NativeException("Invalid Ole10Native");
                }
            }
        }
 public void ConfirmLong(long expVal)
 {
     cmp(HexDump.LongToHex(expVal), HexDump.LongToHex(_bds.ReadLong()));
 }
Exemple #28
0
        public void Defaults()
        {
            Assert.Throws <ArgumentNullException>(() => HexDump.Format(null));

            Assert.Equal("", HexDump.Format(ByteSequence('a', 0)));

            Assert.Equal("0000    61 62 63 64 65 66                                   abcdef           ", HexDump.Format(ByteSequence('a', 6)));
            Assert.Equal("0000    61 62 63 64 65 66 67 68  69 6A 6B 6C 6D 6E 6F 70    abcdefgh ijklmnop", HexDump.Format(ByteSequence('a', 16)));

            Assert.Equal(
                "0000    61 62 63 64 65 66 67 68  69 6A 6B 6C 6D 6E 6F 70    abcdefgh ijklmnop" + Environment.NewLine +
                "0010    71 72 73 74 75 76 77 78  79 7A                      qrstuvwx yz      ",
                HexDump.Format(ByteSequence('a', 26)));

            Assert.Equal(
                "0000    61 62 63 64 65 66 67 68  69 6A 6B 6C 6D 6E 6F 70" + Environment.NewLine +
                "0010    71 72 73 74 75 76 77 78  79 7A                  ",
                HexDump.Format(ByteSequence('a', 26), includeAscii: false));

            Assert.Equal(
                "61 62 63 64 65 66 67 68  69 6A 6B 6C 6D 6E 6F 70    abcdefgh ijklmnop" + Environment.NewLine +
                "71 72 73 74 75 76 77 78  79 7A                      qrstuvwx yz      ",
                HexDump.Format(ByteSequence('a', 26), includeOffset: false));

            Assert.Equal(
                "61 62 63 64 65 66 67 68  69 6A 6B 6C 6D 6E 6F 70" + Environment.NewLine +
                "71 72 73 74 75 76 77 78  79 7A                  ",
                HexDump.Format(ByteSequence('a', 26), includeOffset: false, includeAscii: false));
        }
Exemple #29
0
        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append("[TEXT]\n");
            buffer.Append("    .horizontalAlignment  = ")
            .Append("0x").Append(HexDump.ToHex(HorizontalAlignment))
            .Append(" (").Append(HorizontalAlignment).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .verticalAlignment    = ")
            .Append("0x").Append(HexDump.ToHex(VerticalAlignment))
            .Append(" (").Append(VerticalAlignment).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .DisplayMode          = ")
            .Append("0x").Append(HexDump.ToHex(DisplayMode))
            .Append(" (").Append(DisplayMode).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .rgbColor             = ")
            .Append("0x").Append(HexDump.ToHex(RgbColor))
            .Append(" (").Append(RgbColor).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .x                    = ")
            .Append("0x").Append(HexDump.ToHex(X))
            .Append(" (").Append(X).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .y                    = ")
            .Append("0x").Append(HexDump.ToHex(Y))
            .Append(" (").Append(Y).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .width                = ")
            .Append("0x").Append(HexDump.ToHex(Width))
            .Append(" (").Append(Width).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .height               = ")
            .Append("0x").Append(HexDump.ToHex(Height))
            .Append(" (").Append(Height).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .options1             = ")
            .Append("0x").Append(HexDump.ToHex(Options1))
            .Append(" (").Append(Options1).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("         .autoColor                = ").Append(IsAutoColor).Append('\n');
            buffer.Append("         .showKey                  = ").Append(ShowKey).Append('\n');
            buffer.Append("         .showValue                = ").Append(ShowValue).Append('\n');
            buffer.Append("         .vertical                 = ").Append(IsVertical).Append('\n');
            buffer.Append("         .autoGeneratedText        = ").Append(IsAutoGeneratedText).Append('\n');
            buffer.Append("         .generated                = ").Append(IsGenerated).Append('\n');
            buffer.Append("         .autoLabelDeleted         = ").Append(IsAutoLabelDeleted).Append('\n');
            buffer.Append("         .autoBackground           = ").Append(IsAutoBackground).Append('\n');
            buffer.Append("         .rotation                 = ").Append(Rotation).Append('\n');
            buffer.Append("         .showCategoryLabelAsPercentage     = ").Append(ShowCategoryLabelAsPercentage).Append('\n');
            buffer.Append("         .showValueAsPercentage     = ").Append(ShowValueAsPercentage).Append('\n');
            buffer.Append("         .showBubbleSizes          = ").Append(ShowBubbleSizes).Append('\n');
            buffer.Append("         .showLabel                = ").Append(ShowLabel).Append('\n');
            buffer.Append("    .IndexOfColorValue    = ")
            .Append("0x").Append(HexDump.ToHex(IndexOfColorValue))
            .Append(" (").Append(IndexOfColorValue).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("    .options2             = ")
            .Append("0x").Append(HexDump.ToHex(Options2))
            .Append(" (").Append(Options2).Append(" )");
            buffer.Append(Environment.NewLine);
            buffer.Append("         .dataLabelPlacement       = ").Append(DataLabelPlacement).Append('\n');
            buffer.Append("    .textRotation         = ")
            .Append("0x").Append(HexDump.ToHex(TextRotation))
            .Append(" (").Append(TextRotation).Append(" )");
            buffer.Append(Environment.NewLine);

            buffer.Append("[/TEXT]\n");
            return(buffer.ToString());
        }
Exemple #30
0
        public override String ToXml(String tab)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)))
            .Append(tab).Append("\t").Append("<ShapeIdMax>").Append(field_1_shapeIdMax).Append("</ShapeIdMax>\n")
            .Append(tab).Append("\t").Append("<NumIdClusters>").Append(NumIdClusters).Append("</NumIdClusters>\n")
            .Append(tab).Append("\t").Append("<NumShapesSaved>").Append(field_3_numShapesSaved).Append("</NumShapesSaved>\n")
            .Append(tab).Append("\t").Append("<DrawingsSaved>").Append(field_4_drawingsSaved).Append("</DrawingsSaved>\n");
            builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
            return(builder.ToString());
        }