0

I am receiving Error 5 Access Denied Exception when trying to overwrite Sectors belonging to System files, but can succeed on other Sectors just fine. I then have dismounted (mountvol X: /p) the particular Partition that is linked to them Sectors but to no avail. I need a solution because I am conducting an experiment with the goal to better understand and ultimately being able to repair damaged $MFT. Thanks.

The path is "\\.\PhysicalDrive1"

    Public Function WriteBytes(ByVal path As String, _
                  ByVal OFFSET_POS As Long, ByVal data As Byte()) As Boolean

   Dim handle As IntPtr = IntPtr.Zero
   handle = CreateFile(path, FileAccess.ReadWrite, FileShare.ReadWrite, _
                  IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero)

   Dim bytesWritten As UInteger
   Dim nativeOverlapped = New NativeOverlapped With {
                .OffsetLow = 0,
                .OffsetHigh = 0
   }


   Dim msg As Boolean = SetFilePointerEx(handle, OFFSET_POS, IntPtr.Zero, 
                  MoveMethod.FILE_CURRENT)

   Debug.WriteLine(String.Format("{0}: Setting Sector to position {1} ", _
   msg, OFFSET_POS \ 512))


   If Not WriteFile(handle, data, CUInt(data.Length), _
                  bytesWritten, nativeOverlapped) Then


        Debug.WriteLine(String.Format("Unable to write to the volume. Error code: {0}", Marshal.GetLastWin32Error()))


        Return False
   End If 
   Return True
End Function

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.