You need to enable admin rights.You can read the beginning of the disc
Code: Select all
EnableExplicit
#block = 512 ; multiple of disk sector
Global hDevice, bResult.b, dwBytesRead.l, FilePtr.l
Global Dim Buff.a(#block)
hDevice = CreateFile_("\\.\PhysicalDrive0", #GENERIC_READ, #FILE_SHARE_READ | #FILE_SHARE_WRITE, #NUL, #OPEN_EXISTING, 0, #NUL)
; hDevice = CreateFile_("\\?\C:\bootmgr", #GENERIC_READ, #FILE_SHARE_READ | #FILE_SHARE_WRITE, #NUL, #OPEN_EXISTING, 0, #NUL)
If hDevice <> #INVALID_HANDLE_VALUE
FilePtr = SetFilePointer_(hDevice, #block * 0, #NUL, #FILE_BEGIN)
; FilePtr = SetFilePointer_(hDevice, #block * 1, #NUL, #FILE_BEGIN)
If FilePtr <> #INVALID_SET_FILE_POINTER
bResult = ReadFile_(hDevice, @Buff(), #block, @dwBytesRead, #NUL);
If Not (bResult And dwBytesRead = #block)
End
EndIf
EndIf
CloseHandle_(hDevice)
; MessageRequester("", Str(dwBytesRead))
ShowMemoryViewer(@Buff(), ArraySize(Buff()))
EndIf
Define i, j, res.s, c16 = 16, symbol.s
For i=0 To 511
res + RSet(Hex(Buff(i)), 2, "0") + " "
c16 - 1
If c16 = 0
res + " "
For j=i-15 To i
If Buff(j) = 0
symbol = "."
; ElseIf Buff(j) = 9 Or Buff(j) = 10 Or Buff(j) = 13 Or Buff(j) = 11
ElseIf Buff(j) < 32
symbol = " "
Else
symbol = Chr(Buff(j))
EndIf
res + symbol
Next
res + #CRLF$
c16 = 16
EndIf
Next
res = RSet(res , Len(res) - 2)
#Editor = 1
If OpenWindow(0, 0, 0,570+10, 590+10, "Beginning of disk 0", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(#Editor , 5, 5, 560+10, 580+10, #PB_Editor_ReadOnly)
SetGadgetText(#Editor, res)
SendMessage_(GadgetID(#Editor),#WM_SETFONT,LoadFont(1,"Consolas",11,0),1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
EndIf
And now any file and shift by 512
Code: Select all
; AZJIO
EnableExplicit
Enumeration
#Editor
#btnOpen
#btnPrev
#btnNext
#btnFind
EndEnumeration
; Wilbert
; https://www.purebasic.fr/english/viewtopic.php?p=525097#p525097
XIncludeFile "FindData.pbi"
UseModule FindData
#Window = 0
#block = 512
Global Dim Buff.a(#block)
Global res.s, flgFO = 0, hDevice, PosFile = 0, tmp$, FSize.q, CurPath$
Procedure Fill(Array Buff.a(1))
Protected i, j, c16 = 16, symbol.s
res = ""
For i = 0 To 511
res + RSet(Hex(Buff(i)), 2, "0") + " "
c16 - 1
If c16 = 0
res + " "
For j = i - 15 To i
If Buff(j) = 0
symbol = "."
; ElseIf Buff(j) = 9 Or Buff(j) = 10 Or Buff(j) = 13 Or Buff(j) = 11
ElseIf Buff(j) < 32
symbol = " "
Else
symbol = Chr(Buff(j))
EndIf
res + symbol
Next
res + #CRLF$
c16 = 16
EndIf
Next
res = RSet(res , Len(res) - 2)
SetGadgetText(#Editor, res)
EndProcedure
Procedure FileNext()
Protected bResult.b, dwBytesRead.l, FilePtr.l
FilePtr = SetFilePointer_(hDevice, #block * PosFile, #NUL, #FILE_BEGIN)
If FilePtr <> #INVALID_SET_FILE_POINTER And FilePtr < FSize
bResult = ReadFile_(hDevice, @Buff(), #block, @dwBytesRead, #NUL);
If bResult And dwBytesRead <> 0
If dwBytesRead < #block
FillMemory(@Buff() + dwBytesRead , #block - dwBytesRead, 0, #PB_Ascii)
EndIf
flgFO = 1
Fill(Buff())
EndIf
Else
PosFile - 1
EndIf
; MessageRequester("", Str(dwBytesRead))
; ShowMemoryViewer(@Buff(), ArraySize(Buff()))
EndProcedure
Procedure OpenFile2(tmp$)
If flgFO
CloseHandle_(hDevice)
flgFO = 0
EndIf
PosFile = 0
; hDevice = CreateFile_("\\.\PhysicalDrive0", #GENERIC_READ, #FILE_SHARE_READ | #FILE_SHARE_WRITE, #NUL, #OPEN_EXISTING, 0, #NUL)
hDevice = CreateFile_("\\?\" + tmp$, #GENERIC_READ, #FILE_SHARE_READ | #FILE_SHARE_WRITE, #NUL, #OPEN_EXISTING, 0, #NUL)
If hDevice <> #INVALID_HANDLE_VALUE
FileNext()
EndIf
EndProcedure
Procedure BinFind()
Protected length.q, Input$, *mem, BPos, *memFind, bytes
Input$ = InputRequester("Найти", "Введите текст", "")
If Asc(Input$) And flgFO And FSize < 10000000
If ReadFile(0, CurPath$, #PB_File_SharedRead)
length = Lof(0)
*mem = AllocateMemory(length)
If *mem
bytes = ReadData(0, *mem, length)
*memFind = Ascii(Input$)
BPos = FastSearch(*mem, bytes, *memFind, StringByteLength(Input$, #PB_Ascii))
If BPos <> -1
PosFile = BPos / #block
FileNext()
SetWindowTitle(0, "block: " + Str(PosFile))
EndIf
FreeMemory(*memFind)
FreeMemory(*mem)
EndIf
CloseFile(0)
EndIf
EndIf
EndProcedure
If OpenWindow(#Window, 0, 0, 570 + 10, 630 + 10, "Hex view", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(#Editor , 5, 5, 560 + 10, 580 + 10, #PB_Editor_ReadOnly)
SendMessage_(GadgetID(#Editor), #WM_SETFONT, LoadFont(1, "Consolas", 11, 0), 1)
ButtonGadget(#btnOpen, 10, 605, 70, 30, "Open")
ButtonGadget(#btnPrev, 90, 605, 30, 30, "<")
ButtonGadget(#btnNext, 130, 605, 30, 30, ">")
ButtonGadget(#btnFind, 170, 605, 70, 30, "Find")
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #btnOpen
tmp$ = OpenFileRequester("Open file", GetCurrentDirectory(), "all (*.*)|*", 0)
If Asc(tmp$)
FSize = FileSize(tmp$)
If FSize > 0
CurPath$ = tmp$
OpenFile2(tmp$)
tmp$ = ""
EndIf
EndIf
Case #btnPrev
If flgFO = 0
Continue
EndIf
PosFile - 1
If PosFile < 0
PosFile = FSize / #block
EndIf
FileNext()
SetWindowTitle(#Window, "block: " + Str(PosFile))
Case #btnNext
If flgFO = 0
Continue
EndIf
PosFile + 1
FileNext()
SetWindowTitle(#Window, "block: " + Str(PosFile))
Case #btnFind
BinFind()
EndSelect
Case #PB_Event_CloseWindow
If flgFO
CloseHandle_(hDevice)
EndIf
CloseWindow(#Window)
Break
EndSelect
ForEver
EndIf