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.

202 lines
7.3 KiB

  1. #include <windows.h> /* required for all Windows applications */
  2. #define MAX_COMMUNICATION_BLOCK_SIZE 4096
  3. #define DEAD_VALUE 0xFEFEFEFEL
  4. #include <dbginfo.h>
  5. extern BOOL FAR PASCAL WowKillRemoteTask( LPSTR lpBuffer );
  6. int PASCAL WinMain(HANDLE hInstance,
  7. HANDLE hPrevInstance, LPSTR lpszCmdLine, int iCmd )
  8. {
  9. HANDLE hCommunicationBlock;
  10. LPSTR lpCommunicationBlock;
  11. BOOL b;
  12. LPCOM_HEADER lphead;
  13. WORD wArgsPassed;
  14. WORD wArgsSize;
  15. WORD wSuccess;
  16. DWORD dwReturnValue;
  17. LPSTR lpModuleName;
  18. LPSTR lpEntryName;
  19. HANDLE hModule;
  20. DWORD (FAR PASCAL *lpfn)();
  21. BOOL fFailed;
  22. LPWORD lpw;
  23. // We only want 1 instance of WOWDEB
  24. if ( hPrevInstance != NULL ) {
  25. return( FALSE );
  26. }
  27. hCommunicationBlock = GlobalAlloc(GMEM_FIXED, MAX_COMMUNICATION_BLOCK_SIZE);
  28. if ( hCommunicationBlock == (HANDLE)0 ) {
  29. OutputDebugString("Failed to allocate memory block\n");
  30. return( FALSE );
  31. }
  32. lpCommunicationBlock = GlobalLock(hCommunicationBlock);
  33. if ( lpCommunicationBlock == NULL ) {
  34. OutputDebugString("Failed to lock memory block\n");
  35. return( FALSE );
  36. }
  37. /*
  38. ** Just make sure that TOOLHELP is loaded before we remotely kill
  39. ** ourselves.
  40. */
  41. hModule = LoadLibrary( "TOOLHELP.DLL" );
  42. dwReturnValue = DEAD_VALUE;
  43. wSuccess = (WORD)FALSE;
  44. do {
  45. /*
  46. ** Initialize the communications block
  47. */
  48. lphead = (LPCOM_HEADER)lpCommunicationBlock;
  49. lphead->dwBlockAddress = (DWORD)lpCommunicationBlock;
  50. lphead->dwReturnValue = dwReturnValue;
  51. lphead->wArgsPassed = 0;
  52. lphead->wArgsSize = 0;
  53. lphead->wBlockLength = MAX_COMMUNICATION_BLOCK_SIZE;
  54. lphead->wSuccess = (WORD)wSuccess;
  55. b = WowKillRemoteTask( lpCommunicationBlock );
  56. if ( !b ) {
  57. break;
  58. }
  59. wSuccess = (WORD)FALSE;
  60. dwReturnValue = 0;
  61. /*
  62. ** Unpacketize the information and execute it
  63. ** Note: The below statements expect the contents of the structures
  64. ** to change after the above "WowKillRemoteTask" API call. If the
  65. ** compiler attempts to optimize the references below, it will get
  66. ** the wrong values.
  67. */
  68. wArgsPassed = lphead->wArgsPassed;
  69. wArgsSize = lphead->wArgsSize;
  70. lpModuleName = lpCommunicationBlock + sizeof(COM_HEADER) + wArgsSize;
  71. lpEntryName = lpModuleName + lstrlen(lpModuleName) + 1;
  72. hModule = LoadLibrary( lpModuleName );
  73. if ( hModule == 0 ) {
  74. #ifdef DEBUG
  75. OutputDebugString("Failed to load library\n");
  76. #endif
  77. continue;
  78. }
  79. lpfn = (DWORD (FAR PASCAL *)())GetProcAddress( hModule, lpEntryName );
  80. if ( lpfn == NULL ) {
  81. #ifdef DEBUG
  82. OutputDebugString("Failed to get proc address\n");
  83. #endif
  84. continue;
  85. }
  86. // Now copy the right number of bytes onto the stack and call the
  87. // function.
  88. lpw = (LPWORD)(lpCommunicationBlock + sizeof(COM_HEADER));
  89. fFailed = FALSE;
  90. // Cheesy way of putting a variable number of arguments on the stack
  91. // for a pascal call.
  92. switch( wArgsPassed ) {
  93. case 0:
  94. dwReturnValue = (* lpfn)();
  95. break;
  96. case 2:
  97. dwReturnValue = (* lpfn)( lpw[ 0] );
  98. break;
  99. case 4:
  100. dwReturnValue = (* lpfn)( lpw[ 1], lpw[ 0] );
  101. break;
  102. case 6:
  103. dwReturnValue = (* lpfn)( lpw[ 2], lpw[ 1], lpw[ 0] );
  104. break;
  105. case 8:
  106. dwReturnValue = (* lpfn)( lpw[ 3], lpw[ 2], lpw[ 1], lpw[ 0] );
  107. break;
  108. case 10:
  109. dwReturnValue = (* lpfn)( lpw[ 4], lpw[ 3], lpw[ 2], lpw[ 1],
  110. lpw[ 0] );
  111. break;
  112. case 12:
  113. dwReturnValue = (* lpfn)( lpw[ 5], lpw[ 4], lpw[ 3], lpw[ 2],
  114. lpw[ 1], lpw[ 0] );
  115. break;
  116. case 14:
  117. dwReturnValue = (* lpfn)( lpw[ 6], lpw[ 5], lpw[ 4], lpw[ 3],
  118. lpw[ 2], lpw[ 1], lpw[ 0] );
  119. break;
  120. case 16:
  121. dwReturnValue = (* lpfn)( lpw[ 7], lpw[ 6], lpw[ 5], lpw[ 4],
  122. lpw[ 3], lpw[ 2], lpw[ 1], lpw[ 0] );
  123. break;
  124. case 18:
  125. dwReturnValue = (* lpfn)( lpw[ 8], lpw[ 7], lpw[ 6], lpw[ 5],
  126. lpw[ 4], lpw[ 3], lpw[ 2], lpw[ 1],
  127. lpw[ 0] );
  128. break;
  129. case 20:
  130. dwReturnValue = (* lpfn)( lpw[ 9], lpw[ 8], lpw[ 7], lpw[ 6],
  131. lpw[ 5], lpw[ 4], lpw[ 3], lpw[ 2],
  132. lpw[ 1], lpw[ 0] );
  133. case 22:
  134. dwReturnValue = (* lpfn)( lpw[10], lpw[ 9], lpw[ 8], lpw[ 7],
  135. lpw[ 6], lpw[ 5], lpw[ 4], lpw[ 3],
  136. lpw[ 2], lpw[ 1], lpw[ 0] );
  137. break;
  138. case 24:
  139. dwReturnValue = (* lpfn)( lpw[11], lpw[10], lpw[ 9], lpw[ 8],
  140. lpw[ 7], lpw[ 6], lpw[ 5], lpw[ 4],
  141. lpw[ 3], lpw[ 2], lpw[ 1], lpw[ 0] );
  142. break;
  143. case 26:
  144. dwReturnValue = (* lpfn)( lpw[12], lpw[11], lpw[10], lpw[ 9],
  145. lpw[ 8], lpw[ 7], lpw[ 6], lpw[ 5],
  146. lpw[ 4], lpw[ 3], lpw[ 2], lpw[ 1],
  147. lpw[ 0] );
  148. break;
  149. case 28:
  150. dwReturnValue = (* lpfn)( lpw[13], lpw[12], lpw[11], lpw[10],
  151. lpw[ 9], lpw[ 8], lpw[ 7], lpw[ 6],
  152. lpw[ 5], lpw[ 4], lpw[ 3], lpw[ 2],
  153. lpw[ 1], lpw[ 0] );
  154. break;
  155. case 30:
  156. dwReturnValue = (* lpfn)( lpw[14], lpw[13], lpw[12], lpw[11],
  157. lpw[10], lpw[ 9], lpw[ 8], lpw[ 7],
  158. lpw[ 6], lpw[ 5], lpw[ 4], lpw[ 3],
  159. lpw[ 2], lpw[ 1], lpw[ 0] );
  160. break;
  161. case 32:
  162. dwReturnValue = (* lpfn)( lpw[15], lpw[14], lpw[13], lpw[12],
  163. lpw[11], lpw[10], lpw[ 9], lpw[ 8],
  164. lpw[ 7], lpw[ 6], lpw[ 5], lpw[ 4],
  165. lpw[ 3], lpw[ 2], lpw[ 1], lpw[ 0] );
  166. break;
  167. default:
  168. #ifdef DEBUG
  169. OutputDebugString("Wrong number of parameters\n");
  170. #endif
  171. fFailed = TRUE;
  172. break;
  173. }
  174. if ( fFailed ) {
  175. continue;
  176. }
  177. wSuccess = (WORD)TRUE;
  178. } while( TRUE );
  179. return( 1 );
  180. }