示例#1
0
        public ElfProgramHeader(Reader reader, long headerPositon, long fileOffset, bool virt = false)
        {
            _reader = reader;
            _header = _reader.Read <ELFProgramHeader64>(headerPositon);

            if (virt && _header.Type == ELFProgramHeaderType.Load)
            {
                AddressSpace = new RelativeAddressSpace(reader.DataSource, "ProgramHeader", _header.VirtualAddress, _header.VirtualSize);
            }
            else
            {
                AddressSpace = new RelativeAddressSpace(reader.DataSource, "ProgramHeader", fileOffset + _header.FileOffset, _header.FileSize);
            }
        }
示例#2
0
        public int Read(long position, byte[] buffer, int bufferOffset, int count)
        {
            for (int i = 0; i < _segments.Count; i++)
            {
                ref ELFProgramHeader64 header = ref _segments[i].RefHeader;
                // FileSize == 0 means the segment isn't backed by any data
                if (header.FileSize > 0 && header.VirtualAddress <= position && position + count <= header.VirtualAddress + header.VirtualSize)
                {
                    long segmentOffset = position - header.VirtualAddress;
                    int  fileBytes     = (int)Math.Min(count, header.FileSize);

                    long fileOffset = header.FileOffset + segmentOffset;
                    int  bytesRead  = _addressSpace.Read(fileOffset, buffer, bufferOffset, fileBytes);

                    //zero the rest of the buffer if it is in the virtual address space but not the physical address space
                    if (bytesRead == fileBytes && fileBytes != count)
                    {
                        Array.Clear(buffer, bufferOffset + fileBytes, count - fileBytes);
                        bytesRead = count;
                    }

                    return(bytesRead);
                }
            }