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.

286 lines
6.0 KiB

  1. #include <windows.h>
  2. #include <winioctl.h>
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include <Shlwapi.h>
  6. #include <ntddsac.h>
  7. #include <sacapi.h>
  8. typedef struct _BYTEWISE_UUID {
  9. ULONG a;
  10. USHORT b;
  11. USHORT c;
  12. UCHAR e[8];
  13. } BYTEWISE_UUID, *PBYTEWISE_UUID;
  14. int htoi(
  15. char *c
  16. )
  17. {
  18. unsigned int result;
  19. (void) sscanf( (char *) c, "%x", &result );
  20. return result;
  21. }
  22. ULONG
  23. AtoGUID(
  24. IN WCHAR *s,
  25. OUT GUID *g
  26. )
  27. /*
  28. Description:
  29. translate the given string representation of a GUID into a real GUID.
  30. expected string format:
  31. 37a9b260-525d-11d6-870c-806d6172696f
  32. Args:
  33. s - the string to translate
  34. g - on success, the returned guid
  35. Return:
  36. 1 - success
  37. 0 - true
  38. */
  39. {
  40. ULONG l;
  41. PBYTEWISE_UUID p;
  42. ULONG x;
  43. ULONG y;
  44. l = wcslen(s);
  45. if (l != (16*2 + 4)) {
  46. return 0;
  47. }
  48. p = (PBYTEWISE_UUID)g;
  49. x = 0;
  50. y = 0;
  51. RtlZeroMemory(p, sizeof(BYTEWISE_UUID));
  52. p->a |= htoi((char *)&s[y++]) << 28;
  53. p->a |= htoi((char *)&s[y++]) << 24;
  54. p->a |= htoi((char *)&s[y++]) << 20;
  55. p->a |= htoi((char *)&s[y++]) << 16;
  56. p->a |= htoi((char *)&s[y++]) << 12;
  57. p->a |= htoi((char *)&s[y++]) << 8;
  58. p->a |= htoi((char *)&s[y++]) << 4;
  59. p->a |= htoi((char *)&s[y++]) << 0;
  60. // skip -
  61. y++;
  62. p->b |= htoi((char *)&s[y++]) << 12;
  63. p->b |= htoi((char *)&s[y++]) << 8;
  64. p->b |= htoi((char *)&s[y++]) << 4;
  65. p->b |= htoi((char *)&s[y++]) << 0;
  66. // skip -
  67. y++;
  68. p->c |= htoi((char *)&s[y++]) << 12;
  69. p->c |= htoi((char *)&s[y++]) << 8;
  70. p->c |= htoi((char *)&s[y++]) << 4;
  71. p->c |= htoi((char *)&s[y++]) << 0;
  72. // skip -
  73. y++;
  74. x = 0;
  75. p->e[x] |= htoi((char *)&s[y++]) << 4;
  76. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  77. p->e[x] |= htoi((char *)&s[y++]) << 4;
  78. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  79. // skip -
  80. y++;
  81. p->e[x] |= htoi((char *)&s[y++]) << 4;
  82. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  83. p->e[x] |= htoi((char *)&s[y++]) << 4;
  84. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  85. p->e[x] |= htoi((char *)&s[y++]) << 4;
  86. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  87. p->e[x] |= htoi((char *)&s[y++]) << 4;
  88. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  89. p->e[x] |= htoi((char *)&s[y++]) << 4;
  90. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  91. p->e[x] |= htoi((char *)&s[y++]) << 4;
  92. p->e[x] |= htoi((char *)&s[y++]) << 0; x++;
  93. //
  94. wprintf(L"s = %s, g = %06x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\r\n",
  95. s,
  96. p->a,
  97. p->b,
  98. p->c,
  99. p->e[0],
  100. p->e[1],
  101. p->e[2],
  102. p->e[3],
  103. p->e[4],
  104. p->e[5],
  105. p->e[6],
  106. p->e[7]
  107. );
  108. return 1;
  109. }
  110. int _cdecl wmain(int argc, WCHAR **argv)
  111. {
  112. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  113. SAC_CHANNEL_HANDLE SacChannelHandle;
  114. int c;
  115. //
  116. // Configure the new channel
  117. //
  118. RtlZeroMemory(&Attributes, sizeof(SAC_CHANNEL_OPEN_ATTRIBUTES));
  119. Attributes.Type = ChannelTypeVTUTF8;
  120. wnsprintf(
  121. Attributes.Name,
  122. SAC_MAX_CHANNEL_NAME_LENGTH+1,
  123. L"Spoofer"
  124. );
  125. wnsprintf(
  126. Attributes.Description,
  127. SAC_MAX_CHANNEL_DESCRIPTION_LENGTH+1,
  128. L"Spoofer"
  129. );
  130. Attributes.Flags = 0;
  131. Attributes.CloseEvent = NULL;
  132. Attributes.HasNewDataEvent = NULL;
  133. //
  134. // Open the Hello channel
  135. //
  136. if (SacChannelOpen(
  137. &SacChannelHandle,
  138. &Attributes
  139. )) {
  140. printf("Successfully opened new channel\n");
  141. } else {
  142. printf("Failed to open new channel\n");
  143. goto cleanup;
  144. }
  145. //
  146. // tweak the sac channel handle to have the guid we specified at the
  147. // command prompt
  148. //
  149. printf("driverhandle = %p\r\n", SacChannelHandle.DriverHandle);
  150. {
  151. ULONG x;
  152. PBYTEWISE_UUID p;
  153. p = (PBYTEWISE_UUID)&(SacChannelHandle.ChannelHandle);
  154. wprintf(L"g = %06x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\r\n",
  155. p->a,
  156. p->b,
  157. p->c,
  158. p->e[0],
  159. p->e[1],
  160. p->e[2],
  161. p->e[3],
  162. p->e[4],
  163. p->e[5],
  164. p->e[6],
  165. p->e[7]
  166. );
  167. }
  168. AtoGUID(argv[1], &(SacChannelHandle.ChannelHandle));
  169. printf("driverhandle = %p\r\n", SacChannelHandle.DriverHandle);
  170. {
  171. ULONG x;
  172. PBYTEWISE_UUID p;
  173. p = (PBYTEWISE_UUID)&(SacChannelHandle.ChannelHandle);
  174. wprintf(L"g = %06x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\r\n",
  175. p->a,
  176. p->b,
  177. p->c,
  178. p->e[0],
  179. p->e[1],
  180. p->e[2],
  181. p->e[3],
  182. p->e[4],
  183. p->e[5],
  184. p->e[6],
  185. p->e[7]
  186. );
  187. }
  188. //
  189. // Write to the Hello Channel
  190. //
  191. {
  192. PWCHAR String = L"Hello, World!\r\n";
  193. if (SacChannelVTUTF8WriteString(
  194. SacChannelHandle,
  195. String
  196. )) {
  197. printf("Successfully printed string to channel\n");
  198. } else {
  199. printf("Failed to print string to channel\n");
  200. }
  201. }
  202. //
  203. // Wait for user input
  204. //
  205. getc(stdin);
  206. //
  207. // Close the Hello Channel
  208. //
  209. if (SacChannelClose(&SacChannelHandle)) {
  210. printf("Successfully closed channel\n");
  211. } else {
  212. printf("Failed to close channel\n");
  213. }
  214. cleanup:
  215. return 0;
  216. }