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.

181 lines
4.3 KiB

4 years ago
  1. /***********************************************************************
  2. * Microsoft (R) 32-Bit Incremental Linker
  3. *
  4. * Copyright (C) Microsoft Corp 1992-95. All rights reserved.
  5. *
  6. * File: cpp.cpp
  7. *
  8. * File Comments:
  9. *
  10. * C++ specific support for Link
  11. *
  12. ***********************************************************************/
  13. #include "link.h"
  14. #define _CRTBLD // Use copy from C runtime DLL
  15. #include "undname.h"
  16. char *
  17. SzUndecorateNameOnly(
  18. const char *szIn
  19. )
  20. {
  21. char *szUndecorated;
  22. if (szIn[0] != '?') {
  23. return((char *) szIn);
  24. }
  25. szUndecorated = __unDName(NULL,
  26. szIn,
  27. 0,
  28. &malloc,
  29. &free,
  30. UNDNAME_32_BIT_DECODE | UNDNAME_NAME_ONLY);
  31. if (szUndecorated == NULL) {
  32. // Undecorator failed
  33. return((char *) szIn);
  34. }
  35. return(szUndecorated);
  36. }
  37. char *
  38. SzOutputSymbolName(
  39. const char *szIn,
  40. BOOL fDnameLast
  41. )
  42. {
  43. const char *szDname;
  44. BOOL fImport;
  45. BOOL fCrossTOCGlue;
  46. BOOL fEntry;
  47. BOOL fNativeEntry;
  48. BOOL fFunctionHeader;
  49. BOOL fPCodeCallTable;
  50. char *szUndecorated;
  51. size_t cchOut = 0;
  52. char *szOut;
  53. #define szDeclspec "__declspec(dllimport) "
  54. #define szCrossTOCGlue "[Cross TOC Glue] "
  55. #define szEntry "[Entry] "
  56. #define szNativeEntry "[Native Entry] "
  57. #define szFunctionHeader "[Function Header] "
  58. #define szPCodeCallTable "[PCode Call Table] "
  59. szDname = szIn;
  60. if (fImport = (strncmp(szDname, "__imp_", 6) == 0)) {
  61. szDname += 6;
  62. } else if (fCrossTOCGlue = (strncmp(szDname, "__glue_", 6) == 0)) {
  63. szDname += 7;
  64. }
  65. if (fEntry = (strncmp(szDname, "..", 2) == 0)) {
  66. szDname += 2;
  67. } else if (fNativeEntry = (strncmp(szDname, "__nep", 5) == 0)) {
  68. szDname += 5;
  69. } else if (fFunctionHeader = (strncmp(szDname, "__fh", 4) == 0)) {
  70. szDname += 4;
  71. } else if (fPCodeCallTable = (strncmp(szDname, "__pcd_tbl", 9) == 0)) {
  72. szDname += 9;
  73. }
  74. if (szDname[0] != '?') {
  75. return((char *) szIn);
  76. }
  77. szUndecorated = __unDName(NULL,
  78. szDname,
  79. 0,
  80. &malloc,
  81. &free,
  82. UNDNAME_32_BIT_DECODE);
  83. if (szUndecorated == NULL) {
  84. // Undecorator failed
  85. return((char *) szIn);
  86. }
  87. if (fImport) {
  88. // Prefix "__declspec(dllimport) " to the undecorated name
  89. cchOut += sizeof(szDeclspec) - 1;
  90. } else if (fCrossTOCGlue) {
  91. // Prefix "[Cross TOC Glue] " to the undecorated name
  92. cchOut += sizeof(szCrossTOCGlue) - 1;
  93. }
  94. if (fEntry) {
  95. // Prefix "[Entry] " to the undecorated name
  96. cchOut += sizeof(szEntry) - 1;
  97. } else if (fNativeEntry) {
  98. // Prefix "[Native Entry] " to the undecorated name
  99. cchOut += sizeof(szNativeEntry) - 1;
  100. } else if (fFunctionHeader) {
  101. // Prefix "[Function Header] " to the undecorated name
  102. cchOut += sizeof(szFunctionHeader) - 1;
  103. } else if (fPCodeCallTable) {
  104. // Prefix "[PCode Call Table] " to the undecorated name
  105. cchOut += sizeof(szPCodeCallTable) - 1;
  106. }
  107. if (fDnameLast) {
  108. // Alloc: " undname ", '(' dname ')', '\0'
  109. cchOut += strlen(szUndecorated) + 2 + strlen(szIn) + 3;
  110. } else {
  111. // Alloc: [dname (with space)], '(', undname, ')', '\0'
  112. cchOut += strlen(szIn) + 1 + strlen(szUndecorated) + 3;
  113. }
  114. szOut = (char *) PvAlloc(cchOut);
  115. if (fDnameLast) {
  116. strcpy(szOut, "\"");
  117. } else {
  118. strcpy(szOut, szIn);
  119. strcat(szOut, " (");
  120. }
  121. if (fImport) {
  122. strcat(szOut, szDeclspec);
  123. } else if (fCrossTOCGlue) {
  124. strcat(szOut, szCrossTOCGlue);
  125. }
  126. if (fEntry) {
  127. strcat(szOut, szEntry);
  128. } else if (fNativeEntry) {
  129. strcat(szOut, szNativeEntry);
  130. } else if (fFunctionHeader) {
  131. strcat(szOut, szFunctionHeader);
  132. } else if (fPCodeCallTable) {
  133. strcat(szOut, szPCodeCallTable);
  134. }
  135. strcat(szOut, szUndecorated);
  136. if (fDnameLast) {
  137. strcat(szOut, "\"(");
  138. strcat(szOut, szIn);
  139. }
  140. strcat(szOut, ")");
  141. return(szOut);
  142. }