NO

Author Topic: Reading the master boot record  (Read 1842 times)

Offline Vortex

  • Member
  • *
  • Posts: 903
    • http://www.vortex.masmcode.com
Reading the master boot record
« on: January 01, 2024, 12:13:17 PM »
Here is a command line tool to read the master boot record :

Code: [Select]
include     ReadMBR.inc

.data

szFileName  db '\\.\PhysicalDrive0',0
CmdPar      db 'Usage :',13,10,13,10
            db 'ReadMBR.exe master_boot_record_file.ext',13,10,0

.data?

buffer      db 512 dup(?)
buffer2     db 512 dup(?)
bytes       dd ?
hFile       dd ?

.code

start:

    call    main
    invoke  ExitProcess,0

main PROC uses esi

    mov     esi,OFFSET buffer
    invoke  ParseCmdLine,esi
    cmp     eax,2
    jz      @f
    invoke  StdOut,ADDR CmdPar
    ret
@@:
    xor     eax,eax
    invoke  CreateFile,ADDR szFileName,\
            GENERIC_READ,FILE_SHARE_READ or FILE_SHARE_WRITE,eax,\
            OPEN_EXISTING,eax,eax
    mov     hFile,eax
   
    invoke  ReadFile,eax,ADDR buffer2,512,ADDR bytes,0
    invoke  CloseHandle,hFile

    invoke  WriteFileToDisc,DWORD PTR [esi+4],ADDR buffer2,512

    ret

main ENDP

END start

Code it... That's all...