Read and write the C language program for the hard disk sector

zhaozj2021-02-11  156

I use C to write the MBR and DBR sectors of the hard drive.

/ ***************************************** * Master Boot Record Program: * * Backup the master boot sector * * fixed the master boot sector * * change the partition table * * - by crystal.mouse 04/30/99 - * * turboc 2.0 * ********** ******************************************* / # include #include #include #include #include #include #include #include #include

/ * Define the * /

Char buff [512]; / * buffer for master boot sector * // * buffer1 backup for master boot sector * / char buff1 [512]; / * this is the dos boot programme data * / char sector2 [512] =

{0xEB, 0x3C, 0x90, 0X4D, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31, 0x00, 0x02, 0x20, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0xF8, 0xc9, 0x00, 0x3f 0x00, 0x40, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x01, 0x0a, 0x19, 0x00, 0x80, 0x00, 0x29, 0x04, 0x12, 0x6f, 0x04, 0x30, 0x34, 0x32, 0x36, 0x39, 0x39, 0x20 0x20, 0X20, 0X20, 0X20, 0X46, 0X41, 0X54, 0X31, 0X36, 0X20, 0X20, 0X20, 0XFA, 0X33, 0XC9, 0X8E, 0X7B, 0X16, 0x07, 0xBd, 0x78, 0x00 0xC5, 0x76, 0x00, 0x1e, 0x56, 0x16, 0x55, 0x, 0x4, 0x00, 0x89, 0x4e, 0x02, 0x/1, 0x0b, 0xFc, 0x1f, 0xa4, 0x06, 0x1f, 0xBd, 0x00 0x7c, 0x0f, 0x8b, 0x46,0x18, 0x88,0x45,0x18, 0x38, 0x4e, 0x24, 0x7d, 0x22,0x8b, 0xc1, 0x99,0x72,0x77,0x01,0 x72, 0x1a, 0x83 0xA1, 0x1c, 0x7c, 0x66, 0x3b, 0x07, 0x8a, 0x57, 0xFc, 0x75, 0x06, 0x80, 0xca, 0x02, 0x88, 0x56, 0x02, 0x80, 0xc3, 0x10,0x73,0xed 0x33, 0xc9, 0x8a, 0x46, 0x10, 0x16, 0x03, 0x46, 0x1c, 0x13, 0x56, 0x1e, 0x13, 0x46, 0x0e, 0x13, 0x1, 0x8b, 0x76, 0x11, 0x60, 0x89 0x46, 0xFc, 0x89, 0x56, 0xFE, 0xB8, 0X20, 0x00, 0XF7, 0XE6, 0X8B, 0X5E, 0x0B, 0x03, 0XC3, 0X48, 0XF7, 0XF3, 0X01, 0X46, 0XFC, 0x1 1,0x4e, 0xFe, 0x61, 0xbf, 0x00, 0x07, 0xe8, 0x23, 0x01, 0x72, 0x39, 0x38, 0x2d, 0x74, 0x17, 0x60, 0xB1, 0x0b, 0xbe, 0xD8, 0x7d, 0xF3, 0xa6, 0x61, 0x74, 0x39, 0x4e, 0x74, 0x09, 0x83, 0xc7, 0x20, 0x3b, 0xfb, 0x72,0xe7, 0xeb, 0x7d, 0xbe, 0x7f, 0x7d, 0xAc, 0x98, 0x03, 0xf0, 0xAc, 0x84, 0xc0, 0x74, 0x17, 0x3c, 0xff, 0x74, 0x09, 0x10, 0x0E, 0xBb, 0x10, 0x00, 0XE, 0x30, 0x82, 0x7d, 0xE, 0x82, 0X7D, 0x80, 0X7D, 0XEB, 0X80, 0X98, 0xcd, 0x16, 0x5e, 0x1f, 0x66, 0x8f, 0x04, 0x7, 0x19, 0x8b, 0x7d, 0x1a, 0x8d, 0x45, 0xFe, 0x8a, 0x4e, 0x0d, 0xf7, 0xe1, 0x03, 0x46, 0xFC, 0x13, 0x56, 0xFe, 0xB1, 0x04, 0xE8, 0XC1, 0X00, 0X72, 0X02, 0X70, 0X00, 0X02, 0X70, 0X00, 0X2D, 0X60, 0X66, 0X6A, 0X00, 0X52, 0x50, 0x06, 0x53, 0x6a, 0x01, 0x6a, 0x10, 0x8b, 0x10,0x74,0 x 33, 0x91, 0x92, 0x33, 0x2, 0x1, 0x76, 0x18, 0x91, 0x1, 0x76, 0x18, 0x42,

0x87, 0xca, 0xF7, 0x76, 0x1a, 0x8a, 0x0, 0x8a, 0x02, 0x0a, 0xcc, 0x8a, 0x01, 0x02,0x8a, 0x56,0 x24, 0xcd, 0x13, 0x8d, 0x64, 0x10, 0x61, 0x72, 0x0a, 0x40, 0x75, 0x01, 0x42, 0x03, 0x5e, 0x0b, 0x49,0 x 75, 0x18, 0x01, 0x27, 0x0d, 0x0a, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x64, 0x69, 0x73, 0x6b, 0x0, 0x0d, 0x0a, 0x44, 0x69, 0 x 73, 0x6b, 0x20, 0x49, 0x2f, 0x4f, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0xff, 0x0d, 0x70a, 0x6c, 0x61, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x69, 0x73, 0x6b, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x0d, 0x0a, 0x00, 0x00, 0x49, 0x4f, 0x20, 0x20, 0x20, 0x20, 0x209, 0x53, 0x4d, 0x53, 0x44, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x53, 0x59, 0x53, 0x7f, 0x01, 0x00, 0x41, 0x, 0x00, 0x07, 0x80, 0x7e, 0x02, 0x0e, 0x00, 0x40, 0xff, 0x00, 0x00, 0x55, 0xaa}; / * sector1 is the master boot program data * / char sector1 [512] =

