private void LoadHeaderAndStreams(PeHeaderReader pe, MemoryMappedViewAccessor mm) { var clrDataDir = pe.DataDirectories[PeHeaderReader.Image_Directory_Entry_Type.COM_DESCRIPTOR]; if (Marshal.SizeOf(typeof(IMAGE_COR20_HEADER)) != clrDataDir.Size) throw new Exception("Size wrong."); mm.Read<IMAGE_COR20_HEADER>(pe.GetFileOffset(clrDataDir.VirtualAddress), out mHeader); if (mHeader.cb != clrDataDir.Size) throw new Exception("Size wrong."); var metaLoc = pe.GetFileOffset(mHeader.MetaData.VirtualAddress); mm.Read<MetaDataHeaderPart1>(metaLoc, out mMetaHeader); var versionBytes = new byte[mMetaHeader.VersionLength]; metaLoc += Marshal.SizeOf(typeof(MetaDataHeaderPart1)); mm.ReadArray<byte>(metaLoc, versionBytes, 0, versionBytes.Length); int versionSize = 0; while (versionSize < versionBytes.Length && versionBytes[versionSize] != 0) versionSize++; mVersionName = Encoding.ASCII.GetString(versionBytes, 0, versionSize); metaLoc += mMetaHeader.VersionLength; mMetaDataFlags = mm.ReadUInt16(metaLoc); metaLoc += 2; uint numberOfMetaStreams = mm.ReadUInt16(metaLoc); metaLoc += 2; for (int i = 0; i < numberOfMetaStreams; i++) { MetaDataStream mds; mm.Read<MetaDataStream>(metaLoc, out mds); metaLoc += Marshal.SizeOf(typeof(MetaDataStream)); byte b; StringBuilder sb = new StringBuilder(); while ((b = mm.ReadByte(metaLoc++)) != 0) { sb.Append((char)b); } metaLoc += 3; metaLoc &= ~3; mMetaStreams.Add(sb.ToString(), mds); } }
public byte Read(long T, MemoryMappedViewAccessor stream) { //byte[] buffer = new byte[1]; // long Temp = stream.Position; // stream.Position = (long)Math.Floor(T / 8.0); // BinaryReader reader = new BinaryReader(stream); byte lol = default(byte); try { stream.Read<byte>(0, out lol); } catch { return default(byte); } //stream.Position = Temp; return lol; }
private static CacheNotifyDataMapInfo InnerResetData(MemoryMappedViewAccessor accessor) { for (int i = 0; i < GetTotalMemorySize(); i++) accessor.Write(i, (byte)0); CacheNotifyDataMapInfo mapInfo; accessor.Read(0, out mapInfo); mapInfo.Mark = CacheNotifyDataMapInfo.Tag; accessor.Write(0, ref mapInfo); return mapInfo; }
private static long InnerReadCacheNotifyData(long lastTicks, MemoryMappedViewAccessor accessor, CacheNotifyDataMapInfo mapInfo, List<CacheNotifyData> result) { int itemSize = Marshal.SizeOf(typeof(CacheNotifyDataMapItem)); long returnTicks = lastTicks; long startPointer = Marshal.SizeOf(typeof(CacheNotifyDataMapInfo)); for (int i = 0; i < CacheNotifyDataMapInfo.CacheDataItemCount; i++) { CacheNotifyDataMapItem item; accessor.Read(startPointer, out item); if (item.Ticks > lastTicks) { if (item.Ticks > returnTicks) returnTicks = item.Ticks; byte[] data = new byte[item.Size]; accessor.ReadArray(startPointer + itemSize, data, 0, (int)item.Size); CacheNotifyData cnd = CacheNotifyData.FromBuffer(data); result.Add(cnd); } startPointer += itemSize + CacheNotifyDataMapInfo.CacheDataBlockSize; } return returnTicks; }
private void LoadMetaTable(PeHeaderReader pe, MemoryMappedViewAccessor mm) { long loc = pe.GetFileOffset(mHeader.MetaData.VirtualAddress + mMetaStreams["#~"].Offset); mm.Read<TableHeader>(loc, out mTableHeader); Console.WriteLine(); }