Windows NT 4.0 source code leak
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.

175 lines
4.2 KiB

4 years ago
  1. // CVR: CodeView Record utilities
  2. #ifndef _VC_VER_INC
  3. #include "..\include\vcver.h"
  4. #endif
  5. #ifndef __CVR_INCLUDED__
  6. #define __CVR_INCLUDED__
  7. #ifndef __PDB_INCLUDED__
  8. #include <pdb.h>
  9. #endif
  10. #ifndef _CV_INFO_INCLUDED
  11. #include <cvinfo.h>
  12. #endif
  13. #ifndef _INC_STDDEF
  14. #include <stddef.h>
  15. #endif
  16. #ifndef _WINDOWS_
  17. // get rid of baggage we don't need from windows.h
  18. #define WIN32_LEAN_AND_MEAN
  19. //#define NOGDI
  20. #define NOUSER
  21. #define NONLS
  22. #include "windows.h"
  23. #endif
  24. typedef BYTE* PB;
  25. typedef long CB;
  26. typedef char* SZ; // zero terminated string
  27. typedef char* ST; // length prefixed string
  28. typedef SYMTYPE* PSYM;
  29. typedef SYMTYPE UNALIGNED * PSYMUNALIGNED;
  30. typedef TYPTYPE* PTYPE;
  31. //////////////////////////////////////////////////////////////////////////////
  32. // TII (type index iterator) implementation declarations
  33. typedef ptrdiff_t IB;
  34. struct TYTI { // position of type indices within a type record with the given leaf
  35. USHORT leaf;
  36. SZ sz; // leaf type name
  37. short cib;
  38. IB* rgibTI;
  39. TI* (*pfn)(PTYPE ptype, int iib, PB* ppb, PB pbEnd); // fn to call if cib == cibFunction
  40. PB (*pfnPbAfter)(void* pv); // end of record fn to call for elements of a field list
  41. };
  42. struct SYTI { // position of symbol indices within a symbol recoord with the given rectyp
  43. USHORT rectyp;
  44. SZ sz; // symbol rectyp name
  45. IB ibName; // position of symbol name
  46. ST (*pfnstName)(PSYM psym); // function to call if name offset variable
  47. BOOL isGlobal:1; // symbol is global
  48. BOOL unused:15;
  49. short cib;
  50. IB* rgibTI;
  51. };
  52. #if defined(PDB_LIBRARY)
  53. #define CVR_EXPORT
  54. #else
  55. #if defined(CVR_IMP)
  56. #define CVR_EXPORT __declspec(dllexport)
  57. #else
  58. #define CVR_EXPORT __declspec(dllimport)
  59. #endif
  60. #endif
  61. #ifndef CVRAPI
  62. #define CVRAPI __cdecl
  63. #endif
  64. class SymTiIter { // type indices within symbol record iterator
  65. public:
  66. CVR_EXPORT SymTiIter(PSYM psym_);
  67. inline TI& rti();
  68. inline BOOL next();
  69. private:
  70. PSYM psym; // current symbol
  71. int iib; // index of curren TI in this symbol record
  72. SYTI* psyti; // address of symbol->ti-info for current symbol record
  73. };
  74. inline TI& SymTiIter::rti()
  75. {
  76. return *(TI*)((PB)psym + psyti->rgibTI[iib]);
  77. }
  78. inline BOOL SymTiIter::next()
  79. {
  80. return ++iib < psyti->cib;
  81. }
  82. class TypeTiIter { // type indices within type record iterator
  83. public:
  84. TypeTiIter(TYPTYPE* ptype);
  85. inline TI& rti();
  86. BOOL next();
  87. PB pbFindField(USHORT leaf);
  88. private:
  89. void init();
  90. BOOL nextField();
  91. PTYPE ptype; // current type
  92. USHORT* pleaf; // leaf part of current type
  93. PB pbFnState; // private state of current iterating fn (iff ptyti->cib == cibFunction)
  94. PB pbEnd; // pointer just past end of type record
  95. int iib; // index of current TI in this type record
  96. BOOL isFieldList; // TRUE if this type record is a LF_FIELDLIST
  97. TI* pti; // address of current TI
  98. TYTI* ptyti; // address of type->ti-info for current type record
  99. };
  100. inline TI& TypeTiIter::rti()
  101. {
  102. return *pti;
  103. }
  104. // utility function protos
  105. CVR_EXPORT BOOL CVRAPI fGetSymName(PSYM psym, OUT ST* pst);
  106. BOOL fSymIsGlobal(PSYM psym);
  107. BOOL fGetTypeLeafName(PTYPE ptype, OUT SZ* psz);
  108. CVR_EXPORT BOOL CVRAPI fGetSymRecTypName(PSYM psym, OUT SZ* psz);
  109. ////////////////////////////////////////////////////////////////////////////////
  110. // Inline utility functions.
  111. // Return the number of bytes in an ST
  112. inline CB cbForSt(ST st)
  113. {
  114. return *(PB)st + 1;
  115. }
  116. // Return the number of bytes the type record occupies.
  117. //
  118. inline CB cbForType(PTYPE ptype)
  119. {
  120. return ptype->len + sizeof(ptype->len);
  121. }
  122. // Return a pointer to the byte just past the end of the type record.
  123. //
  124. inline PB pbEndType(PTYPE ptype)
  125. {
  126. return (PB)ptype + cbForType(ptype);
  127. }
  128. // Return the number of bytes the symbol record occupies.
  129. //
  130. #define MDALIGNTYPE_ DWORD
  131. inline CB cbAlign_(CB cb)
  132. {
  133. return ((cb + sizeof(MDALIGNTYPE_) - 1)) & ~(sizeof(MDALIGNTYPE_) - 1);
  134. }
  135. inline CB cbForSym(PSYMUNALIGNED psym)
  136. {
  137. CB cb = psym->reclen + sizeof(psym->reclen);
  138. // procrefs also have a hidden length preceeded name following the record
  139. if ((psym->rectyp == S_PROCREF) || (psym->rectyp == S_LPROCREF))
  140. cb += cbAlign_(cbForSt((ST)((PB)psym + cb)));
  141. return cb;
  142. }
  143. // Return a pointer to the byte just past the end of the symbol record.
  144. //
  145. inline PB pbEndSym(PSYM psym)
  146. {
  147. return (PB)psym + cbForSym(psym);
  148. }
  149. #endif // __CVR_INCLUDED__