public static void RemoveIntegrityStream(SafeFileHandle handle) { var oldInfo = new NativeMethods.FSCTL_GET_INTEGRITY_INFORMATION_BUFFER(); var oldInfoSizeReturn = 0; if (!NativeMethods.DeviceIoControl(handle, NativeMethods.FSCTL_GET_INTEGRITY_INFORMATION, IntPtr.Zero, 0, ref oldInfo, Marshal.SizeOf(oldInfo), out oldInfoSizeReturn, IntPtr.Zero)) { try { throw new Win32Exception(); } catch (Win32Exception ex) { throw new InvalidOperationException(ex.Message, ex); } } if (oldInfo.ChecksumAlgorithm == NativeMethods.CHECKSUM_TYPE_NONE) { return; } //already done var newInfo = new NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION_BUFFER() { ChecksumAlgorithm = NativeMethods.CHECKSUM_TYPE_NONE, Flags = oldInfo.Flags }; var newInfoSizeReturn = 0; if (!NativeMethods.DeviceIoControl(handle, NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION, ref newInfo, Marshal.SizeOf(newInfo), IntPtr.Zero, 0, out newInfoSizeReturn, IntPtr.Zero)) { try { throw new Win32Exception(); } catch (Win32Exception ex) { throw new InvalidOperationException(ex.Message, ex); } } }
public static void RemoveIntegrityStream(SafeFileHandle handle) { var oldInfo = new NativeMethods.FSCTL_GET_INTEGRITY_INFORMATION_BUFFER(); var oldInfoSizeReturn = 0; if (!NativeMethods.DeviceIoControl(handle, NativeMethods.FSCTL_GET_INTEGRITY_INFORMATION, IntPtr.Zero, 0, ref oldInfo, Marshal.SizeOf(oldInfo), out oldInfoSizeReturn, IntPtr.Zero)) { try { throw new Win32Exception(); } catch (Win32Exception ex) { throw new InvalidOperationException(ex.Message, ex); } } if (oldInfo.ChecksumAlgorithm == NativeMethods.CHECKSUM_TYPE_NONE) { return; } //already done var newInfo = new NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION_BUFFER() { ChecksumAlgorithm = NativeMethods.CHECKSUM_TYPE_NONE, Flags = oldInfo.Flags }; var newInfoSizeReturn = 0; if (!NativeMethods.DeviceIoControl(handle, NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION, ref newInfo, Marshal.SizeOf(newInfo), IntPtr.Zero, 0, out newInfoSizeReturn, IntPtr.Zero)) { try { throw new Win32Exception(); } catch (Win32Exception ex) { throw new InvalidOperationException(ex.Message, ex); } } }