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.

148 lines
3.7 KiB

  1. #include <windows.h>
  2. #include <winioctl.h>
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include <emsapi.h>
  6. int _cdecl wmain(int argc, WCHAR **argv)
  7. {
  8. EMSRawChannel* channel;
  9. UCHAR Buffer[256];
  10. ULONG CharCount;
  11. UCHAR AssembledString[1024];
  12. ULONG TotalCharCount;
  13. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  14. //
  15. // Configure the new channel
  16. //
  17. RtlZeroMemory(&Attributes, sizeof(SAC_CHANNEL_OPEN_ATTRIBUTES));
  18. Attributes.Type = ChannelTypeVTUTF8;
  19. Attributes.Name = L"Hello";
  20. Attributes.Description = NULL;
  21. Attributes.Flags = 0;
  22. Attributes.CloseEvent = NULL;
  23. Attributes.HasNewDataEvent = NULL;
  24. Attributes.ApplicationType = NULL;
  25. //
  26. // Open the Hello channel
  27. //
  28. channel = EMSRawChannel::Construct(Attributes);
  29. //
  30. // See if the channel was created
  31. //
  32. if (channel == NULL) {
  33. return 0;
  34. }
  35. do {
  36. //
  37. // Write to the Hello Channel
  38. //
  39. if (channel->Write(
  40. (PBYTE)"Hello, World! Type 'wow' to exit\r\n",
  41. sizeof("Hello, World! Type 'wow' to exit\r\n")
  42. )) {
  43. printf("Successfully printed string to channel\n");
  44. } else {
  45. printf("Failed to print string to channel\n");
  46. break;
  47. }
  48. //
  49. // Get remote user input
  50. //
  51. AssembledString[0] = '\0';
  52. TotalCharCount = 0;
  53. while(!(TotalCharCount == sizeof(AssembledString)-1))
  54. {
  55. //
  56. // Wait for remote user input
  57. //
  58. while(1) {
  59. BOOL InputWaiting;
  60. if (channel->HasNewData(
  61. &InputWaiting
  62. ))
  63. {
  64. if (InputWaiting) {
  65. break;
  66. }
  67. } else {
  68. printf("Failed to poll channel\n");
  69. break;
  70. }
  71. }
  72. if (channel->Read(
  73. Buffer,
  74. sizeof(Buffer),
  75. &CharCount
  76. )) {
  77. if (TotalCharCount + CharCount > sizeof(AssembledString)-1) {
  78. CharCount = sizeof(AssembledString)-1 - TotalCharCount;
  79. }
  80. TotalCharCount += CharCount;
  81. strncat((CHAR*)AssembledString, (CHAR*)Buffer, CharCount);
  82. } else {
  83. printf("Failed to read channel\n");
  84. break;
  85. }
  86. //
  87. // echo string back to remote user
  88. //
  89. if (channel->Write(
  90. (PBYTE)Buffer,
  91. CharCount
  92. )) {
  93. printf("Successfully printed string to channel\n");
  94. } else {
  95. printf("Failed to print string to channel\n");
  96. break;
  97. }
  98. if (strstr((CHAR*)AssembledString, "wow") != NULL) {
  99. //
  100. // Write to the Hello Channel
  101. //
  102. if (channel->Write(
  103. (PBYTE)"\r\nExiting\r\n",
  104. sizeof("\r\nExiting\r\n")
  105. )) {
  106. printf("Successfully printed string to channel\n");
  107. } else {
  108. printf("Failed to print string to channel\n");
  109. }
  110. break;
  111. }
  112. }
  113. } while (FALSE);
  114. //
  115. // Close the Hello Channel
  116. //
  117. delete channel;
  118. return 0;
  119. }