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.

149 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. injectee.cxx
  5. Abstract:
  6. Injectee
  7. Author:
  8. Larry Zhu (LZhu) December 1, 2001 Created
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. #include "injectee.hxx"
  16. BOOL
  17. DllMain(
  18. IN HANDLE hModule,
  19. IN DWORD dwReason,
  20. IN DWORD dwReserved
  21. )
  22. {
  23. return DllMainDefaultHandler(hModule, dwReason, dwReason);
  24. }
  25. #if 0
  26. Return Values for Start():
  27. ERROR_NO_MORE_USER_HANDLES unload repeatedly
  28. ERROR_SERVER_HAS_OPEN_HANDLES no unload at all
  29. others unload once
  30. #endif 0
  31. int
  32. Start(
  33. IN ULONG cbParameters,
  34. IN VOID* pvParameters
  35. )
  36. {
  37. // do your stuff
  38. HMODULE hLib = LoadLibraryA((CHAR*) pvParameters);
  39. //
  40. // Unload the dll
  41. //
  42. if (hLib)
  43. {
  44. DebugPrintf(SSPI_LOG, "Start() LoadLibraryA(%s)\n", pvParameters);
  45. while (FreeLibrary(hLib))
  46. {
  47. }
  48. }
  49. else
  50. {
  51. DebugPrintf(SSPI_ERROR, "Start() LoadLibraryA(%s) failed with last error %#x\n", pvParameters, GetLastError());
  52. }
  53. return 0;
  54. }
  55. int
  56. RunIt(
  57. IN ULONG cbParameters,
  58. IN VOID* pvParameters
  59. )
  60. {
  61. //
  62. // RunItDefaultHandler calls Start() and adds try except
  63. //
  64. return RunItDefaultHandler(cbParameters, pvParameters);
  65. }
  66. int
  67. Init(
  68. IN ULONG argc,
  69. IN PCSTR argv[],
  70. OUT ULONG* pcbParameters,
  71. OUT VOID** ppvParameters
  72. )
  73. {
  74. DWORD dwErr = ERROR_SUCCESS;
  75. CHAR Parameters[REMOTE_PACKET_SIZE] = {0};
  76. ULONG cbBuffer = sizeof(Parameters);
  77. ULONG cbParameter = 0;
  78. DebugPrintf(SSPI_LOG, "Init: Hello world!\n");
  79. *pcbParameters = 0;
  80. *ppvParameters = NULL;
  81. if (argc == 1)
  82. {
  83. memcpy(Parameters + cbParameter, argv[0], strlen(argv[0]) + 1);
  84. cbParameter += strlen(argv[0]) + 1;
  85. cbParameter++; // add a NULL
  86. dwErr = ERROR_SUCCESS;
  87. }
  88. else // return "Usage" in ppvParameters, must be a NULL terminated string
  89. {
  90. strcpy(Parameters, "<dll to be unloaded>");
  91. cbParameter = strlen(Parameters) + 1;
  92. dwErr = ERROR_INVALID_PARAMETER; // will display usage
  93. }
  94. *ppvParameters = new CHAR[cbParameter];
  95. if (*ppvParameters)
  96. {
  97. *pcbParameters = cbParameter;
  98. memcpy(*ppvParameters, Parameters, *pcbParameters);
  99. }
  100. else
  101. {
  102. dwErr = ERROR_OUTOFMEMORY;
  103. goto Cleanup;
  104. }
  105. #if 0
  106. dwErr = ERROR_CONTINUE; // use the default Init handler in injecter
  107. #endif
  108. Cleanup:
  109. return dwErr;
  110. }