예제 #1
0
        public UInt16 Write(Stream stream, HeaderIdentityClass EI_CLASS)
        {
            UInt16 headerLength = 0;

            headerLength += stream.WriteWord((UInt32)SH_NAME);
            headerLength += stream.WriteWord((UInt32)SH_TYPE);
            headerLength += stream.WriteWord((UInt32)SH_FLAGS);
            headerLength += stream.WriteAddress32(SH_ADDR);
            headerLength += stream.WriteOffset32(SH_OFFSET);
            headerLength += stream.WriteWord((UInt32)SH_SIZE);
            headerLength += stream.WriteWord((UInt32)SH_LINK);
            headerLength += stream.WriteWord((UInt32)SH_INFO);
            headerLength += stream.WriteWord((UInt32)SH_ADDRALIGN);
            headerLength += stream.WriteWord((UInt32)SH_ENTSIZE);

            return(headerLength);
        }
예제 #2
0
        public void Read(Stream stream)
        {
            var magic = new byte[MAGIC.Length];

            stream.Read(magic);
            if (!MAGIC.SequenceEqual(magic))
            {
                throw new BadImageFormatException("Magic value is not present for an ELF file");
            }

            EI_CLASS      = stream.ReadByteAndParse <HeaderIdentityClass>(HeaderIdentityClass.ELFCLASSNONE);
            EI_DATA       = stream.ReadByteAndParse <HeaderIdentityData>(HeaderIdentityData.ELFDATANONE);
            EI_VERSION    = stream.ReadByteAndParse <HeaderIdentityVersion>(HeaderIdentityVersion.EI_CURRENT);
            EI_OSABI      = stream.ReadByteAndParse <HeaderOsAbiVersion>(HeaderOsAbiVersion.ELFOSABI_NONE);
            EI_ABIVERSION = (byte)stream.ReadByte();

            stream.Seek(16, SeekOrigin.Begin);
            E_TYPE      = stream.ReadHalfWord <HeaderType>(HeaderType.ET_NONE);
            E_MACHINE   = stream.ReadHalfWord <HeaderMachine>(HeaderMachine.EM_NONE);
            E_VERSION   = stream.ReadWord <HeaderVersion>(HeaderVersion.EV_NONE);
            E_ENTRY     = stream.ReadAddress32();
            E_PHOFF     = stream.ReadOffset32();
            E_SHOFF     = stream.ReadOffset32();
            E_FLAGS     = stream.ReadUInt32();
            E_EHSIZE    = stream.ReadUInt16();
            E_PHENTSIZE = stream.ReadUInt16();
            E_PHNUM     = stream.ReadUInt16();
            E_SHENTSIZE = stream.ReadUInt16();
            E_SHNUM     = stream.ReadUInt16();
            E_SHSTRNDX  = stream.ReadUInt16();

            if (E_EHSIZE != stream.Position && E_EHSIZE != 64)
            {
                throw new InvalidOperationException("E_EHSIZE does not equal the current reader position");
            }
        }