B
B
bloodrazorr2015-11-22 16:31:03
Programming
bloodrazorr, 2015-11-22 16:31:03

How to write bytes to a specific disk sector c#?

Good day to all.
I am writing a program for guaranteed data destruction. The question arose about overwriting clusters where the file is located. At the current stage, it is not possible to jump to the specified position on the disk. Tried to use a function that SetFilePointerreturns -1.

SafeFileHandle hDrive = CreateFile("\\\\.\\" + fileRoot, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if (SetFilePointerEx(hDrive, start, &start2, 0) != -1)
{
    ...
    WriteFile(hDrive, buff, buff.Length, &retBytes, null)
}

What can you advise and how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2015-11-22
@vilgeforce

I advise you to call GetLastError on an error and see what it returns. Without an error code - fortune-telling on the coffee grounds.

N
nirvimel, 2015-11-22
@nirvimel

The question arose about overwriting clusters where the .

If this is the only problem, then you can overwrite the contents of the file itself.
This won't work on Copy-on-write filesystems, but it doesn't seem to work on windows.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question