Page 1 of 1

Recovery tool

Posted: Mon Mar 12, 2012 1:43 pm
by AnoPem
Does anyone know if it is posible to make an recovery tool in vb.net to recover deleted files when you have removed files from recycle bin. If so please make a tutorial :)

Re: Recovery tool

Posted: Tue Mar 13, 2012 12:06 am
by mandai
There are a few ways of doing data recovery.

If you have raw access to a drive you could use your own method to parse the filesystem, then you may be able to recreate deleted files.
You could also scan the disk for file data structures.

Re: Recovery tool

Posted: Tue Mar 13, 2012 2:43 pm
by MrAksel
Any way to get access to the raw data? I guess that would require a driver, and it might be hard to find one that suits your needs.

Re: Recovery tool

Posted: Wed Mar 14, 2012 12:53 am
by mandai
There is no reason why you would need to use a driver unless you want to bypass the operating system in some way or communicate directly with the hardware.

You can use the CreateFile function to access partitions/drives. Here is an example:
Code: Select all
    <DllImport("kernel32.dll")> Shared Function CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As UInteger, ByVal dwShareMode As UInteger, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As UInteger, ByVal dwFlagsAndAttributes As UInteger, ByVal hTemplateFile As IntPtr) As IntPtr
    End Function

    Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click

        Dim driveHandle As IntPtr = CreateFile("\\.\C:", IO.FileAccess.Read, IO.FileShare.ReadWrite, IntPtr.Zero, IO.FileMode.Open, 0, IntPtr.Zero)
        Dim safeDriveHandle As SafeFileHandle = New SafeFileHandle(driveHandle, True)

        Dim fs As FileStream = New FileStream(safeDriveHandle, FileAccess.Read)

        Dim data(512 - 1) As Byte
        Dim read As Integer = fs.Read(data, 0, data.Length)

        fs.Close()

        MsgBox("read " & read & " bytes")

    End Sub