Abderrahmane Mechri Abderrahmane Mechri - 8 months ago 100
C Question

read boot sector using C on windows8

i tried to read the boot sector using this program

int lire_secteur(int num_sect,unsigned char* buf)
{
int retCode = 0;
unsigned char secteur[512];
char disque[10] ;
char partition ;
FILE* device ;
do
{
disque[0]='\0' ;
scanf("%c",&partition) ;
if (partition=='0')
{
strcpy(disque,"\\\\.\\PHYSICALDRIVE0") ;
}
else
{
sprintf(disque,"\\\\.\\%c:",partition) ;
}
device = fopen(disque, "rb+");
}

while (device == NULL) ;
fseek( device,num_sect*512 , SEEK_SET );
if (fread (secteur, 512,1, device) < 1)
{
printf("erreur\n");
return 1 ;
}
else
{
memcpy(buf,secteur, 512);
retCode=0;
}
return retCode;
}


i have successfully read all sectors in the hard drive but when i want to read the boot sector i have this:
enter image description here

is the problem in my code or it'is due to windows8 ?

Answer Source

You got the right result, that is the boot sector. You might want to print it out formatted in hex rather than just a string like that as you'll be outputting random control characters to the screen.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download