Boot Sector - can it be read using C++?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jlm699
    Contributor
    • Jul 2007
    • 314

    Boot Sector - can it be read using C++?

    Greetings friends,

    It's been a while since I've visited this C/C++ forum, and as expected my C++ is unacceptably rusty. Recently I've been reading about Master Boot Records (MBR) and the boot process of a computer. Now I've downloaded small utilities that have the ability to read (and backup to file) the MBR of a partition. These utilities usually have the ability to restore the MBR from a file or simply "fix" the MBR. What I'm wondering: Can a similar utility be written in C++ ? I have no idea what these programs may have been written in, btw.

    Alright so I know that was long-winded but my only real question is, is it possible to access and read the portion of the disk that contains the MBR via C++ and can somebody point me in the direction of how to achieve this?

    thanks!

    James
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    Can a similar utility be written in C++ ?
    Absolutely. As you might realize, a lot of the limitations of a programming language arise from the library bindings it has. In this case, you care about the bindings to the operating system API, as the operating system has control of the hard disk and filesystem. Currently, Microsoft maintains two sets of APIs for working with Windows: the old C WinAPI and the newer .NET APIs. C++, by compatibility with C, has access to the Windows API.

    So you'll basically have to figure out how to use the Windows API to get access to the hard disk. Then, in combination with knowledge of filesystems and hard drives and so on, you can write code to work with the MBR.

    Comment

    Working...