/// <summary> /// take a snapshot of the entire memory block's contents, for use in GetXorStream /// </summary> public void SaveXorSnapshot() { if (_snapshot != null) { throw new InvalidOperationException("Snapshot already taken"); } if (!Active) { throw new InvalidOperationException("Not active"); } // temporarily switch the entire block to `R`: in case some areas are unreadable, we don't want // that to complicate things Kernel32.MemoryProtection old; if (!Kernel32.VirtualProtect(Z.UU(Start), Z.UU(Size), Kernel32.MemoryProtection.READONLY, out old)) { throw new InvalidOperationException($"{nameof(Kernel32.VirtualProtect)}() returned FALSE!"); } _snapshot = new byte[Size]; var ds = new MemoryStream(_snapshot, true); var ss = GetStream(Start, Size, false); ss.CopyTo(ds); XorHash = WaterboxUtils.Hash(_snapshot); ProtectAll(); }
/// <summary> /// take a snapshot of the entire memory block's contents, for use in GetXorStream /// </summary> public override void SaveXorSnapshot() { if (_snapshot != null) { throw new InvalidOperationException("Snapshot already taken"); } if (!Active) { throw new InvalidOperationException("Not active"); } // temporarily switch the entire block to `R`: in case some areas are unreadable, we don't want // that to complicate things if (mprotect(Z.US(Start), Z.UU(Size), MemoryProtection.Read) != 0) { throw new InvalidOperationException("mprotect() returned -1!"); } _snapshot = new byte[Size]; var ds = new MemoryStream(_snapshot, true); var ss = GetStream(Start, Size, false); ss.CopyTo(ds); XorHash = WaterboxUtils.Hash(_snapshot); ProtectAll(); }
/// <summary> /// take a hash of the current full contents of the block, including unreadable areas /// </summary> /// <returns></returns> public override byte[] FullHash() { if (!Active) { throw new InvalidOperationException("Not active"); } // temporarily switch the entire block to `R` if (mprotect(Z.US(Start), Z.UU(Size), MemoryProtection.Read) != 0) { throw new InvalidOperationException("mprotect() returned -1!"); } var ret = WaterboxUtils.Hash(GetStream(Start, Size, false)); ProtectAll(); return(ret); }
/// <summary> /// take a hash of the current full contents of the block, including unreadable areas /// </summary> public byte[] FullHash() { if (!Active) { throw new InvalidOperationException("Not active"); } // temporarily switch the entire block to `R` Kernel32.MemoryProtection old; if (!Kernel32.VirtualProtect(Z.UU(Start), Z.UU(Size), Kernel32.MemoryProtection.READONLY, out old)) { throw new InvalidOperationException($"{nameof(Kernel32.VirtualProtect)}() returned FALSE!"); } var ret = WaterboxUtils.Hash(GetStream(Start, Size, false)); ProtectAll(); return(ret); }
/// <exception cref="InvalidOperationException"><see cref="MemoryBlockBase.Active"/> is <see langword="false"/> or failed to make memory read-only</exception> public override byte[] FullHash() { if (!Active) { throw new InvalidOperationException("Not active"); } // temporarily switch the entire block to `R` var exitCode = mprotect(Z.US(AddressRange.Start), Z.UU(Size), MemoryProtection.Read); if (exitCode != 0) { throw new InvalidOperationException($"{nameof(mprotect)}() returned {exitCode}!"); } var ret = WaterboxUtils.Hash(GetStream(AddressRange.Start, Size, false)); ProtectAll(); return(ret); }
/// <exception cref="InvalidOperationException">snapshot already taken, <see cref="MemoryBlockBase.Active"/> is <see langword="false"/>, or failed to make memory read-only</exception> public override void SaveXorSnapshot() { if (_snapshot != null) { throw new InvalidOperationException("Snapshot already taken"); } if (!Active) { throw new InvalidOperationException("Not active"); } // temporarily switch the entire block to `R`: in case some areas are unreadable, we don't want that to complicate things var exitCode = mprotect(Z.US(AddressRange.Start), Z.UU(Size), MemoryProtection.Read); if (exitCode != 0) { throw new InvalidOperationException($"{nameof(mprotect)}() returned {exitCode}!"); } _snapshot = new byte[Size]; GetStream(AddressRange.Start, Size, false).CopyTo(new MemoryStream(_snapshot, true)); XorHash = WaterboxUtils.Hash(_snapshot); ProtectAll(); }