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.

101 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. AddProcessParametersFlags.cpp
  5. Abstract:
  6. Use this shim to add flags to Peb->ProcessParameters->Flags.
  7. It takes a command line to specify the flags in hex numbers. Note that the Flags
  8. are a ULONG so specify at most 8 digits for the number. The flags you specify
  9. will be OR-ed with the existing Peb->ProcessParameters->Flags.
  10. eg: 1000
  11. which is RTL_USER_PROC_DLL_REDIRECTION_LOCAL.
  12. Notes:
  13. This is a general purpose shim.
  14. History:
  15. 09/27/2002 maonis Created
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(AddProcessParametersFlags)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_END
  22. VOID
  23. ProcessCommandLine(
  24. LPCSTR lpCommandLine
  25. )
  26. {
  27. ANSI_STRING AnsiString;
  28. WCHAR wszBuffer[16];
  29. UNICODE_STRING UnicodeString;
  30. ULONG ulFlags;
  31. PPEB Peb = NtCurrentPeb();
  32. RtlInitAnsiString(&AnsiString, lpCommandLine);
  33. UnicodeString.Buffer = wszBuffer;
  34. UnicodeString.MaximumLength = sizeof(wszBuffer);
  35. if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&UnicodeString,
  36. &AnsiString,
  37. FALSE)))
  38. {
  39. DPFN(eDbgLevelError,
  40. "[ParseCommandLine] Failed to convert string \"%s\" to UNICODE.\n",
  41. lpCommandLine);
  42. return;
  43. }
  44. if (!NT_SUCCESS(RtlUnicodeStringToInteger(&UnicodeString,
  45. 16,
  46. &ulFlags)))
  47. {
  48. DPFN(eDbgLevelError,
  49. "[ParseCommandLine] Failed to convert string \"%s\" to a hex number.\n",
  50. lpCommandLine);
  51. return;
  52. }
  53. Peb->ProcessParameters->Flags |= ulFlags;
  54. }
  55. /*++
  56. Register hooked functions
  57. --*/
  58. BOOL
  59. NOTIFY_FUNCTION(
  60. DWORD fdwReason)
  61. {
  62. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED) {
  63. ProcessCommandLine(COMMAND_LINE);
  64. }
  65. return TRUE;
  66. }
  67. HOOK_BEGIN
  68. CALL_NOTIFY_FUNCTION
  69. HOOK_END
  70. IMPLEMENT_SHIM_END