Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.4 KiB

  1. //
  2. // readbpb.c
  3. //copyright (c) 1994 by CuTEST Inc.
  4. #include "windows.h"
  5. #include "stdio.h"
  6. #include "stdlib.h"
  7. #include "winioctl.h"
  8. int main(int argc, char *argv[])
  9. {
  10. ULONG Value;
  11. UCHAR Buffer[8012];
  12. HANDLE Source, Target;
  13. DWORD BytesRead, BytesWritten;
  14. ULONG err;
  15. int i;
  16. if ((Source = CreateFile( "ntfsboot.com",
  17. GENERIC_READ | GENERIC_WRITE,
  18. FILE_SHARE_READ | FILE_SHARE_WRITE,
  19. NULL,
  20. OPEN_EXISTING,
  21. FILE_ATTRIBUTE_NORMAL,
  22. NULL
  23. )) == ((HANDLE)-1)) {
  24. printf("Can't get a handle to ntfsboot.com\n");
  25. err = GetLastError();
  26. printf("error = %d\n", err);
  27. return 0;
  28. }
  29. printf("Open to ntfsboot.com succeeded\n");
  30. if ((Target = CreateFile( "bootntfs.h",
  31. GENERIC_READ | GENERIC_WRITE,
  32. FILE_SHARE_READ | FILE_SHARE_WRITE,
  33. NULL,
  34. OPEN_ALWAYS,
  35. FILE_ATTRIBUTE_NORMAL,
  36. NULL
  37. )) == ((HANDLE)-1)) {
  38. printf("Can't get a handle to bootntfs.h\n");
  39. err = GetLastError();
  40. printf("error = %d\n", err);
  41. return 0;
  42. }
  43. printf("Open to bootntfs.h succeeded\n");
  44. sprintf(Buffer, "#define NTFSBOOTCODE_SIZE 32768\n\n\n");
  45. WriteFile(Target, Buffer, strlen(Buffer), &BytesWritten, NULL);
  46. sprintf(Buffer, "unsigned char NtfsBootCode[] = {\n");
  47. WriteFile(Target, Buffer, strlen(Buffer), &BytesWritten, NULL);
  48. printf("Starting Do-While loop\n");
  49. i = 0;
  50. do {
  51. ReadFile(Source, &Value, 1, &BytesRead, NULL);
  52. _itoa(Value, Buffer, 10);
  53. WriteFile(Target, Buffer, strlen(Buffer), &BytesWritten, NULL);
  54. sprintf(Buffer, ",");
  55. WriteFile(Target, Buffer, strlen(Buffer), &BytesWritten, NULL);
  56. if ((i != 0) && (i % 16 == 0)) {
  57. sprintf(Buffer, "\n");
  58. WriteFile(Target, Buffer, strlen(Buffer), &BytesWritten, NULL);
  59. }
  60. i++;
  61. } while (BytesRead);
  62. sprintf(Buffer, "};\n");
  63. WriteFile(Target, Buffer, strlen(Buffer), &BytesWritten, NULL);
  64. CloseHandle(Source);
  65. CloseHandle(Target);
  66. }