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.

102 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. lsastring.hxx
  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. #ifndef LSA_STRING_HXX
  15. #define LSA_STRING_HXX
  16. #ifdef __cplusplus
  17. class TSTRING
  18. {
  19. SIGNATURE('tstr');
  20. public:
  21. TSTRING(void);
  22. TSTRING(IN ULONG64 baseOffset);
  23. ~TSTRING(void);
  24. HRESULT IsValid(void) const;
  25. USHORT GetMaximumLengthDirect(void) const;
  26. USHORT GetLengthDirect(void) const;
  27. PCWSTR toWStrDirect(void) const;
  28. PCSTR toStrDirect(void) const;
  29. protected:
  30. HRESULT Initialize(IN ULONG64 baseOffset);
  31. private:
  32. HRESULT Initialize(void);
  33. //
  34. // T can be either CHAR or WCHAR
  35. //
  36. template<typename T>
  37. const T* InternalToTStrDirect(IN CONST T&) const
  38. {
  39. static T szBuffer[1024] = {0};
  40. USHORT Length = 0;
  41. ULONG64 addrBuffer = 0;
  42. ExitIfControlC();
  43. Length = GetLengthDirect();
  44. if (Length >= sizeof(szBuffer)) {
  45. DBG_LOG(LSA_ERROR, ("TSTRING Buffer Length is %d greate than %d\n", Length, sizeof(szBuffer)));
  46. throw "TSTRING::toTStrDirect failed with insufficient buffer";
  47. }
  48. //
  49. // NULL terminate the string
  50. //
  51. szBuffer[Length / sizeof(T)] = 0;
  52. addrBuffer = ReadPtrVar(ForwardAdjustPtrAddr(m_baseOffset + sizeof(USHORT) * 2));
  53. if (Length && !ReadMemory(addrBuffer, szBuffer, Length, NULL)) {
  54. DBG_LOG(LSA_ERROR, ("Unable read buffer %#I64x of Length %d from STRING %#I64x\n", addrBuffer, Length, m_baseOffset));
  55. throw "TSTRING::toTStrDirect failed to read buffer";
  56. }
  57. return szBuffer;
  58. }
  59. ULONG64 m_baseOffset;
  60. HRESULT m_hr;
  61. };
  62. #endif // #ifdef __cplusplus
  63. #endif // #ifndef LSA_STRING_HXX