Guest User

Untitled

a guest
Jul 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Public Function WriteBytes(ByVal path As String, _
  2. ByVal OFFSET_POS As Long, ByVal data As Byte()) As Boolean
  3.  
  4. Dim handle As IntPtr = IntPtr.Zero
  5. handle = CreateFile(path, FileAccess.ReadWrite, FileShare.ReadWrite, _
  6. IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero)
  7.  
  8. Dim bytesWritten As UInteger
  9. Dim nativeOverlapped = New NativeOverlapped With {
  10. .OffsetLow = 0,
  11. .OffsetHigh = 0
  12. }
  13.  
  14.  
  15. Dim msg As Boolean = SetFilePointerEx(handle, OFFSET_POS, IntPtr.Zero,
  16. MoveMethod.FILE_CURRENT)
  17.  
  18. Debug.WriteLine(String.Format("{0}: Setting Sector to position {1} ", _
  19. msg, OFFSET_POS 512))
  20.  
  21.  
  22. If Not WriteFile(handle, data, CUInt(data.Length), _
  23. bytesWritten, nativeOverlapped) Then
  24.  
  25.  
  26. Debug.WriteLine(String.Format("Unable to write to the volume. Error code: {0}", Marshal.GetLastWin32Error()))
  27.  
  28.  
  29. Return False
  30. End If
  31. Return True
  32. End Function
Add Comment
Please, Sign In to add comment