{0xFA, 0x33, 0xc0, 0x8e, 0x2, 0x8b, 0x00, 0x7c, 0x8b, 0xF4, 0x50, 0x07, 0x50, 0x1f, 0xFb, 0xFc, 0xBF, 0x00, 0x06, 0XB9, 0x00, 0X01, 0XF2, 0XA5, 0XEA 0x1D, 0x06, 0x00, 0x00, 0XBB, 0x00, 0x08, 0XB9, 0x01, 0x00, 0XBA, 0x80, 0x00, 0xCD, 0x13, 0xBF, 0x00, 0x06, 0X, 0x00, 0x08, 0xB9 0x00, 0x01, 0x74, 0x14, 0XA7, 0x74, 0x14, 0XBE, 0X17, 0X07, 0XE8, 0X2F, 0X01, 0XB8, 0x01, 0X03, 0XBB, 0x00, 0x06, 0XB9, 0x01, 0X00, 0XBA, 0x80, 0x00 , 0xcd, 0x13, 0xBe, 0x04, 0x80, 0x3c, 0x80, 0x74, 0x0e, 0x80, 0x3c, 0x00, 0x75, 0x1c, 0x83, 0xc6, 0x10, 0xFe, 0xcb, 0x75, 0xef, 0xcd 0x18, 0x8b, 0x14, 0x8b, 0x4c, 0x02, 0x8b, 0xee, 0x83, 0xc6, 0x10, 0xFe, 0xcb, 0x74, 0x0d, 0x80, 0x3c, 0x00, 0x74, 0xF4, 0xBe, 0xae, 0x06, 0xe8, 0xF0 0x00, 0xeb, 0x00, 0xBb, 0x00, 0x7c, 0x57, 0x01, 0x02,0x57,0xcd, 0x13, 0x5f, 0x73, 0x0c, 0x33, 0xc0, 0xcd, 0x13, 0x4f, 0x75, 0xed , 0xbe, 0x0,0xbe, 0xF7, 0x06, 0xBF, 0xFE, 0x7D, 0x81, 0X3D, 0X55, 0XAA, 0X75, 0X, 0X8B, 0x7C, 0x00, 0x00, 0x49 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x6 5, 0x2e, 0x20, 0x4f, 0x68, 0x2c, 0x67, 0x6f, 0x64, 0x21, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6E, 0x67, 0x20, 0X6F, 0X70, 0X74, 0X69, 0X61, 0X74, 0X69, 0X73, 0X79, 0X73, 0X74, 0X65, 0X6D, 0X2E, 0X20, 0X57, 0X68, 0X79, 0X3F, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6E, 0x67, 0x20, 0X72, 0X61, 0X74, 0X69, 0X61, 0X67, 0X20, 0X73, 0X79, 0X73, 0X74, 0X65, 0X6D, 0x2e, 0x20, 0x53, 0x68, 0x69, 0x74, 0x21, 0x00, 0x4d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x42, 0X6F, 0x6F, 0X74, 0X20, 0X53, 0X65, 0X63, 0X74, 0X6F, 0x72, 0x20, 0x63, 0x68, 0x61, 0x64, 0x67, 0x0a, 0x0d, 0x44, 0x6f, 0x6e, 0x27, 0x74, 0x20, 0x77, 0x6f, 0x72, 0x72, 0x79, 0x2c, 0x49, 0x20, 0x68, 0x61, 0x76, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x20, 0x69, 0x74, 0x21, 0x20, 0x43, 0x6c, 0x65,

0x76, 0x65, 0x72, 0x21, 0x20, 0x45, 0x54, 0x2d, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x20, 0x59, 0x65, 0x61, 0x68, 0x21, 0x0a, 0x0d, 0x00, 0xAc, 0x3c, 0x00, 0x74, 0x0b, 0x56, 0xbb, 0x07, 0x00, 0x10, 0x0e, 0xcd, 0x10, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xAa}; char fnwrite [20], fnread [20]; / * Filename * / file * fp; / * file pointer * / int head, cylinder, sector, drive; / * harddisk HE AD, CYLINDER SECTOR DRIVE * /

