⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 读写硬盘扇区.c

📁 读写硬盘扇区的工具
💻 C
📖 第 1 页 / 共 2 页
字号:
printf("\nDo you want to backup?(Y/N)");
key=getch();
if(key=='y' || key=='Y')
{
infina(fnwrite);
if(!backupmbr(fnwrite))

printf("\nBackup Error!");

else
printf("\nBackup OK!");
}
else
if(key=='n' || key=='N')
printf("\nWarning:it would modify the Dos Boot Sector!");
/* write the sector2 to the dos boot sector */
if(biosdisk(0x03,0x80,head,cylinder,sector,1,sector2)!=0)
printf("\nDos Boot Sector Write error!");
else
printf("\nDos Boot Sector Write OK!");

break;
/* reset the machine */
case 'r':
case 'R':
*res=0x1234;
(*reset)();
/* view the harddisk sector data */
case 'v':
case 'V':
search();
printmbr();
break;
/* fixed the flappy boot sector */
case 'f':
case 'F':
printf("\nWhich dekette? -> (A,B,...):");
key=getch();
printf("%1c:",key);
if(key>=97)

key=key-97;
else
key=key-65;
/* if(detect(0x10,key,0))
{
printf("\nDriver %1c: not ready!",key+65);
break;
}
else
if(detect(0x13,key,1)==0x03)
{
printf("\nDriver %1c: write protect!",key+65);
break;
}
else */
if(biosdisk(0x03,key,0,0,1,1,sector2))
printf("\nDriver %c: write error!",key+65);
else
printf("\nDrive %1c: write OK!",key+65);

break;
/* fixed the MBR with default data */

case 'm':
case 'M':
printf("\nIt would modify the Master Boot Record.");
printf("\nDo you want to backup?(Y/N)");
key=getch();
printf("%1c",key);
if(key=='y' || key=='Y')
{
infina(fnwrite);
if(!backupmbr(fnwrite))
{
printf("\nBackup Error!");
break;
}
}
else
if(key=='n' || key=='N')
printf("\nWarning:it would modify the Master Boot Sector!");
init(M);
if((buff[0x1be]&0x00ff)==0x80 || (buff[0x1be+16]&0x00ff)==0x80
|| (buff[0x1be+32]&0x00ff)==0x80 || (buff[0x1be+48]&0x00ff)==0x80)
copypart(buff+0x1be,sector1+0x1be);
if(biosdisk(0x03,0x80,0,0,1,1,sector1))
{
printf("\nHardDisk Write error!");
break;
}
else
{
printf("\nHardDisk Write OK!");
printf("\nPress 'v' to check it.");
}
break;
/* dos shell */

case 's':
case 'S':
printf("\nPress 'Exit' to return....");
system("");
break;
/* exit */
case 'q':
case 'Q':
title();
return 1;
/* print the undefine command */
default:
printf("%cBad command!",27);

}
}
}
/* display the information */
void title()
{
printf("\nThank you for using the programme...");
printf("\nProgrammer:Crystal.Mouse");
printf("\nDate:05/01/1999");
}

/* change the destination partition table data with the source data */
int copypart(char *src,char *dest)
{
char len=0x40;
while(len>=0)
{
*(dest+len)=*(src+len);
len--;
}
}
/* input the filename */

void infina(char *file)
{
printf("\nPlease input the file name:");
scanf("%s",file);
}

void search()
{
int i,addr;
init(M);
for(i=0x1be;i<0x1fe;i++)
if((buff[i]&0x00ff)==0x80)
{
addr=i;
break;
}
head=buff[addr+1];
sector=(buff[addr+2]<<2)>>2;
cylinder=(buff[addr+2]>>6)*256+buff[addr+3];
}

/* close the cursor */
void closecur()
{
union REGS r;
r.h.ah=1;
r.h.ch=0x20;
int86(0x10,&r,&r);
}
/* open the cursor */

void opencur()
{
union REGS r;
r.h.ah=1;
r.h.ch=12;
r.h.cl=13;
int86(0x10,&r,&r);
}

void help()
{

printf("\n\tMaster Boot sector backup programme...");
printf("\n\tH: help.");
printf("\n\tW: ReWrite the Master Boot Record from a file.");
printf("\n\tB: Backup the Master Boot Record to a file.");
printf("\n\tO: Save the Dos Boot Sector to a file.");
printf("\n\tD: Rewrite the Dos Boot Sector from a file.");
printf("\n\tI: Rewrite the Dos Boot Sector with a default.");
printf("\n\tV: View the Master Boot Record.");
printf("\n\tF: Fixed the floppy Boot Sector.");
printf("\n\tM: The same with Command:'Fdisk /mbr'.");
printf("\n\tS: Dos shell.");
printf("\n\tQ: Exit the programme.");
printf("\n Press any key to continue...");
getch();
sound(2000);
delay(2000);
nosound();

}

