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.

125 lines
2.7 KiB

  1. @rem = '
  2. @perl.exe -w %~f0 %*
  3. @goto :EOF
  4. '; undef @rem;
  5. ### checkcrt.bat - list .obj files which import illegal crt functions.
  6. # Recursively scans all .obj files which are in obj\i386\ directories,
  7. # but doesn't recurse into directories called 'test'.
  8. #
  9. # @allowed: List of functions which are allowed as library references,
  10. # because Office implements them.
  11. @allowed = ("__purecall", "__ftol", "__except_handler3");
  12. foreach $a (@allowed) { $allowed{$a}=1; }
  13. ## checkObj - checks a given object file for imported names
  14. #
  15. # Scans link /dump /relocations for records that match illegal names
  16. sub checkObj {
  17. my $fn = $_[0];
  18. ## Exclude crtcheck.obj - it's part of the solution,
  19. ## not part of the problem.
  20. if ($fn =~ /crtcheck.obj$/i) { return; }
  21. $ObjectFilesChecked++;
  22. open(OBJ, "link /dump /relocations $fn |");
  23. while (<OBJ>) {
  24. if (/^ [0-9A-F]+\s+\S+\s+[0-9A-F]+\s+[0-9A-F]+\s+(__imp_)?(\S+)/) {
  25. my $func = $2;
  26. if (exists($illegal{$func})) {
  27. $import{$func}{$fn} = 1;
  28. } else {
  29. # print "Legal: $func\n";
  30. }
  31. }
  32. }
  33. close(OBJ);
  34. }
  35. ## processdir
  36. #
  37. # Processes a directory. If this is an obj\i386 directory, calls checkObj
  38. # for every *.obj file.
  39. #
  40. # Then recursively calls processdir for each subdirectory.
  41. sub processdir {
  42. my $dir = $_[0];
  43. my $fn;
  44. my $objdir = 0;
  45. $objdir = 1 if $dir =~ m[/obj/i386$];
  46. opendir(DIR, $dir);
  47. my @files = sort readdir(DIR);
  48. closedir(DIR);
  49. foreach $fn (@files) {
  50. if ($objdir) {
  51. if ($fn =~ /\.obj *$/) {
  52. checkObj("$dir/$fn");
  53. }
  54. }
  55. if (-d "$dir/$fn") {
  56. # Skip directories called ".", "..", or "test"
  57. if ($fn !~ /^(\.)|(\.\.)|(test)$/) {
  58. processdir("$dir/$fn");
  59. }
  60. }
  61. }
  62. }
  63. ## GetCRTentryPoints
  64. #
  65. # Uses link /dump on msvcrt.lib to obtain all its function names
  66. sub GetCRTentryPoints()
  67. {
  68. my $crtfn = $ENV{"_NTBINDIR"} . "\\public\\sdk\\lib\\i386\\msvcrt.lib";
  69. if (!-f $crtfn) { die "$crtfn not found.\n"; }
  70. #print "Debug: crtfn = $crtfn\n";
  71. open(LIB, "link /dump /exports $crtfn |");
  72. while (<LIB>) {
  73. if (/^ ([^ \r\n]+)/) {
  74. if (!$allowed{$1}) {
  75. $illegal{$1}++;
  76. # print "Illegal: $1\n";
  77. }
  78. }
  79. }
  80. close(LIB);
  81. }
  82. ### MAIN
  83. GetCRTentryPoints();
  84. processdir(".");
  85. foreach $i (sort keys %import) {
  86. print "$i\n";
  87. foreach $fn (sort keys %{ $import{$i} }) {
  88. $fn =~ s[^\./][];
  89. print "\t$fn\n";
  90. }
  91. }
  92. print "\n$ObjectFilesChecked object files checked.\n";