/ * Define the key code * /

#define ESC 0x011b # define LEFT 0x4b00 # define RIGHT 0x4d00 # define UP 0x4800 # define DOWN 0x5000 # define HOME 0x4700 # define END 0x4f00 # define PGUP 0x4900 # define PGDN 0x5100 # define F2 0x3c00 # define F1 0x3b00

#define w 1 # Define R 0 / * flag for * / # define d 0 / * flag for dos boot sector * / # define m 1 / * flag for master boot sector * /

/ * Declare the function * /

INT FileOpen (int F, char * file); / * read or create the backupfile * / int Writembr (char * file); / * Write the buffer to master boot sector * / int writebr (char * file); / * WRITE The buffer to dos boot sector * / int backupmbr (char * file); / * backup the master boot record data * / int backupdbr (char * file); / * backup the dos boot sector data * / int printmbr (); / * Print the master boot sector * / int it (int F); / * init the OPERATING * / VOID HELP (); / * help * / void title (); / * display the infomation * / int copyspace (char * src) CHAR * DEST); void infina (char * file); / * open or create the backup file * / void closecur (); / * close the cursor * / void opencur (); / * open the cursor * / int display (); / * Display the data * / void interrupt (* reset) (); / * interrupt reset the machine * / void resetwin (); / * reset the screen * / void search (); / * search the dos boot Sector * / int detect (int Num, int DRIVER, INT F); / * detect the driving * / int d Etect (int Num, int DRiver, int F) / * detect the disk * / {

Union regs r; r.h.ah = Num; R.H.DL = driver; int86 (0x13, & r, & r); if (f) return r.h.al; else return r.x.cflag;}

