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.

196 lines
10 KiB

  1. #include <windows.h>
  2. #include <wincrypt.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <zlib.h>
  7. #include "compress.h"
  8. BYTE rgbTestCer [] = {
  9. 0x30, 0x82, 0x05, 0x8f, 0x30, 0x82, 0x04, 0xf8, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0a, 0x1e,
  10. 0x39, 0xa7, 0x1c, 0x00, 0x01, 0x00, 0x0f, 0xc9, 0x64, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  11. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x4b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
  12. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a,
  13. 0x13, 0x09, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x31, 0x0e, 0x30, 0x0c, 0x06,
  14. 0x03, 0x55, 0x04, 0x0b, 0x13, 0x05, 0x4e, 0x74, 0x64, 0x65, 0x76, 0x31, 0x18, 0x30, 0x16, 0x06,
  15. 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f, 0x4e, 0x54, 0x44, 0x45, 0x56, 0x20, 0x49, 0x53, 0x53, 0x55,
  16. 0x45, 0x33, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x31, 0x31, 0x31, 0x31, 0x39, 0x32,
  17. 0x31, 0x32, 0x39, 0x31, 0x34, 0x5a, 0x17, 0x0d, 0x30, 0x32, 0x30, 0x39, 0x32, 0x30, 0x32, 0x31,
  18. 0x33, 0x33, 0x32, 0x38, 0x5a, 0x30, 0x7b, 0x31, 0x13, 0x30, 0x11, 0x06, 0x0a, 0x09, 0x92, 0x26,
  19. 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x03, 0x63, 0x6f, 0x6d, 0x31, 0x19, 0x30, 0x17,
  20. 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x09, 0x6d, 0x69,
  21. 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x31, 0x15, 0x30, 0x13, 0x06, 0x0a, 0x09, 0x92, 0x26,
  22. 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x05, 0x6e, 0x74, 0x64, 0x65, 0x76, 0x31, 0x0c,
  23. 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x03, 0x49, 0x54, 0x47, 0x31, 0x0e, 0x30, 0x0c,
  24. 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x05, 0x55, 0x73, 0x65, 0x72, 0x73, 0x31, 0x14, 0x30, 0x12,
  25. 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0b, 0x44, 0x61, 0x6e, 0x20, 0x47, 0x72, 0x69, 0x66, 0x66,
  26. 0x69, 0x6e, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
  27. 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0x89,
  28. 0x9f, 0x70, 0xb2, 0x5e, 0xfd, 0x99, 0x31, 0xb8, 0xcd, 0x17, 0xba, 0x2f, 0x7c, 0xb9, 0xed, 0xde,
  29. 0x56, 0xff, 0xb3, 0x37, 0x78, 0xd0, 0x51, 0xae, 0x14, 0x7c, 0xae, 0x91, 0x1f, 0xb0, 0x26, 0x87,
  30. 0xaf, 0x43, 0x3e, 0xde, 0x59, 0xbb, 0xc8, 0xcf, 0xbe, 0x25, 0x03, 0x0a, 0x1c, 0xd8, 0x18, 0x4d,
  31. 0x1a, 0xbd, 0xe3, 0xb0, 0x73, 0xc9, 0x2b, 0x29, 0x0b, 0x0a, 0x12, 0xdd, 0x55, 0x37, 0xcb, 0x2b,
  32. 0x8f, 0xf2, 0xe6, 0x2c, 0x2e, 0x7f, 0x8d, 0x71, 0x9a, 0x77, 0xf6, 0x4e, 0x4e, 0x3e, 0x94, 0x2e,
  33. 0xdb, 0x3c, 0xd4, 0xde, 0x32, 0x1f, 0xc7, 0xb9, 0x96, 0x72, 0xbb, 0x0d, 0x80, 0xc9, 0xc0, 0x3e,
  34. 0x84, 0xee, 0x33, 0x3c, 0x62, 0x46, 0x17, 0x7d, 0x27, 0x83, 0x15, 0xdd, 0x2f, 0x2f, 0x0a, 0xb3,
  35. 0xcf, 0x76, 0xf6, 0x9b, 0x0d, 0x70, 0x6d, 0x99, 0x5b, 0xca, 0xba, 0x07, 0x8a, 0x44, 0xd3, 0x02,
  36. 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x03, 0x48, 0x30, 0x82, 0x03, 0x44, 0x30, 0x0b, 0x06, 0x03,
  37. 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x05, 0xa0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
  38. 0x04, 0x16, 0x04, 0x14, 0x38, 0xef, 0x1a, 0xde, 0x6f, 0x3e, 0xa8, 0x73, 0x86, 0x74, 0xb8, 0x27,
  39. 0x4b, 0x9e, 0x8a, 0x98, 0xf7, 0x67, 0x70, 0x47, 0x30, 0x2b, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04,
  40. 0x01, 0x82, 0x37, 0x14, 0x02, 0x04, 0x1e, 0x1e, 0x1c, 0x00, 0x53, 0x00, 0x6d, 0x00, 0x61, 0x00,
  41. 0x72, 0x00, 0x74, 0x00, 0x63, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x4c, 0x00, 0x6f, 0x00,
  42. 0x67, 0x00, 0x6f, 0x00, 0x6e, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,
  43. 0x80, 0x14, 0xc9, 0x44, 0x56, 0x4a, 0x90, 0x13, 0x7c, 0xa9, 0xf3, 0x33, 0x06, 0x6b, 0xde, 0xd0,
  44. 0x99, 0xbb, 0xe7, 0xc8, 0xce, 0xe9, 0x30, 0x82, 0x01, 0x26, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04,
  45. 0x82, 0x01, 0x1d, 0x30, 0x82, 0x01, 0x19, 0x30, 0x82, 0x01, 0x15, 0xa0, 0x82, 0x01, 0x11, 0xa0,
  46. 0x82, 0x01, 0x0d, 0x86, 0x81, 0xc4, 0x6c, 0x64, 0x61, 0x70, 0x3a, 0x2f, 0x2f, 0x2f, 0x43, 0x4e,
  47. 0x3d, 0x4e, 0x54, 0x44, 0x45, 0x56, 0x25, 0x32, 0x30, 0x49, 0x53, 0x53, 0x55, 0x45, 0x33, 0x25,
  48. 0x32, 0x30, 0x43, 0x41, 0x2c, 0x43, 0x4e, 0x3d, 0x57, 0x48, 0x49, 0x43, 0x41, 0x33, 0x2c, 0x43,
  49. 0x4e, 0x3d, 0x43, 0x44, 0x50, 0x2c, 0x43, 0x4e, 0x3d, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x25,
  50. 0x32, 0x30, 0x4b, 0x65, 0x79, 0x25, 0x32, 0x30, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73,
  51. 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2c, 0x43, 0x4e, 0x3d,
  52. 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x44, 0x43,
  53. 0x3d, 0x6e, 0x74, 0x64, 0x65, 0x76, 0x2c, 0x44, 0x43, 0x3d, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73,
  54. 0x6f, 0x66, 0x74, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d, 0x3f, 0x63, 0x65, 0x72, 0x74, 0x69,
  55. 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
  56. 0x4c, 0x69, 0x73, 0x74, 0x3f, 0x62, 0x61, 0x73, 0x65, 0x3f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74,
  57. 0x43, 0x6c, 0x61, 0x73, 0x73, 0x3d, 0x63, 0x52, 0x4c, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62,
  58. 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x86, 0x44, 0x68, 0x74, 0x74, 0x70,
  59. 0x3a, 0x2f, 0x2f, 0x77, 0x68, 0x69, 0x63, 0x61, 0x33, 0x2e, 0x6e, 0x74, 0x64, 0x65, 0x76, 0x2e,
  60. 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x43, 0x65,
  61. 0x72, 0x74, 0x45, 0x6e, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x4e, 0x54, 0x44, 0x45, 0x56, 0x25, 0x32,
  62. 0x30, 0x49, 0x53, 0x53, 0x55, 0x45, 0x33, 0x25, 0x32, 0x30, 0x43, 0x41, 0x2e, 0x63, 0x72, 0x6c,
  63. 0x30, 0x82, 0x01, 0x42, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x82,
  64. 0x01, 0x34, 0x30, 0x82, 0x01, 0x30, 0x30, 0x81, 0xbd, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05,
  65. 0x07, 0x30, 0x02, 0x86, 0x81, 0xb0, 0x6c, 0x64, 0x61, 0x70, 0x3a, 0x2f, 0x2f, 0x2f, 0x43, 0x4e,
  66. 0x3d, 0x4e, 0x54, 0x44, 0x45, 0x56, 0x25, 0x32, 0x30, 0x49, 0x53, 0x53, 0x55, 0x45, 0x33, 0x25,
  67. 0x32, 0x30, 0x43, 0x41, 0x2c, 0x43, 0x4e, 0x3d, 0x41, 0x49, 0x41, 0x2c, 0x43, 0x4e, 0x3d, 0x50,
  68. 0x75, 0x62, 0x6c, 0x69, 0x63, 0x25, 0x32, 0x30, 0x4b, 0x65, 0x79, 0x25, 0x32, 0x30, 0x53, 0x65,
  69. 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
  70. 0x65, 0x73, 0x2c, 0x43, 0x4e, 0x3d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74,
  71. 0x69, 0x6f, 0x6e, 0x2c, 0x44, 0x43, 0x3d, 0x6e, 0x74, 0x64, 0x65, 0x76, 0x2c, 0x44, 0x43, 0x3d,
  72. 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d,
  73. 0x3f, 0x63, 0x41, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x3f, 0x62,
  74. 0x61, 0x73, 0x65, 0x3f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x3d,
  75. 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x41, 0x75, 0x74,
  76. 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x30, 0x6e, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
  77. 0x30, 0x02, 0x86, 0x62, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x68, 0x69, 0x63, 0x61,
  78. 0x33, 0x2e, 0x6e, 0x74, 0x64, 0x65, 0x76, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66,
  79. 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x43, 0x65, 0x72, 0x74, 0x45, 0x6e, 0x72, 0x6f, 0x6c, 0x6c,
  80. 0x2f, 0x57, 0x48, 0x49, 0x43, 0x41, 0x33, 0x2e, 0x6e, 0x74, 0x64, 0x65, 0x76, 0x2e, 0x6d, 0x69,
  81. 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 0x4e, 0x54, 0x44, 0x45,
  82. 0x56, 0x25, 0x32, 0x30, 0x49, 0x53, 0x53, 0x55, 0x45, 0x33, 0x25, 0x32, 0x30, 0x43, 0x41, 0x28,
  83. 0x31, 0x29, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x18, 0x30,
  84. 0x16, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x14, 0x02, 0x02, 0x06, 0x08, 0x2b,
  85. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x37, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x30,
  86. 0x30, 0x2e, 0xa0, 0x2c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x14, 0x02, 0x03,
  87. 0xa0, 0x1e, 0x0c, 0x1c, 0x64, 0x61, 0x6e, 0x67, 0x72, 0x69, 0x66, 0x66, 0x40, 0x6e, 0x74, 0x64,
  88. 0x65, 0x76, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f, 0x6d,
  89. 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03,
  90. 0x81, 0x81, 0x00, 0x92, 0xe6, 0x34, 0x6a, 0x1b, 0x71, 0xe6, 0x91, 0x4a, 0x92, 0x35, 0x00, 0x2d,
  91. 0xe3, 0x20, 0x50, 0x68, 0x01, 0x7d, 0x92, 0xe7, 0xc1, 0x5c, 0xfd, 0x13, 0xb5, 0x49, 0x31, 0xc5,
  92. 0xc5, 0x0d, 0x5f, 0xa5, 0xf3, 0xa6, 0xd1, 0xb4, 0x28, 0x7b, 0x70, 0xfd, 0x16, 0xd2, 0x60, 0x3a,
  93. 0xa9, 0xa5, 0x39, 0x08, 0xed, 0x36, 0x76, 0xa5, 0x44, 0xf3, 0x45, 0x8e, 0x56, 0x63, 0xd6, 0xfe,
  94. 0x0e, 0xbd, 0x41, 0xf0, 0xdf, 0x2c, 0xa7, 0xdf, 0x03, 0xda, 0xf0, 0x35, 0x2f, 0x51, 0xab, 0xa3,
  95. 0x0d, 0x94, 0xb2, 0x89, 0x12, 0xe0, 0x30, 0x6f, 0xee, 0x1f, 0x09, 0x21, 0xe4, 0x3e, 0x51, 0x4f,
  96. 0xf0, 0x4a, 0xb3, 0x30, 0x87, 0xef, 0x7a, 0x49, 0x2f, 0x0e, 0x30, 0x4d, 0xd0, 0xd5, 0x4b, 0xfc,
  97. 0x77, 0xac, 0x81, 0xb8, 0xf1, 0x36, 0xfa, 0x9e, 0xbb, 0x35, 0x5b, 0xf7, 0x4a, 0x5f, 0x81, 0x16,
  98. 0x98, 0x27, 0xd7
  99. };
  100. #define cbTestCer sizeof(rgbTestCer)
  101. int _cdecl main(int argc, char * argv[])
  102. {
  103. DWORD dwSts = ERROR_SUCCESS;
  104. DWORD cbIn = 0;
  105. DWORD cbOut = 0;
  106. DWORD cbOut2 = 0;
  107. PBYTE pbOut = NULL;
  108. PBYTE pbOut2 = NULL;
  109. dwSts = CompressData(
  110. cbTestCer,
  111. rgbTestCer,
  112. &cbOut,
  113. NULL);
  114. if (ERROR_SUCCESS != dwSts)
  115. goto Ret;
  116. pbOut = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbOut);
  117. if (NULL == pbOut)
  118. {
  119. dwSts = ERROR_NOT_ENOUGH_MEMORY;
  120. goto Ret;
  121. }
  122. dwSts = CompressData(
  123. cbTestCer,
  124. rgbTestCer,
  125. &cbOut,
  126. pbOut);
  127. if (ERROR_SUCCESS != dwSts)
  128. goto Ret;
  129. printf("Compression ratio = %f\n",
  130. (float) cbTestCer / (float) cbOut);
  131. dwSts = UncompressData(
  132. cbOut,
  133. pbOut,
  134. &cbOut2,
  135. NULL);
  136. if (ERROR_SUCCESS != dwSts)
  137. goto Ret;
  138. pbOut2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbOut2);
  139. if (NULL == pbOut2)
  140. {
  141. dwSts = ERROR_NOT_ENOUGH_MEMORY;
  142. goto Ret;
  143. }
  144. dwSts = UncompressData(
  145. cbOut,
  146. pbOut,
  147. &cbOut2,
  148. pbOut2);
  149. if (ERROR_SUCCESS != dwSts)
  150. goto Ret;
  151. if (cbOut2 != cbTestCer)
  152. {
  153. printf("ERROR: data lengths don't match\n");
  154. dwSts = ERROR_INTERNAL_ERROR;
  155. goto Ret;
  156. }
  157. if (0 != memcmp(pbOut2, rgbTestCer, cbOut2))
  158. {
  159. printf("ERROR: data doesn't match\n");
  160. dwSts = ERROR_INTERNAL_ERROR;
  161. goto Ret;
  162. }
  163. Ret:
  164. if (ERROR_SUCCESS != dwSts)
  165. printf(" failed, 0x%x\n", dwSts);
  166. else
  167. printf("Success.\n");
  168. if (pbOut)
  169. HeapFree(GetProcessHeap(), 0, pbOut);
  170. if (pbOut2)
  171. HeapFree(GetProcessHeap(), 0, pbOut2);
  172. return 0;
  173. }