/// <summary> /// Read the specified number of bytes. /// </summary> /// <param name="addressSpace">The address space to read from</param> /// <param name="position">The position in the address space to start reading from</param> /// <param name="count">The number of bytes to read</param> /// <returns> /// Returns an array of exactly "count" bytes or throw an exception. /// </returns> /// <throws> /// BadInputFormatException to indicate an "unexpected end of stream" condition /// </throws> public static byte[] Read(this IAddressSpace addressSpace, ulong position, uint count) { byte[] bytes = ArrayHelper.New <byte>(count); if (count != addressSpace.Read(position, bytes, 0, count)) { throw new BadInputFormatException("Unable to read bytes at offset 0x" + position.ToString("x")); } return(bytes); }
public uint Read(ulong position, byte[] buffer, uint bufferOffset, uint count) { ulong max = position + count; if (max > Max) { Max = max; } return(_addressSpace.Read(position, buffer, bufferOffset, count)); }
/// <summary> /// Reads a range of bytes from the address space /// </summary> /// <param name="position">The position in the address space to begin reading from</param> /// <param name="buffer">The buffer that will receive the bytes that are read</param> /// <param name="bufferOffset">The offset in the output buffer to begin writing the bytes</param> /// <param name="count">The number of bytes to read into the buffer</param> /// <returns>The number of bytes read</returns> public uint Read(ulong position, byte[] buffer, uint bufferOffset, uint count) { ulong basePosition = (ulong)((long)position - _baseToRelativeShift); if (basePosition < _baseStart) { return(0); } count = (uint)Math.Min(count, _length); return(_baseAddressSpace.Read(basePosition, buffer, bufferOffset, count)); }
public override object Read(IAddressSpace dataSource, ulong position) { byte[] buffer = dataSource.Read(position, 2); if (IsBigEndian) { return((char)((buffer[0] << 8) | buffer[1])); } else { return((char)((buffer[1] << 8) | buffer[0])); } }
public override object Read(IAddressSpace dataSource, ulong position) { byte[] buffer = dataSource.Read(position, 4); if (IsBigEndian) { return((uint)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3])); } else { return((uint)((buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8) | buffer[0])); } }
public override object Read(IAddressSpace dataSource, ulong position) { byte[] buffer = dataSource.Read(position, 8); if (IsBigEndian) { return(((ulong)buffer[0] << 56) | ((ulong)buffer[1] << 48) | ((ulong)buffer[2] << 40) | ((ulong)buffer[3] << 32) | ((ulong)buffer[4] << 24) | ((ulong)buffer[5] << 16) | ((ulong)buffer[6] << 8) | (ulong)buffer[7]); } else { return(((ulong)buffer[7] << 56) | ((ulong)buffer[6] << 48) | ((ulong)buffer[5] << 40) | ((ulong)buffer[4] << 32) | ((ulong)buffer[3] << 24) | ((ulong)buffer[2] << 16) | ((ulong)buffer[1] << 8) | (ulong)buffer[0]); } }
public override object Read(IAddressSpace dataSource, ulong position) { byte[] buffer = dataSource.Read(position, 4); if (IsBigEndian == BitConverter.IsLittleEndian) { byte temp = buffer[0]; buffer[0] = buffer[3]; buffer[3] = temp; temp = buffer[1]; buffer[1] = buffer[2]; buffer[2] = temp; } return(BitConverter.ToSingle(buffer, 0)); }
public uint Read(ulong position, byte[] buffer, uint bufferOffset, uint count) { ImageSectionHeader segment = _segments.Where(header => header.VirtualAddress <= position && position <= header.VirtualAddress + header.VirtualSize).FirstOrDefault(); if (segment == null) { return(0); } ulong offset = _baseAddress + position - segment.VirtualAddress + segment.PointerToRawData; uint result = _addressSpace.Read(offset, buffer, bufferOffset, count); return(result); }
public int Read(long position, Span <byte> buffer) { long basePosition = position - _baseToRelativeShift; if (basePosition < _baseStart) { return(0); } if (_length < buffer.Length) { buffer = buffer.Slice(0, (int)_length); } return(_baseAddressSpace.Read(basePosition, buffer)); }
public uint Read(ulong position, byte[] buffer, uint bufferOffset, uint count) { if (count == 0) { return(0); } MinidumpSegment seg = FindSegment(position); if (seg == null) { return(0); } // TODO: What if they read past the end of the segment? Debug.Assert(position >= seg.VirtualAddress); ulong offset = position - seg.VirtualAddress + seg.FileOffset; return(_addressSpace.Read(offset, buffer, bufferOffset, count)); }
public object Read(IAddressSpace dataSource, ulong position, out uint bytesRead) { List <byte> stringBytes = new List <byte>(); byte[] buffer = new byte[1]; uint offset = 0; for (; ; offset++) { byte[] nextByte = dataSource.Read(position + offset, 1); if (nextByte[0] == 0) { break; } else { stringBytes.Add(nextByte[0]); } } bytesRead = offset + 1; return(_encoding.GetString(stringBytes.ToArray(), 0, stringBytes.Count)); }
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); } }
public uint Read(ulong position, byte[] buffer, uint bufferOffset, uint count) { if (position + count > Length) { throw new BadInputFormatException("Unexpected end of data: Expected " + count + " bytes."); } uint bytesRead = 0; while (bytesRead != count) { ulong virtualAddressToRead = position + bytesRead; uint virtualPageOffset; ulong physicalPosition = GetPhysicalAddress(position, out virtualPageOffset); uint pageBytesToRead = Math.Min(_pageSize - virtualPageOffset, count - bytesRead); uint pageBytesRead = _physicalAddresses.Read(physicalPosition, buffer, bufferOffset + bytesRead, pageBytesToRead); bytesRead += pageBytesRead; if (pageBytesToRead != pageBytesRead) { break; } } return(bytesRead); }
public override object Read(IAddressSpace dataSource, ulong position) { byte[] buffer = dataSource.Read(position, 1); return(buffer[0]); }
public uint Read(ulong position, byte[] buffer, uint bufferOffset, uint count) { return(DataSource.Read(position, buffer, bufferOffset, count)); }