public PeImageLoader(IServiceProvider services, string filename, byte [] img, uint peOffset) : base(services, filename, img) { ImageReader rdr = new LeImageReader(RawImage, peOffset); if (rdr.ReadByte() != 'P' || rdr.ReadByte() != 'E' || rdr.ReadByte() != 0x0 || rdr.ReadByte() != 0x0) { throw new BadImageFormatException("Not a valid PE header."); } importThunks = new Dictionary<uint, PseudoProcedure>(); importReferences = new Dictionary<Address, ImportReference>(); short expectedMagic = ReadCoffHeader(rdr); ReadOptionalHeader(rdr, expectedMagic); }
public byte[] GetBytes() { byte[] data; var stm = new MemoryStream(); var rdr = new LeImageReader(image, (uint) offset); byte trackNext = rdr.ReadByte(); while (trackNext != 0) { byte sectorNext = rdr.ReadByte(); data = rdr.ReadBytes(0xFE); stm.Write(data, 0, data.Length); rdr.Offset = (uint) SectorOffset(trackNext, sectorNext); trackNext = rdr.ReadByte(); } byte lastUsed = rdr.ReadByte(); data = rdr.ReadBytes(lastUsed - 2); stm.Write(data, 0, data.Length); return stm.ToArray(); }
public bool ReadDirectorySector(LeImageReader rdr, List<ArchiveDirectoryEntry> entries) { byte nextDirTrack = 0; byte nextDirSector = 0; for (int i = 0; i < 8; ++i) { if (i == 0) { nextDirTrack = rdr.ReadByte(); nextDirSector = rdr.ReadByte(); } else { rdr.Seek(2); } var fileType = (FileType) rdr.ReadByte(); var fileTrack = rdr.ReadByte(); var fileSector = rdr.ReadByte(); var sName = Encoding.ASCII.GetString(rdr.ReadBytes(16)) .TrimEnd((char) 0xA0); var relTrack = rdr.ReadByte(); var relSector = rdr.ReadByte(); var rel = rdr.ReadByte(); rdr.Seek(6); var sectorSize = rdr.ReadLeInt16(); if ((fileType & FileType.FileTypeMask) != FileType.DEL) { entries.Add(new D64FileEntry( sName, RawImage, SectorOffset(fileTrack, fileSector), fileType)); } } if (nextDirTrack != 0) { rdr.Offset = (uint) SectorOffset(nextDirTrack, nextDirSector); return true; } else { return false; } }
public List<ArchiveDirectoryEntry> LoadDiskDirectory() { var entries = new List<ArchiveDirectoryEntry>(); var rdr = new LeImageReader(RawImage, (uint)SectorOffset(18, 0)); byte track = rdr.ReadByte(); if (track == 0) return entries; byte sector = rdr.ReadByte(); rdr.Offset = (uint) D64Loader.SectorOffset(track, sector); while (ReadDirectorySector(rdr, entries)) ; return entries; }