Exemplo n.º 1
0
        public RpxHeader(string rpxFilePath)
        {
            identity = new byte[ELF_SIGNATURE_LENGTH];

            using (FileStream fs = new FileStream(rpxFilePath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding()))
                {
                    // Read in the header
                    identity   = br.ReadBytes(ELF_SIGNATURE_LENGTH);
                    type       = EndianUtility.ReadUInt16BE(br);
                    machine    = EndianUtility.ReadUInt16BE(br);
                    version    = EndianUtility.ReadUInt32BE(br);
                    entryPoint = EndianUtility.ReadUInt32BE(br);
                    phOffset   = EndianUtility.ReadUInt32BE(br);
                    shOffset   = EndianUtility.ReadUInt32BE(br);
                    flags      = EndianUtility.ReadUInt32BE(br);
                    ehSize     = EndianUtility.ReadUInt16BE(br);
                    phEntSize  = EndianUtility.ReadUInt16BE(br);
                    phNum      = EndianUtility.ReadUInt16BE(br);
                    shEntSize  = EndianUtility.ReadUInt16BE(br);
                    shNum      = EndianUtility.ReadUInt16BE(br);
                    shStrIndex = EndianUtility.ReadUInt16BE(br);
                }
            }

            sHeaderDataElfOffset = (ulong)(shOffset + (shNum * shEntSize));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RpxHeader"/> class.
        /// </summary>
        /// <param name="rpxFilePath">path to RPX file.</param>
        public RpxHeader(string rpxFilePath)
        {
            this.identity = new byte[ElfSignatureLength];

            using (FileStream fs = new FileStream(rpxFilePath, FileMode.Open, FileAccess.Read))
            {
                using BinaryReader br = new BinaryReader(fs, new ASCIIEncoding());

                // Read in the header
                this.identity   = br.ReadBytes(ElfSignatureLength);
                this.type       = EndianUtility.ReadUInt16BE(br);
                this.machine    = EndianUtility.ReadUInt16BE(br);
                this.version    = EndianUtility.ReadUInt32BE(br);
                this.entryPoint = EndianUtility.ReadUInt32BE(br);
                this.phOffset   = EndianUtility.ReadUInt32BE(br);
                this.shOffset   = EndianUtility.ReadUInt32BE(br);
                this.flags      = EndianUtility.ReadUInt32BE(br);
                this.ehSize     = EndianUtility.ReadUInt16BE(br);
                this.phEntSize  = EndianUtility.ReadUInt16BE(br);
                this.phNum      = EndianUtility.ReadUInt16BE(br);
                this.shEntSize  = EndianUtility.ReadUInt16BE(br);
                this.shNum      = EndianUtility.ReadUInt16BE(br);
                this.shStrIndex = EndianUtility.ReadUInt16BE(br);
            }

            this.sHeaderDataElfOffset = (ulong)(this.shOffset + (this.shNum * this.shEntSize));
        }
Exemplo n.º 3
0
        public void ReadUInt16BE_WithValidUint16_ReadsData()
        {
            using MemoryStream ms = new MemoryStream(new byte[] { 0x10, 0x0 });
            using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding());
            var result = EndianUtility.ReadUInt16BE(br);

            Assert.Equal(4096u, result);
        }
Exemplo n.º 4
0
        public void WriteUInt16BE_WithUInt16_WritesData()
        {
            using MemoryStream ms = new MemoryStream(new byte[2]);
            using BinaryWriter bw = new BinaryWriter(ms);
            EndianUtility.WriteUInt16BE(bw, 1234);
            ms.Seek(0, SeekOrigin.Begin);
            using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding());

            Assert.Equal(1234, EndianUtility.ReadUInt16BE(br));
        }
Exemplo n.º 5
0
 public void ReadUInt16BE_WithInvalidUint16_ThrowsException()
 {
     using MemoryStream ms = new MemoryStream(new byte[] { 0x10 });
     using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding());
     Assert.Throws <System.IO.EndOfStreamException>(() => EndianUtility.ReadUInt16BE(br));
 }