




已阅读5页,还剩23页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
读写硬盘的MBR和DBR扇区的程序。/* Master Boot Record Programme: * Backup the Master Boot Sector * Fix 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 buff512; /*buffer for master boot sector */* buffer1 backup for master boot sector */char buff1512;/* This is the dos boot programme data */char sector2512=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,0xDC,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,0xD1,0xBC,0xFC,0x7B,0x16,0x07,0xBD,0x78,0x00,0xC5,0x76,0x00,0x1E,0x56,0x16,0x55,0xBF,0x22,0x05,0x89,0x7E,0x00,0x89,0x4E,0x02,0xB1,0x0B,0xFC,0xF3,0xA4,0x06,0x1F,0xBD,0x00,0x7C,0xC6,0x45,0xFE,0x0F,0x8B,0x46,0x18,0x88,0x45,0xF9,0x38,0x4E,0x24,0x7D,0x22,0x8B,0xC1,0x99,0xE8,0x77,0x01,0x72,0x1A,0x83,0xEB,0x3A,0x66,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,0x98,0xF7,0x66,0x16,0x03,0x46,0x1C,0x13,0x56,0x1E,0x03,0x46,0x0E,0x13,0xD1,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,0x11,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,0xDD,0xBE,0x7F,0x7D,0xAC,0x98,0x03,0xF0,0xAC,0x84,0xC0,0x74,0x17,0x3C,0xFF,0x74,0x09,0xB4,0x0E,0xBB,0x07,0x00,0xCD,0x10,0xEB,0xEE,0xBE,0x82,0x7D,0xEB,0xE5,0xBE,0x80,0x7D,0xEB,0xE0,0x98,0xCD,0x16,0x5E,0x1F,0x66,0x8F,0x04,0xCD,0x19,0xBE,0x81,0x7D,0x8B,0x7D,0x1A,0x8D,0x45,0xFE,0x8A,0x4E,0x0D,0xF7,0xE1,0x03,0x46,0xFC,0x13,0x56,0xFE,0xB1,0x04,0xE8,0xC1,0x00,0x72,0xD6,0xEA,0x00,0x02,0x70,0x00,0xB4,0x42,0xEB,0x2D,0x60,0x66,0x6A,0x00,0x52,0x50,0x06,0x53,0x6A,0x01,0x6A,0x10,0x8B,0xF4,0x74,0xEC,0x91,0x92,0x33,0xD2,0xF7,0x76,0x18,0x91,0xF7,0x76,0x18,0x42,0x87,0xCA,0xF7,0x76,0x1A,0x8A,0xF2,0x8A,0xE8,0xC0,0xCC,0x02,0x0A,0xCC,0xB8,0x01,0x02,0x8A,0x56,0x24,0xCD,0x13,0x8D,0x64,0x10,0x61,0x72,0x0A,0x40,0x75,0x01,0x42,0x03,0x5E,0x0B,0x49,0x75,0x77,0xC3,0x03,0x18,0x01,0x27,0x0D,0x0A,0x49,0x6E,0x76,0x61,0x6C,0x69,0x64,0x20,0x73,0x79,0x73,0x74,0x65,0x6D,0x20,0x64,0x69,0x73,0x6B,0xFF,0x0D,0x0A,0x44,0x69,0x73,0x6B,0x20,0x49,0x2F,0x4F,0x20,0x65,0x72,0x72,0x6F,0x72,0xFF,0x0D,0x0A,0x52,0x65,0x70,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,0x72,0x65,0x73,0x73,0x20,0x61,0x6E,0x79,0x20,0x6B,0x65,0x79,0x0D,0x0A,0x00,0x00,0x49,0x4F,0x20,0x20,0x20,0x20,0x20,0x20,0x53,0x59,0x53,0x4D,0x53,0x44,0x4F,0x53,0x20,0x20,0x20,0x53,0x59,0x53,0x7F,0x01,0x00,0x41,0xBB,0x00,0x07,0x80,0x7E,0x02,0x0E,0xE9,0x40,0xFF,0x00,0x00,0x55,0xAA;/* sector1 is the Master boot program data */char sector1512=0xFA,0x33,0xC0,0x8E,0xD0,0xBC,0x00,0x7C,0x8B,0xF4,0x50,0x07,0x50,0x1F,0xFB,0xFC,0xBF,0x00,0x06,0xB9,0x00,0x01,0xF2,0xA5,0xEA,0x1D,0x06,0x00,0x00,0xB8,0x01,0x02,0xBB,0x00,0x08,0xB9,0x01,0x00,0xBA,0x80,0x00,0xCD,0x13,0xBF,0x00,0x06,0xBE,0x00,0x08,0xB9,0x00,0x01,0xFC,0xF3,0xA7,0x74,0x14,0xBE,0x17,0x07,0xE8,0x2F,0x01,0xB8,0x01,0x03,0xBB,0x00,0x06,0xB9,0x01,0x00,0xBA,0x80,0x00,0xCD,0x13,0xBE,0xBE,0x07,0xB3,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,0xFE,0xBF,0x05,0x00,0xBB,0x00,0x7C,0xB8,0x01,0x02,0x57,0xCD,0x13,0x5F,0x73,0x0C,0x33,0xC0,0xCD,0x13,0x4F,0x75,0xED,0xBE,0xD2,0x06,0xEB,0xE0,0xBE,0xF7,0x06,0xBF,0xFE,0x7D,0x81,0x3D,0x55,0xAA,0x75,0xD4,0x8B,0xF5,0xEA,0x00,0x7C,0x00,0x00,0x49,0x6E,0x76,0x61,0x6C,0x69,0x64,0x20,0x70,0x61,0x72,0x74,0x69,0x74,0x69,0x6F,0x6E,0x20,0x74,0x61,0x62,0x6C,0x65,0x2E,0x20,0x4F,0x68,0x2C,0x6D,0x79,0x20,0x67,0x6F,0x64,0x21,0x00,0x45,0x72,0x72,0x6F,0x72,0x20,0x6C,0x6F,0x61,0x64,0x69,0x6E,0x67,0x20,0x6F,0x70,0x65,0x72,0x61,0x74,0x69,0x6E,0x67,0x20,0x73,0x79,0x73,0x74,0x65,0x6D,0x2E,0x20,0x57,0x68,0x79,0x3F,0x00,0x4D,0x69,0x73,0x73,0x69,0x6E,0x67,0x20,0x6F,0x70,0x65,0x72,0x61,0x74,0x69,0x6E,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,0x6E,0x67,0x65,0x64,0x2E,0x0A,0x0D,0x44,0x6F,0x6E,0x27,0x74,0x20,0x77,0x6F,0x72,0x72,0x79,0x2C,0x49,0x20,0x68,0x61,0x76,0x65,0x20,0x72,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,0xB4,0x0E,0xCD,0x10,0x5E,0xEB,0xF0,0xC3,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,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 fnwrite20,fnread20; /* filename */FILE *fp; /* file pointer */int head,cylinder,sector,drive; /* harddisk head,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 Creat the backupfile */int writembr(char *file); /* write the buffer to master boot sector */int writedbr(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 init(int f); /* init the operating */void help(); /*help*/void title(); /* display the infomation */int copypart(char *src,char *dest);void infina(char *file); /* open or creat 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 drive */int detect(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 or not */if(!fileopen(W,file) printf(nBackup file write error!); flag=0; return flag;/* rewrite the dos boot record */int writedbr(char *file)int flag; /* flag for success or not */char key;search(); /* search the the dos boot sector: head , cylinder and sector */init(D); /* initialize the dos boot sector data 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(fnwrite) printf(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 data 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; return flag;int fileopen(int f,char *file)/* f for read or creat 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: 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; if(biosdisk(0x03,0x80,0,0,1,1,buff1) /* Rewrite the MBR with buffer1 */ printf(nWrite Master Boot Sector error!); flag=0; else printf(nWrite Master Boot Sector OK!); flag=1; return flag;int init(int f)int i;int result=1;for(i=0;i (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(buff0x1be&0x00ff)=0x80 | (buff0x1be+16&0x00ff)=0x80 | (buff0x1be+32&0x00ff)=0x80 | (buff0x1be+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;i0x1fe;i+) if(buffi&0x00ff)=0x80) addr=i; break; head=buffaddr+1;sector=(buffaddr+22;cylinder=(buffaddr+26)*256+buffaddr+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(ntMaster Boot sector backup programme.); printf(ntH: help.); printf(ntW: ReWrite the Master Boot Record from a file.); printf(ntB: Backup the Master Boot Record to a file.); printf(ntO: Save the Dos Boot Sector to a file.); printf(ntD: Rewrite the Dos Boot Sector from a file.); printf(ntI: Rewrite the Dos Boot Sector with a default.); printf(ntV: View the Master Boot Record.); printf(ntF: Fixed the floppy Boot Sector.); printf(ntM: The same with Command:Fdisk /mbr.); printf(ntS: Dos shell.); printf(ntQ: Exit the programme.); print
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025促销盛宴商家合作合同
- 2025年上海市汽车销售合同
- 7.4 等差数列与等比数列的应用说课稿中职基础课-拓展模块一 下册-高教版(2021)-(数学)-51
- 2025年工业机器人应用编程考试真题解析及模拟试卷及答案
- 初中语文说明文阅读专题训练试题
- 《2025中年人劳动合同》
- 2025年消除艾梅乙培训试题及答案
- 江西省农业发展集团有限公司2025年校园招聘考试历年参考题附答案详解
- 四川能建工程技术服务公司招聘考试历年参考题附答案详解
- 黄石市2025年湖北黄石大冶市事业单位第二批招聘高层次人才40人笔试历年参考题库附带答案详解
- GB/T 37573-2019露天煤矿边坡稳定性年度评价技术规范
- GB/T 33467-2016全自动吹瓶灌装旋盖一体机通用技术要求
- GB/T 20481-2006气象干旱等级
- 校园监控维护记录表
- 2023年石家庄水务投资集团有限责任公司招聘笔试模拟试题及答案解析
- 2020牛津译林版高中英语新教材选修第一册全册课文翻译及单词表
- 绩效考核环保管理考核细则
- 我国运动员在奥林匹克运动会取得的辉煌成绩课件
- 2021新苏教版科学五年级上册第二单元《热传递》课件
- 专升本高等数学的讲义80页PPT课件
- 汽车机械基础(全套课件)
评论
0/150
提交评论