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.

147 lines
3.6 KiB

  1. #include <stdlib.h>
  2. #include "textmode.h"
  3. #include "spcab.h"
  4. WCHAR TemporaryBuffer[16384];
  5. PWSTR SpCabDupStringW(PCWSTR s)
  6. {
  7. if (s == NULL)
  8. return NULL;
  9. else
  10. {
  11. PWSTR q = (PWSTR)RtlAllocateHeap(RtlProcessHeap(), 0, (wcslen(s) + 1) * sizeof(*q));
  12. if (q)
  13. wcscpy(q, s);
  14. return q;
  15. }
  16. }
  17. PVOID SpMemAlloc(SIZE_T n)
  18. {
  19. return RtlAllocateHeap(RtlProcessHeap(), 0, n);
  20. }
  21. VOID SpMemFree(PVOID p)
  22. {
  23. RtlFreeHeap(RtlProcessHeap(), 0, p);
  24. }
  25. PVOID
  26. SpMemRealloc(
  27. IN PVOID Block,
  28. IN SIZE_T NewSize
  29. )
  30. {
  31. return RtlReAllocateHeap(RtlProcessHeap(), 0, Block, NewSize);
  32. }
  33. int g_argi = 0;
  34. void CabTestCreateW(int argc, wchar_t** argv)
  35. {
  36. CCABHANDLE CabHandle;
  37. wchar_t** LocalArgv = argv + g_argi;
  38. CabHandle = SpCabCreateCabinetW(LocalArgv[1], (LocalArgv[1][0] != 0) ? LocalArgv[2] : NULL, (LocalArgv[3][0] != 0) ? LocalArgv[3] : NULL, 0);
  39. SpCabAddFileToCabinetW(CabHandle, LocalArgv[4], (LocalArgv[5] != NULL && LocalArgv[5][0] != 0) ? LocalArgv[5] : LocalArgv[4]);
  40. SpCabFlushAndCloseCabinetEx(CabHandle, NULL, NULL, NULL, NULL);
  41. g_argi += 4;
  42. g_argi += (LocalArgv[5] != NULL);
  43. /*
  44. SpCabCreateCabinetExW(0,0);
  45. SpCabOpenCabinetW(0);
  46. SpCabExtractAllFilesExW(0,0,0);
  47. SpCabCloseCabinetW(0);
  48. SpCabCreateCabinetA(0,0,0,0);
  49. SpCabCreateCabinetExA(0,0);
  50. SpCabOpenCabinetA(0);
  51. SpCabExtractAllFilesExA(0,0,0);
  52. SpCabCloseCabinetA(0);
  53. */
  54. }
  55. BOOL CabTestExtractFileCallbackW(PCWSTR File)
  56. {
  57. printf("extracting %ls\n", File);
  58. return TRUE;
  59. }
  60. BOOL CabTestExtractFileCallbackA(PCSTR File)
  61. {
  62. printf("extracting %s\n", File);
  63. return TRUE;
  64. }
  65. void CabTestExtractW(int argc, wchar_t** argv)
  66. {
  67. CCABHANDLE CabHandle;
  68. wchar_t** LocalArgv = argv + g_argi;
  69. CabHandle = SpCabOpenCabinetW(LocalArgv[1]);
  70. SpCabExtractAllFilesExW(CabHandle, LocalArgv[2], CabTestExtractFileCallbackW);
  71. SpCabCloseCabinet(CabHandle);
  72. g_argi += 2;
  73. }
  74. void CabTestExtractA(int argc, char** argv)
  75. {
  76. CCABHANDLE CabHandle;
  77. char** LocalArgv = argv + g_argi;
  78. CabHandle = SpCabOpenCabinetA(LocalArgv[1]);
  79. SpCabExtractAllFilesExA(CabHandle, LocalArgv[2], CabTestExtractFileCallbackA);
  80. SpCabCloseCabinet(CabHandle);
  81. g_argi += 2;
  82. }
  83. void CabTestCreateA(int argc, char** argv)
  84. {
  85. CCABHANDLE CabHandle;
  86. char** LocalArgv = argv + g_argi;
  87. CabHandle = SpCabCreateCabinetA(LocalArgv[1], (LocalArgv[1][0] != 0) ? LocalArgv[2] : NULL, (LocalArgv[3][0] != 0) ? LocalArgv[3] : NULL, 0);
  88. SpCabAddFileToCabinetA(CabHandle, LocalArgv[4], (LocalArgv[5] != NULL && LocalArgv[5][0] != 0) ? LocalArgv[5] : LocalArgv[4]);
  89. SpCabFlushAndCloseCabinetEx(CabHandle, NULL, NULL, NULL, NULL);
  90. g_argi += 4;
  91. g_argi += (LocalArgv[5] != NULL);
  92. }
  93. void MainA(int argc, char** argv)
  94. {
  95. argv[1] += (argv[1][0] == '-');
  96. if (_stricmp(argv[1], "create") == 0)
  97. CabTestCreateA(argc - 1, argv + 1);
  98. else if (_stricmp(argv[1], "extract") == 0)
  99. CabTestExtractA(argc - 1, argv + 1);
  100. }
  101. void MainW(int argc, wchar_t** argv)
  102. {
  103. argv[1] += (argv[1][0] == '-');
  104. if (_wcsicmp(argv[1], L"create") == 0)
  105. CabTestCreateW(argc - 1, argv + 1);
  106. else if (_wcsicmp(argv[1], L"extract") == 0)
  107. CabTestExtractW(argc - 1, argv + 1);
  108. }
  109. int __cdecl wmain(int argc, wchar_t** argv)
  110. {
  111. MainW(argc, argv);
  112. return 0;
  113. }
  114. void __cdecl wmainCRTStartup(void);
  115. int __cdecl main(int argc, char** argv)
  116. {
  117. MainA(argc, argv);
  118. wmainCRTStartup(); // trick to get A and W coverage in a single binary, this call doesn't return
  119. return 0;
  120. }