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.

147 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. lsastring.cxx
  6. Abstract:
  7. This file provides useful accssors and mutators.
  8. Author:
  9. Larry Zhu (LZhu) May 1, 2001 Created
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. --*/
  14. #include "precomp.hxx"
  15. #pragma hdrstop
  16. #include "lsastring.hxx"
  17. #include <stdio.h>
  18. #include <string.h>
  19. TSTRING::TSTRING(void) : m_hr(E_FAIL)
  20. {
  21. }
  22. TSTRING::TSTRING(IN ULONG64 baseOffset)
  23. : m_baseOffset(baseOffset), m_hr(E_FAIL)
  24. {
  25. m_hr = Initialize();
  26. }
  27. TSTRING::~TSTRING(void)
  28. {
  29. }
  30. HRESULT TSTRING::IsValid(void) const
  31. {
  32. return m_hr;
  33. }
  34. USHORT TSTRING::GetMaximumLengthDirect(void) const
  35. {
  36. USHORT MaximumLength = 0;
  37. if (!ReadMemory(m_baseOffset + sizeof(USHORT), &MaximumLength, sizeof(MaximumLength), NULL)) {
  38. DBG_LOG(LSA_ERROR, ("Unable read STRING::MaximumLength from %#I64x\n", m_baseOffset));
  39. throw "TSTRING::GetMaximumLengthDirect failed";
  40. }
  41. return MaximumLength;
  42. }
  43. USHORT TSTRING::GetLengthDirect(void) const
  44. {
  45. USHORT Length = 0;
  46. if (!ReadMemory(m_baseOffset, &Length, sizeof(Length), NULL)) {
  47. DBG_LOG(LSA_ERROR, ("Unable read STRING::Length from %#I64x\n", m_baseOffset));
  48. throw "TSTRING::GetLengthDirect failed";
  49. }
  50. return Length;
  51. }
  52. PCWSTR TSTRING::toWStrDirect(void) const
  53. {
  54. //
  55. // use cDontCare in the template function InternalToTStrDirect to instantiate "T"
  56. //
  57. WCHAR cDontCare = 0;
  58. PCWSTR pszWStr = InternalToTStrDirect(cDontCare);
  59. return !*pszWStr ? kstrNullPtrW : pszWStr;
  60. }
  61. PCSTR TSTRING::toStrDirect(void) const
  62. {
  63. //
  64. // use cDontCare in the template function InternalToTStrDirect to instantiate "T"
  65. //
  66. CHAR cDontCare = 0;
  67. PCSTR pszStr = InternalToTStrDirect(cDontCare);
  68. return !*pszStr ? kstrNullPtrA : pszStr;
  69. }
  70. /******************************************************************************
  71. Private Methods
  72. ******************************************************************************/
  73. /*++
  74. Routine Name:
  75. Initialize
  76. Routine Description:
  77. Do necessary initialization.
  78. Arguments:
  79. None
  80. Return Value:
  81. An HRESULT
  82. --*/
  83. HRESULT TSTRING::Initialize(void)
  84. {
  85. HRESULT hRetval = E_FAIL;
  86. hRetval = S_OK;
  87. return hRetval;
  88. }
  89. HRESULT TSTRING::Initialize(IN ULONG64 baseOffset)
  90. {
  91. m_baseOffset = baseOffset;
  92. m_hr = Initialize();
  93. return m_hr;
  94. }