FIXPART.C
上传用户:yugezi
上传日期:2007-01-06
资源大小:18k
文件大小:5k
源码类别:

磁盘编程

开发平台:

Others

  1. #include<stdio.h>
  2. #include<bios.h>
  3. #include<stdlib.h>
  4. #include<alloc.h>
  5. #include<fcntl.h>
  6. #include<sysstat.h>
  7. #include<dos.h>
  8. char Sector1[512]=
  9.       { 0xFA,0x33,0xC0,0x8E,0xD0,0xBC,0x00,0x7C,0x8B,0xF4,0x50,0x07,
  10. 0x50,0x1F,0xFB,0xFC,0xBF,0x00,0x06,0xB9,0x00,0x01,0xF2,0xA5,
  11. 0xEA,0x1D,0x06,0x00,0x00,0xBE,0xBE,0x07,0xB3,0x04,0x80,0x3C,
  12. 0x80,0x74,0x0E,0x80,0x3C,0x00,0x75,0x1C,0x83,0xC6,0x10,0xFE,
  13. 0xCB,0x75,0xEF,0xCD,0x18,0x8B,0x14,0x8B,0x4C,0x02,0x8B,0xEE,
  14. 0x83,0xC6,0x10,0xFE,0xCB,0x74,0x1A,0x80,0x3C,0x00,0x74,0xF4,
  15. 0xBE,0x8B,0x06,0xAC,0x3C,0x00,0x74,0x0B,0x56,0xBB,0x07,0x00,
  16. 0xB4,0x0E,0xCD,0x10,0x5E,0xEB,0xF0,0xEB,0xFE,0xBF,0x05,0x00,
  17. 0xBB,0x00,0x7C,0xB8,0x01,0x02,0x57,0xCD,0x13,0x5F,0x75,0x0C,
  18. 0x33,0xC0,0xCD,0x13,0x4F,0x75,0xED,0xBE,0xA3,0x06,0xEB,0xD3,
  19. 0xBE,0xC2,0x06,0xBF,0xFE,0x7D,0x81,0x3D,0x55,0xAA,0x75,0xC7,
  20. 0x8B,0xF5,0xEA,0x00,0x7C,0x00,0x00,0x49,0x6E,0x76,0x61,0x6C,
  21. 0x69,0x64,0x20,0x70,0x61,0x72,0x74,0x69,0x74,0x69,0x6F,0x6E,
  22. 0x20,0x74,0x61,0x62,0x6C,0x65,0x00,0x45,0x72,0x72,0x6F,0x72,
  23. 0x20,0x6C,0x6F,0x61,0x64,0x69,0x6E,0x67,0x20,0x6F,0x70,0x65,
  24. 0x72,0x61,0x74,0x69,0x6E,0x67,0x20,0x73,0x79,0x73,0x74,0x65,
  25. 0x6D,0x00,0x4D,0x69,0x73,0x73,0x69,0x6E,0x67,0x20,0x6F,0x70,
  26. 0x65,0x72,0x61,0x74,0x69,0x6E,0x67,0x20,0x73,0x79,0x73,0x74,
  27. 0x65,0x6D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  28. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  29. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  34. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  36. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  37. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  38. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  40. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  42. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  43. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x00,0x00,0x80,0x01,0x01,0x00,0x04,0x04,0xD1,0x02,0x11,0x00,
  47. 0x00,0x00,0xEE,0xFF,0x00,0x00,0x00,0x00,0xC1,0x03,0x05,0x04,
  48. 0xD1,0xFE,0xFF,0xFF,0x00,0x00,0xAC,0x53,0x00,0x00,0x00,0x00,
  49. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51. 0x00,0x00,0x00,0x00,0x00,0x00,0x55,0xAA};
  52. void CopyPart(char *src,char *dest);
  53. void copyright();
  54. void reboot(void)
  55. {
  56.  void (far *reboot_ptr)(void);
  57.  unsigned int far *i_ptr;
  58.  clrscr();
  59.  i_ptr=MK_FP(0x0040,0x0072);
  60.  *i_ptr=0x1234;
  61.  reboot_ptr=MK_FP(0xF000,0xFFF0);
  62.  reboot_ptr();
  63. }
  64. main()
  65. {
  66.  char filename[20];
  67.  char *buffer;
  68.  FILE *fp;
  69.  copyright();
  70.  printf("n BACKUP Filename: ");
  71.  scanf("%s",filename);
  72.  printf("n Backuping File %s ...... ",filename);
  73.  fp=fopen(filename,"wb");
  74.  if(fp==NULL){puts("na Open file error");exit(1);}
  75.  buffer=(char *)malloc(512);
  76.  if(biosdisk(0x02,0x80,0,0,1,1,buffer))
  77.  {
  78.   printf("n Read HD Master Boot Sector error!n");
  79.   exit(1);
  80.  }
  81.  fwrite(buffer,512,1,fp);
  82.  fclose(fp);
  83.  printf(" OK!n");
  84.  CopyPart(buffer+0x1be,Sector1+0x1be);
  85.  printf("n Write Old HD Master Boot Sector to Sector 3 ...... ");
  86.  if(biosdisk(0x03,0x80,0,0,3,1,buffer))
  87.  {
  88.   printf("n Write Old HD Master Boot Sector to Sector 3 error!n");
  89.   exit(1);
  90.  }
  91.  printf(" OK!n");
  92.  printf("n Write Old HD Master Boot Sector to Sector 7 ...... ");
  93.  if(biosdisk(0x03,0x80,0,0,7,1,buffer))
  94.  {
  95.   printf("n Write Old HD Master Boot Sector to Sector 7 error!n");
  96.   exit(1);
  97.  }
  98.  printf(" OK!n");
  99.  free(buffer);
  100.  printf("n Write New Data to HD Master Boot Sector ...... ");
  101.  if(biosdisk(0x03,0x80,0,0,1,1,Sector1))
  102.  {
  103.   printf("n Restore HD Master Boot Sector error!n");
  104.   exit(1);
  105.  }
  106.  printf(" OK!n");
  107.  printf("n Now,your Hard-Disk is all right!");
  108.  printf("n Prees any key to reboot your system.n");
  109.  getch();
  110.  reboot();
  111. }
  112. void copyright()
  113. {
  114.  printf("n Babysoft  (R) HD Master Boot Sector Fixer version 1.0.");
  115.  printf("n Copyright (C) 1997.9 LiuYading,Babysoft Corp.n");
  116. }
  117. void CopyPart(char *src,char *dest)
  118. {
  119.  char Plength;
  120.  Plength=0x40;
  121.  while(Plength>=0)
  122.  {
  123.   *(dest+Plength)=*(src+Plength);
  124.   Plength--;
  125.  }
  126. }