Jump to content
  • Advertisement
Sign in to follow this  
Larry91

low-level!

This topic is 2757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!
How can I create a program that can write the boot sector with C++!
I have tried this:

#include <sys/types.h> /* unistd.h needs this */
#include <unistd.h> /* contains read/write */
#include <fcntl.h>
#include <stdio.h>
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
char boot_buf[512];
int hdd_image, boot_image;

/*boot_image = open("boot.img", O_RDONLY);
read(boot_image, boot_buf, 510);
close(boot_image);*/

fstream img("boot.img", ios::in | ios::binary);
img.read((char*)boot_buf, 510);
img.close();

boot_buf[510] = 0x55;
boot_buf[511] = 0xaa;

hdd_image = open("/dev/hd1", O_RDWR);
if(hdd_image == -1) cout<<"Error!"<<endl;
lseek(hdd_image, 512, SEEK_CUR);
write(hdd_image, boot_buf, 512);
close(hdd_image);
}

What's wrong? I have a virtual machine with a virtual driver Z: and I want to write its first sector (boot sector)! How can I do this? 10x a lot!

Share this post


Link to post
Share on other sites
Advertisement
Messing with the boot sector is a massive no-no under basically all modern operating systems and BIOS implementations. Chances are you're running into security issues.


There are virtually no legitimate uses for modifying the boot sector. I can only imagine that you're trying to do something unpleasant here, which I don't really think GDNet needs to help you with.

Of course, on the off chance that I'm mistaken and you do have a reasonable need to know this, feel free to PM me and explain your situation, and I'll re-open the thread.

Share this post


Link to post
Share on other sites

This topic is 2757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!