/ * backup the dos boot sector * / int backupdbr (char * file) {int flag = 1; / * flag for success / * / if (! FileOpen (w, file) {printf ("/ nbackup file write error ! "); FLAG = 0;} Return Flag;

}

/ * REWRITE DOS BOOT RECORD * / INT WRITEDBR (Char * file) {INT FLAG; / * Flag for Success OR not * / char key; search (); / * search the the the dos boot Sector: head, cylinder and sector * / Init (d); / * Initialize the dos boot sector to the buffer * / printf ("/ nwarning ..."); Printf ("/ Nit might destory your harddisk!"); Printf ("/ NDO you Want to a backup? (y / n) "); key = getch (); switch (key) {case 'y': case 'y': infina (fnWrite); / * Input the backup filename * / if (! Backupdbr ("/ nbackup error!"); flag = 0; break;} case 'n': case 'n': if (! FileOpen (R, File) / * Open the existed backup file Data to buffer * / {Printf ("/ nbackup file% s open error!", file); flag = 0; return flag;}} / * Rewrite the dos boot sector with the buffer data * / if (BiosDisk (0x03, 0x80, head, cylinder, sector, 1, buff1)) {printf ("/ nwrite master boot sector error!"); Flag = 0;} else {printf ("/ NWRITE DOS BOOT SECTOR OK! "); FLAG = 1;}} / * backup the master boot sector to file * / int backupmbr (char * file) {int flag = 1; init (m); / * Initialize the master boot Sector to the Buffer * / if (! FileOpen (W, file) {printf ("/ nbackup file write error!"); FLAG = 0;} returnif;}

INT FileOpen (int F, char * file) / * f for read or create file * / {int flag= 1; if (f == 0) {IF ((fp = fopen (file, "rb"))! = NULL) {Fread (buff1, 512, 1, fp); fclose (fp);} else flag = 0;} if (f == 1) {IF ((fp = fopen (file, "wb"))! = NULL) {FWRITE (BUFF, 512, 1, FP); Fclose (fp);} else flag = 0;} Return flag;} int Writembr (char * file) {int flag= 1; char key; printf ("/ NWARNING ... "); Printf (" / nit might destory your harddisk! "); Printf (" / ndo you want to a backup? (y / n) "); key = getCH (); switch (key) { Case 'Y': Infina (FnWrite); Init (M); / * Initialize the Mbr to Buffer * / if (! backupmbr (fnWrite)) / * backup the mbr * / {printf ("/ nbackup Error! "); FLAG = 0;

}

Printf ("/ nfile% s backup ok!", fnwrite); if (! BiosDisk (0x03, 0x80, 0, 0, 3, 1, buff)) Printf ("/ NTHE OLD MBR WRITE To Head: 0, Cylinder: 0, Sector: 1 Error! "); If (! BiosDisk (0x03, 0x80, 0, 0, 5, 1, buff) Printf (" / NTHE OLD MBR WRITE TO Head: 0, Cylinder: 0, Sector: 1 Error! "); Printf (" / NThe Old Mbr Also Backup to the HardDisk Side 0 Cylinder 0 Sector 3 and 5. "); FLAG = 1;

Case 'N': Case 'N': IF (! FileOpen (R, File) / * Open the EXISTED Backup file * / {printf ("/ nbackup file% s open error!", file); FLAG = 0; Return flag;}}} f (BiosDisk (0x03, 0x80, 0, 0, 1, 1, buff1)) / * REWRITE THE MBR with buffer1 * / {printf ("/ nwrite master boot sector"); flag = 0 Else {Printf ("/ NWRITE MASTER Boot Sector OK!"); FLAG = 1;}

Return flag;} int it i; int result = 1;

For (i = 0; i <512; i ) / * Initialize the buffer * / buff [i] = 0; if (f) {IF (BiosDisk (0x02, 0x80, 0, 0, 1, 1, buff)) / * read the mbr to buffer * / {printf ("/ nmaster boot record read error!"); result = 0;}} else IF (BiosDisk (0x02,0x80, head, cylinder, sector, 1, buff) { Printf ("/ NDOS Boot Sector Read Error!"); Result = 0;} returnrate;}

Main () {int far * res = (int FAR *) 0x472; / * the data for reset * / INT i, J, K; char key; reset = mk_fp (0xfff, 0x0000); / * Reset Interrupt Address * /

CLRSCR (); while ("/ NSETMBR Program); Printf (" / n. "); key = getCH (); Printf ("% C ", Key); Switch (key) {CASE 'H': Case 'h': Help (); Break; / * Rewrite The Mbr Sead / Case 'W': Case 'W': infina (fnread); / * Input The existed file name * / if (! ") {Printf (" / NWRITE HARDDISK MBR ERROR! "); Printf (" / npress' v 'to check it. "); Printf (" / npress' m " To fix it. ");} else printf (" / NWRITE HARDDISK MBR OK! "); Break;

/ * backup the mbr sector * / case 'b': case 'b': infina (fnwrite);

IF ("/ nbackup mbr!"); Else Printf ("/ nbackup mbr ok!"); break; / * Rewrite the dos boot sector * / case 'd': Case 'D ': Infina (fnread); if (! WriteDBR (FNREAD)) {Printf ("/ NWRITE DOS Boot Sector Error!"); Printf ("/ NPRESS' V 'TO View The DOS Boot Sector!"); Break;} Break; / * backup the dos boot sector * / case 'o': case 'o': infina (fnwrite); search (); init (d); if (! backupdbr (fnwrite)) Printf ("/ NBackup DOS Boot Sector Error! "); Else Printf (" / Nbackup DOS Boot Sector OK! "); Break; / * Rewrite The Dos Boot Sector With default data * / case 'i': Case 'i': search (); init D); Printf ("/ Nit Would Modify The DOS Boot Sec Trotr!"); 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 10); / * 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 * / 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 10); 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 program ..."); Printf ("/ nprogrammer: crystal.mouse); printf (" / ndate: 05 / 01/1999 ");

/ * Change the destination party Table Data with the source data * / int copyspace (char * src, char * DEST) {char len = 0x40; while (len> = 0) {* (DEST LEN) = * (SRC LEN -; "/ NPLEASE INPUT The File Name:"); scanf ("% s", file); scanf ("% s", file);

Void search () {Intdr; 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 Program ..."); 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 Program); Printf (" / N Press Any Key To Continue ... "); getCh (); Sound (2000); DELAY (2000); no 2 ();

}

/ * 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,0 x80, 0, count, 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."; 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 4 (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 f (BiosDisk (0x02,0 x80, 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, line);} if (i% 4 == 0) CPrintf (""); if (f) IF (BUFF [510] == 0x55 && BUFF [511] & 0x00FF) == 0xAA) f (i> = 510) {textattr (red (blue << 4) blink); / * Flash the special data * / sound (1000); delay (1000); NoSound (); CPRINTF ("% 02x", BUFF [I] & 0x00FF); TextColor (White);} elsecprintf ("% 02x", BUFF [I] & 0x00FF); Else Cprintf ("% 02x", BUFF [I] & 0x00FF );

Else IF (BUFF [510] == 0x55 && (BUF [511] & 0x00FF) == 0xAA) IF (i> = 0x1be && ((i-0x1be)% 16 == 0 && (BUFF [i] & 0x00FF) = = 0x80) || (BUFF [I] & 0x00FF) == 0x55 || (BUF [I] & 0x00FF) == 0xAA)) {textttr (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, line); if (isprint (buff [i])) CPRINTF ("% 1c", buff [I]); Else Cprintf (".");} Return 1;}

转载请注明原文地址:https://www.9cbs.com/read-6007.html

New Post(0)