Source code of Windows XP (NT5)
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.

130 lines
2.5 KiB

  1. BEGIN {
  2. FSECTION = 0;
  3. FSYMBOLS = 0;
  4. ISECTION = 0;
  5. }
  6. / Start Length Name Class/ {
  7. FSECTION = 1;
  8. next;
  9. }
  10. /^ entry/ {
  11. next;
  12. }
  13. / Address Publics by Value/ {
  14. FSECTION = 0;
  15. FSYMBOLS = 1;
  16. next;
  17. }
  18. /^FIXUPS:/ {
  19. FSYMBOLS = 0;
  20. next;
  21. }
  22. {
  23. if (FSECTION) {
  24. do_section($0);
  25. }
  26. else if (FSYMBOLS) {
  27. do_symbol($0);
  28. }
  29. }
  30. function do_section( line, n, fields, subfields, sindex, soffset, slen, sname )
  31. {
  32. if (length(line) == 0)
  33. return;
  34. n = split( line, fields );
  35. n = split( fields[1], subfields, ":" );
  36. sindex = hex2dec( subfields[1] );
  37. soffset = hex2dec( subfields[2] );
  38. slen = hex2dec( fields[2] );
  39. sname = fields[3];
  40. SEC_INDEX[ISECTION] = sindex;
  41. SEC_OFFSET[ISECTION] = soffset;
  42. SEC_NAME[ISECTION] = sname;
  43. ISECTION++;
  44. write_sym( sname, soffset, "????", ".start.");
  45. write_sym( sname, soffset + slen, "????", ".end.");
  46. }
  47. function do_symbol( line, n, fields, subfields, sindex, sname, syoffset, modname, symname )
  48. {
  49. if (length(line) == 0)
  50. return;
  51. n = split( line, fields );
  52. if (n != 4 && n != 5)
  53. return;
  54. n = split( fields[1], subfields, ":");
  55. sindex = hex2dec( subfields[1] );
  56. syoffset = hex2dec( subfields[2] );
  57. modname = get_modname( fields[2] );
  58. symname = get_symname( fields[2] );
  59. sname = find_section(sindex, syoffset);
  60. write_sym( sname, syoffset, modname, symname);
  61. }
  62. function find_section( seg, offset, i )
  63. {
  64. for (i = 1; i < ISECTION; i++)
  65. {
  66. if (SEC_INDEX[i] > seg ||
  67. (SEC_INDEX[i] == seg && SEC_OFFSET[i] > offset))
  68. {
  69. return SEC_NAME[i-1];
  70. }
  71. }
  72. return SEC_NAME[ISECTION - 1];
  73. }
  74. function hex2dec(x, h, i, n, l, d, v)
  75. {
  76. h = "0123456789ABCDEF..........abcdef";
  77. n = 0;
  78. for (i = 1; i <= length(x); i++)
  79. {
  80. d = substr(x, i, 1);
  81. v = (index(h, d) - 1) % 16;
  82. if (v >= 0)
  83. n = 16*n + v;
  84. }
  85. return n;
  86. }
  87. function get_modname( str, i1, i2, result, c)
  88. {
  89. i1 = index(str, "@");
  90. i2 = i1 + index(substr(str, i1 + 1), "@");
  91. result = "";
  92. if (i2 > i1 + 1)
  93. result = substr(str, i1 + 1, i2 - i1 - 1);
  94. c = substr(result, 1, 1);
  95. if (result == "" || index("0123456789", c) != 0)
  96. result = "UNKNOWN";
  97. return result;
  98. }
  99. function get_symname( str, i1, result, c )
  100. {
  101. i1 = index(str, "@");
  102. if (i1 == 0)
  103. return substr(str, 1, 25);
  104. result = substr(str, 1, i1 -1);
  105. c = substr(result, 1, 1);
  106. if (c == "?")
  107. result = substr(result, 2);
  108. result = substr(result, 1, 25);
  109. return result;
  110. }
  111. function write_sym( secname, symoffset, modname, symname)
  112. {
  113. printf("%-12s", secname);
  114. printf("%8d ", symoffset);
  115. printf("%-18s", modname);
  116. printf(" %-25s\n", symname);
  117. }