Results 1 to 5 of 5

Thread: Drive Raw Access

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    137

    Drive Raw Access

    Hey guys i know i have not been here in a long time but been moving around alot.

    Can anyone spare some info on how to access a SD card RAW?

    I am currently working on PIC microcontrollers and can read/write data to a SD Card but RAW. I was woundering how would i do the same on a PC.

    I can use either:
    VB6
    VS.NET EXPRESS

    Any links or examples would rock! thanks!
    Live to love, Not to hate

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    137

    Re: Drive Raw Access

    Found someones old code and fixed it:
    Code:
    Public Function ReadDrive(BytesToRead As Long)
    Dim dh As Long, ret As Long
    Dim strBuffer As String
    Dim lngRead As Long
    Dim bBytes() As Byte
    Dim x As Long
    
    ReDim bBytes(1 To BytesToRead) As Byte
    
    dh = CreateFile("\\.\D:", GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, ByVal CLng(0), OPEN_EXISTING, ByVal FILE_FLAG_NO_BUFFERING, 0)
    If dh = -1 Then
     MsgBox "Could not open drive D:"
     End
    End If
    
    ReadFile dh, bBytes(1), UBound(bBytes), ret, ByVal 0&
    Dim HexV As String
    Dim StrV As String
    
    Text1.Text = ""
    Text2.Text = ""
    For x = 1 To UBound(bBytes)
        HexV = Hex(bBytes(x))
        Text1.Text = Text1.Text & HexV & ","
    
        StrV = Chr(bBytes(x))
        Text2.Text = Text2.Text & StrV
    Next x
    End Function
    http://www.vbforums.com/showthread.p...ight=RAW+drive
    Live to love, Not to hate

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    137

    Re: Drive Raw Access

    In fact a little Read Sector Program that can read a sector off any HD. (READ ONLY) for safety

    Code:
    Const FILE_BEGIN = 0
    Const FILE_SHARE_READ = &H1
    Const FILE_SHARE_WRITE = &H2
    Const CREATE_NEW = 1
    Const OPEN_EXISTING = 3
    Const GENERIC_READ = &H80000000
    Const GENERIC_WRITE = &H40000000
    Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
    
    Public Function ReadSector(Sector As Long, Drive As String)
    Dim dh As Long, ret As Long
    Dim strBuffer As String
    Dim bBytes(512) As Byte
    
    Dim HexV As String
    Dim StrV As String
    Dim x As Long
    
    Sector = Sector * 512
    Drive = UCase(Drive)
    
    dh = CreateFile("\\.\" & Drive & ":", GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
    
    If dh = -1 Then
     MsgBox "Could not open drive " & Drive & ":"
     End
    End If
    
    SetFilePointer dh, Sector, 0, FILE_BEGIN
    
    ReadFile dh, bBytes(1), UBound(bBytes), ret, ByVal 0&
    
    CloseHandle (dh)
    
    Text1.Text = ""
    Text2.Text = ""
    For x = 1 To UBound(bBytes)
        HexV = Hex(bBytes(x))
        Text1.Text = Text1.Text & HexV & ","
    
        StrV = Chr(bBytes(x))
        Text2.Text = Text2.Text & StrV
    Next x
    End Function
    
    Private Sub Command1_Click()
        Dim tmp As String
            tmp = Mid$(Drive1.Drive, 1, 1)
        If (IsNumeric(SectTxt.Text) = False) Then
            MsgBox "bad number)"
            Exit Sub
        End If
        
        ReadSector SectTxt.Text, tmp
        
    End Sub
    Live to love, Not to hate

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    137

    Re: Drive Raw Access

    Here is full project with source and new NEXT and PREV buttons
    Attached Files Attached Files
    Live to love, Not to hate

  5. #5
    New Member
    Join Date
    Jun 2009
    Posts
    8

    Re: Drive Raw Access

    Hello Atomsoft,
    Thanks very much for the response and the sample code.
    I did try the code and was able to read a USB stick. Great.
    Next step is to write to the USB :-) and put some safetychecks in to prevent writing to the C-drive
    Djuskal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width