Source code of Windows XP (NT5)
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.

132 lines
2.8 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. int _cdecl
  4. main(
  5. int argc,
  6. CHAR *argv[]
  7. )
  8. {
  9. HANDLE hFileIn;
  10. HANDLE hMapIn;
  11. HANDLE hFileOut;
  12. HANDLE hMapOut;
  13. HANDLE hDataFile;
  14. LPSTR SrcData, DstData;
  15. LPSTR s,e,d;
  16. DWORD FileSize;
  17. CHAR FileName[MAX_PATH];
  18. DWORD DataSize;
  19. //
  20. // map the input file
  21. //
  22. hFileIn = CreateFile( argv[1], GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
  23. if (hFileIn == INVALID_HANDLE_VALUE) {
  24. return -1;
  25. }
  26. FileSize = GetFileSize( hFileIn, NULL );
  27. hMapIn = CreateFileMapping( hFileIn, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL );
  28. if (!hMapIn) {
  29. return -1;
  30. }
  31. SrcData = s = MapViewOfFile( hMapIn, FILE_MAP_READ, 0, 0, 0 );
  32. //
  33. // map the output file
  34. //
  35. hFileOut = CreateFile( argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
  36. if (hFileOut == INVALID_HANDLE_VALUE) {
  37. return -1;
  38. }
  39. hMapOut = CreateFileMapping( hFileOut, NULL, PAGE_READWRITE | SEC_COMMIT, 0, FileSize+64000, NULL );
  40. if (!hMapOut) {
  41. return -1;
  42. }
  43. DstData = d = MapViewOfFile( hMapOut, FILE_MAP_WRITE, 0, 0, 0 );
  44. //
  45. // look for the [SourceDisksFiles] section
  46. //
  47. while (TRUE) {
  48. s = strchr( s, '[' ) + 1;
  49. e = strchr( s, ']' );
  50. if (_strnicmp(s,"SourceDisksFiles",16)!=0) {
  51. s = e + 1;
  52. continue;
  53. }
  54. s = strchr(e,0xa) + 1;
  55. break;
  56. }
  57. CopyMemory(d,SrcData,s-SrcData);
  58. d += (s-SrcData);
  59. //
  60. // now loop thru all of the files in the [SourceDisksFiles] section
  61. //
  62. while (TRUE) {
  63. if (*s==0xd) {
  64. CopyMemory(d,s,2);
  65. d+=2;
  66. s+=2;
  67. continue;
  68. }
  69. if (*s=='[') break;
  70. e = strchr(s,'=');
  71. strcpy(FileName,argv[3]);
  72. if (FileName[strlen(FileName)-1]!='\\') {
  73. strcat(FileName,"\\");
  74. }
  75. strncat(FileName,s,e-s);
  76. hDataFile = CreateFile( FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL );
  77. if (hDataFile != INVALID_HANDLE_VALUE) {
  78. DataSize = GetFileSize( hDataFile, NULL );
  79. CloseHandle(hDataFile);
  80. } else {
  81. DataSize = 0;
  82. }
  83. e = strchr(e,',')+1;
  84. e = strchr(e,',')+1;
  85. CopyMemory(d,s,e-s);
  86. d += (e-s);
  87. sprintf(d,"%01d",DataSize);
  88. d += strlen(d);
  89. s = strchr(e,',');
  90. e = strchr(e,0xa) + 1;
  91. CopyMemory(d,s,e-s);
  92. d += (e-s);
  93. s = e;
  94. }
  95. CopyMemory(d,s,FileSize-(s-SrcData));
  96. d += (FileSize-(s-SrcData));
  97. UnmapViewOfFile( DstData );
  98. CloseHandle( hMapOut );
  99. SetFilePointer( hFileOut, d-DstData, 0, FILE_BEGIN );
  100. SetEndOfFile( hFileOut );
  101. CloseHandle( hFileOut );
  102. return 0;
  103. }