Page 1 of 1

Read HardDrive Raw

Posted: Wed Oct 25, 2006 12:38 am
by Inner
Meh! have fun :)

Code: Select all

; gPreferences[460-5-1-1]
Enumeration
  #MAIN
  #HEXVIEW
EndEnumeration

Procedure ReadSector(drive.s,sls.l,nos.l)
  bytesread.l
  buffer=AllocateMemory(512*nos)
  hdev=CreateFile_("\\.\\vwin32",0,0,0,0,#FILE_FLAG_DELETE_ON_CLOSE,0)
  If hdev=#INVALID_HANDLE_VALUE
    devicename.s="\\.\\"+drive
    hdev=CreateFile_(devicename,#GENERIC_READ,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0)
    
    If hdev=#INVALID_HANDLE_VALUE
      Debug hdev
      ProcedureReturn 0
    EndIf
       
	  ;// Setting the pointer To point To the start of the sector we want To Read ..
	  SetFilePointer_(hdev,(sls*512),0,#FILE_BEGIN); 
	  rfh=ReadFile_(hdev,buffer,512*nos,@bytesread,0)
    
    CloseHandle_(hdev)
  EndIf
  ProcedureReturn buffer
EndProcedure

Procedure PrintB(buffer.l,size.l)
  fmt.s=""
  ClearGadgetItemList(#HEXVIEW)
  For x=0 To size
    ;4,4,4,4,16 // NL
    rbyte.l=PeekB(buffer+x)
    vbyte.l=Val(StrU(rbyte,#Byte))
    If vbyte<32
      strv.s+"."
    Else
      strv.s+Chr(rbyte)
    EndIf
    hb.s=Hex(vbyte)
    If Len(hb)=1
      fmt+"0"+hb+" "      
    Else
      fmt+hb+" "
    EndIf
    a=x % 16
   ; Delay(2000)
    If a=15
      AddGadgetItem(#HEXVIEW,-1,Str(a)+" "+fmt+" "+strv) : fmt="" : strv=""
    EndIf
  Next
EndProcedure

w=600 : h=820

#SECTORSIZE=1

If OpenWindow(#MAIN,0,0,w,h,"Tosser",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  CreateGadgetList(WindowID(#MAIN))
  If LoadFont(1,"blitz", 8) 
    SetGadgetFont(#PB_Default, FontID(1))
  EndIf
  EditorGadget(#HEXVIEW,0,0,w,h,#PB_Editor_ReadOnly)
  
  PrintB(ReadSector("D:",0,#SECTORSIZE),512*#SECTORSIZE)  
  Repeat 
    Event = WindowEvent() 
    If Event        ; An event was in the queue so process it 
    Else
      PrintB(ReadSector("D:",i,2),1024)
      i+1
      Delay(100)
    EndIf 
  Until Event = #PB_Event_CloseWindow
EndIf

;buffer=ReadSector("D:",0,2)

;OpenConsole()
;For i=0 To 1024
;  Print(Chr(PeekB(buffer+i)))
;Next
;FreeMemory(buffer)
;Delay(8000)
;CloseConsole()


Posted: Wed Oct 25, 2006 1:20 am
by dracflamloc
And be careful ;)

Posted: Wed Oct 25, 2006 2:32 am
by CadeX
Looks great, but i wouldn't use it.

Posted: Wed Oct 25, 2006 4:41 am
by Inner
dracflamloc wrote:And be careful ;)
Only if you decide you want to write, was actually trying to find the sector location of a file written to disk, but didn't quite turn out how I'd hoped, oh well.