예제 #1
0
        /// <summary>
        /// Reads the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public void Read(System.IO.BinaryReader reader)
        {
            Ident = reader.ReadBytes(16);

            // Check for magic number
            if (Ident[0] != MagicNumber[0] || Ident[1] != MagicNumber[1] || Ident[2] != MagicNumber[2] || Ident[3] != MagicNumber[3])
            {
                // Magic number not present, so it seems to be an invalid ELF file
                throw new NotSupportedException("This is not a valid ELF file");
            }

            Type                     = (Elf32FileType)reader.ReadUInt16();
            Machine                  = (Elf32MachineType)reader.ReadUInt16();
            Version                  = (Elf32Version)reader.ReadUInt32();
            EntryAddress             = reader.ReadUInt32();
            ProgramHeaderOffset      = reader.ReadUInt32();
            SectionHeaderOffset      = reader.ReadUInt32();
            Flags                    = reader.ReadUInt32();
            ElfHeaderSize            = reader.ReadUInt16();
            ProgramHeaderEntrySize   = reader.ReadUInt16();
            ProgramHeaderNumber      = reader.ReadUInt16();
            SectionHeaderEntrySize   = reader.ReadUInt16();
            SectionHeaderNumber      = reader.ReadUInt16();
            SectionHeaderStringIndex = reader.ReadUInt16();
        }
예제 #2
0
        /// <summary>
        /// Creates the ident.
        /// </summary>
        /// <param name="identClass">The ident class.</param>
        /// <param name="data">The data.</param>
        /// <param name="padding">The padding.</param>
        public void CreateIdent(Elf32IdentClass identClass, Elf32IdentData data, byte[] padding)
        {
            // Store magic number
            Ident[0] = MagicNumber[0];
            Ident[1] = MagicNumber[1];
            Ident[2] = MagicNumber[2];
            Ident[3] = MagicNumber[3];

            // Store class
            Ident[4] = (byte)identClass;
            // Store data flags
            Ident[5] = (byte)data;
            // Version has to be current, otherwise the file won't load
            Ident[6] = (byte)Elf32Version.Current;
            Version  = Elf32Version.Current;

            // Set padding byte to
            Ident[7] = 0x07;

            for (int i = 8; i < 16; ++i)
            {
                Ident[i] = 0x00;
            }
        }
예제 #3
0
        /// <summary>
        /// Reads the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public void Read(System.IO.BinaryReader reader)
        {
            Ident = reader.ReadBytes(16);

            // Check for magic number
            if (Ident[0] != MagicNumber[0] || Ident[1] != MagicNumber[1] || Ident[2] != MagicNumber[2] || Ident[3] != MagicNumber[3])
            {
                // Magic number not present, so it seems to be an invalid ELF file
                throw new NotSupportedException("This is not a valid ELF file");
            }

            Type = (Elf32FileType)reader.ReadUInt16();
            Machine = (Elf32MachineType)reader.ReadUInt16();
            Version = (Elf32Version)reader.ReadUInt32();
            EntryAddress = reader.ReadUInt32();
            ProgramHeaderOffset = reader.ReadUInt32();
            SectionHeaderOffset = reader.ReadUInt32();
            Flags = reader.ReadUInt32();
            ElfHeaderSize = reader.ReadUInt16();
            ProgramHeaderEntrySize = reader.ReadUInt16();
            ProgramHeaderNumber = reader.ReadUInt16();
            SectionHeaderEntrySize = reader.ReadUInt16();
            SectionHeaderNumber = reader.ReadUInt16();
            SectionHeaderStringIndex = reader.ReadUInt16();
        }
예제 #4
0
        /// <summary>
        /// Creates the ident.
        /// </summary>
        /// <param name="identClass">The ident class.</param>
        /// <param name="data">The data.</param>
        /// <param name="padding">The padding.</param>
        public void CreateIdent(Elf32IdentClass identClass, Elf32IdentData data, byte[] padding)
        {
            // Store magic number
            Ident[0] = MagicNumber[0];
            Ident[1] = MagicNumber[1];
            Ident[2] = MagicNumber[2];
            Ident[3] = MagicNumber[3];

            // Store class
            Ident[4] = (byte)identClass;
            // Store data flags
            Ident[5] = (byte)data;
            // Version has to be current, otherwise the file won't load
            Ident[6] = (byte)Elf32Version.Current;
            Version = Elf32Version.Current;

            // Set padding byte to
            Ident[7] = 0x07;

            for (int i = 8; i < 16; ++i)
                Ident[i] = 0x00;
        }