/* print the mbr */
int printmbr()
{
int count=1;
int key;
int f=0;
closecur();
init(M);
display(count,&f);
while(bioskey(1)==0);
key=bioskey(0);
while(1){
switch(key)
{
case ESC:
resetwin();
return 1;
case HOME:
count=1;
f=0;
break;
case END:
count=63;
f=0;
break;
case PGUP:
case UP:
case LEFT:
if(count<=1)
count=63;
else
count--;
f=0;
break;
case PGDN:
case DOWN:
case RIGHT:
if(count>=63)
count=1;
else
count++;
f=0;
break;
case F2:
if(f==0)
{
f=1;
break;
}
if(f==1)
{
f=0;
break;
}
case F1:
resetwin();
printf("\nIt would save the sector to a file...");
if(f)
{ if(biosdisk(0x02,0x80,head,cylinder,sector,1,buff)!=0)
{
printf("\nharddisk Dos Boot Sector read error!");
break;
}
}
else
if(biosdisk(0x02,0x80,0,0,count,1,buff))
{
printf("\nHardDisk MBR read error!");
break;

}
infina(fnwrite);
if(!fileopen(W,fnwrite))
printf("\nFile %s Write error!",fnwrite);

else
{
printf("\nFile %s save OK.",fnwrite);
printf("\nPress any key to return...");
getch();
}
break;
default:
break;
}

display(count,f);
while(bioskey(1)==0);
key=bioskey(0);
}
}

/* reset the screen */
void resetwin()
{
opencur();
window(1,1,80,25);
textcolor(WHITE);
textbackground(BLACK);
clrscr();
}

/* put the buffer data to the screen */
int display(int count,int f)
{
int lines,i;
resetwin();
closecur();
i=count;
if(f)
{
if(biosdisk(0x02,0x80,head,cylinder,sector,1,buff))
{
printf("\nHarddisk read error!");
resetwin();
return 0;
}
}
else
if(biosdisk(0x02,0x80,0,0,count,1,buff))
{
printf("\nHarddisk read error!");
resetwin();
return 0;
}
window(1,25,80,25);
textbackground(CYAN);
textcolor(WHITE);
clrscr();
cprintf(" HELP:ESC PGUP PGDN HOME END %c %c %c %c %c ",24,26,25,27,179);
textcolor(RED);
cprintf("F1");
textcolor(WHITE);
cprintf(":Save this sector to a file.");
cprintf(" 05/01/99");
window(1,1,80,1);
textbackground(LIGHTGRAY);
textcolor(LIGHTGREEN);
clrscr();
cprintf(" HardDisk C:1 %c 63 Sector",196);
if(f)
cprintf(" ( DOS BOOT SECTOR ) By: Howard.Crystal ");
else
cprintf(" (Hard Disk Partition Table) By: Howard.Crystal ");
window(1,2,80,24);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
gotoxy(1,1);
if(!f)
{
cprintf(" Head:%-d Cylinder:%-d Sector:%-d",0,0,i);
cprintf(" F2: View Dos Boot Sector\n");
}
else
{
cprintf(" Head:%-d Cylinder:%-d Sector:%-d",head,cylinder,sector);
cprintf(" F2: View Master Boot Sector\n");
}
lines=1;
gotoxy(1,1);
for(i=0;i<512;i++)
{

if(i%24==0)
{
lines++;
gotoxy(1,lines);
}
if(i%4==0)
cprintf(" ");
if(f)
if(buff[510]==0x55 && (buff[511]&0x00ff)==0xaa)
if(i>=510){
textattr(RED+(BLUE<<4)+BLINK); /* flash the special data */
sound(1000);
delay(1000);
nosound();
cprintf("%02x",buff[i]&0x00ff);
textcolor(WHITE);
}
else

cprintf("%02x",buff[i]&0x00ff);
else
cprintf("%02x",buff[i]&0x00ff);

else
if(buff[510]==0x55 && (buff[511]&0x00ff)==0xaa)
if(i>=0x1be && (((i-0x1be)%16==0 && (buff[i]&0x00ff)==0x80) || (buff[i]&0x00ff)==0x55 || (buff[i]&0x00ff)==0xaa))
{
textattr(RED+(BLUE<<4)+BLINK);
cprintf("%02x",buff[i]&0x00ff);
sound(1000);
delay(1000);
nosound();
textcolor(WHITE);
}
else
cprintf("%02x",buff[i]&0x00ff);

else
cprintf("%02x",buff[i]&0x00ff);
}
lines=1;
for(i=0;i<512;i++)
{
if(i%24==0)
lines++;
gotoxy(57+i%24,lines);
if(isprint(buff[i]))
cprintf("%1c",buff[i]);
else
cprintf(".");
}
return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -