コード例 #1
0
ファイル: ElfVirtualAddressSpace.cs プロジェクト: tmds/clrmd
        public int Read(long position, byte[] buffer, int bufferOffset, int count)
        {
            int bytesRead = 0;

            while (bytesRead != count)
            {
                int i = 0;
                for (; i < _segments.Length; i++)
                {
                    ref ElfProgramHeader64 header = ref _segments[i].RefHeader;

                    long upperAddress = header.VirtualAddress + header.VirtualSize;
                    if (header.VirtualAddress <= position && position < upperAddress)
                    {
                        int  bytesToReadRange = (int)Math.Min(count - bytesRead, upperAddress - position);
                        long segmentOffset    = position - header.VirtualAddress;
                        int  bytesReadRange   = _segments[i].AddressSpace.Read(segmentOffset, buffer, bufferOffset, bytesToReadRange);
                        if (bytesReadRange == 0)
                        {
                            goto done;
                        }
                        position     += bytesReadRange;
                        bufferOffset += bytesReadRange;
                        bytesRead    += bytesReadRange;
                        break;
                    }
                }
                if (i == _segments.Length)
                {
                    break;
                }
            }
コード例 #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);
                }
            }