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.

273 lines
6.8 KiB

  1. @rem ='
  2. @echo off
  3. REM ------------------------------------------------------------------
  4. REM
  5. REM <<template_script.cmd>>
  6. REM <<purpose of this script>>
  7. REM
  8. REM Copyright (c) Microsoft Corporation. All rights reserved.
  9. REM
  10. REM ------------------------------------------------------------------
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. rem ';
  14. #!perl
  15. use strict;
  16. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  17. use lib $ENV{RAZZLETOOLPATH};
  18. use PbuildEnv;
  19. use ParseArgs;
  20. use BuildName;
  21. use GetIniSetting;
  22. use comlib;
  23. use Logmsg;
  24. use Cwd;
  25. use File::Basename qw(basename);
  26. require "$ENV{RAZZLETOOLPATH}\\sendmsg.pl";
  27. my $script_name=basename( $0 );
  28. sub Usage { print<<USAGE; exit(1) }
  29. $script_name - Verify Symbol
  30. $script_name [-l:<language>] [-b <BinTree>] [-s <SymbolPath>]
  31. [-t <SymbolCDList>] [-x <Symbad>] [-n <FullBuildName>] [-?]
  32. -----------------------------------------------------------------
  33. Language Default is usa.
  34. BinTree Binaries Tree, default is
  35. <SDXROOT>\\loc\\bin\\<lang>
  36. SymbolPath Symbol tree, default is
  37. <SymFarm>\\usa\\<BuildName>\\symbols.pri
  38. info from ini file and buildname.txt.
  39. SymbolCDList Symbolcd.txt, default is
  40. <_NTTREE>\\symbolcd\\usa\\SymbolCD.txt
  41. Symbad Symbad.txt, default is
  42. <RazzleToolPath>\\symbad.txt
  43. FullBuildName buildname; we use it to create SymbolPath,
  44. Default is find the text in
  45. <_NTTREE>\\build_logs\\buildname.txt
  46. USAGE
  47. my ($BinTree, $SymbolPath, $SymbolCDList, $Symbad, $FullBuildName, $prevReceiver);
  48. parseargs(
  49. 'b:' => \$BinTree,
  50. 's:' => \$SymbolPath,
  51. 't:' => \$SymbolCDList,
  52. 'x:' => \$Symbad,
  53. 'n:' => \$FullBuildName,
  54. '?' => \&Usage
  55. );
  56. &main;
  57. sub main {
  58. my (@SymbolPaths, $cntptr, $i);
  59. &FindBuildName if (!defined $FullBuildName);
  60. &FindBinTree if (!defined $BinTree);;
  61. &FindSymbolPath if (!defined $SymbolPath);
  62. &FindSymbolCDLst if (!defined $SymbolCDList);
  63. &FindSymbad if (!defined $Symbad);
  64. errmsg("$BinTree not exist.") if (("$BinTree" eq "") || (!-e $BinTree));
  65. errmsg("$SymbolPath not found.") if (("$SymbolPath" eq "") || (!-e $SymbolPath));
  66. errmsg("$SymbolCDList file not found.") if (("$SymbolCDList" eq "") || (!-e $SymbolCDList));
  67. logmsg( "Build name............[$FullBuildName]" );
  68. logmsg( "Symbol path...........[$SymbolPath]" );
  69. logmsg( "Symbol CD list........[$SymbolCDList]" );
  70. logmsg( "Symbol bad list.......[$Symbad]" );
  71. $cntptr = &ComposeNewSymbolCDLst($SymbolCDList);
  72. @SymbolPaths = &CollectSymbolTree($SymbolPath);
  73. for ($i=0; $i< @$cntptr; $i++) {
  74. open(F, "symchk.exe $cntptr->[$i] /s " . join("\;", @SymbolPaths) . " /x $Symbad |");
  75. while(<F>) {
  76. next if !/signatures/i;
  77. &WhoIsTheHacker($cntptr->[$i], $_);
  78. last;
  79. }
  80. close(F);
  81. }
  82. close(F);
  83. }
  84. sub FindBuildName {
  85. open(F, "$ENV{_NTTREE}\\build_logs\\buildname.txt");
  86. chomp($FullBuildName=<F>);
  87. close(F);
  88. }
  89. sub FindBinTree {
  90. $BinTree = "$ENV{SDXROOT}\\loc\\bin\\$ENV{lang}";
  91. }
  92. sub FindSymbolPath {
  93. my @iniRequest = ("SymFarm");
  94. my ( $SymFarm ) = &GetIniSetting::GetSetting( @iniRequest );
  95. my ( $BuildName ) = &BuildName::build_name($FullBuildName);
  96. $SymbolPath = "$SymFarm\\usa\\$BuildName\\symbols.pri";
  97. }
  98. sub FindSymbolCDLst {
  99. $SymbolCDList = "$ENV{_NTTREE}\\symbolcd\\usa\\SymbolCD.txt";
  100. }
  101. sub FindSymbad {
  102. $Symbad = "$ENV{RazzleToolPath}\\symbad.txt";
  103. }
  104. sub ComposeNewSymbolCDLst {
  105. my ($SymbolCDList) = shift;
  106. my ($temp, @content);
  107. # Strip filepath from SymbolCDLst.txt to @content (only store filename)
  108. open(F, "$SymbolCDList");
  109. @content = map({my $t=$_;chomp;($temp,$t)=&FilenameSplitor((split(/\,/, $t))[0]);$t} <F>);
  110. close(F);
  111. &IntellegentFileFinderBackward($BinTree, \@content);
  112. # Store the new file of SymbolCDLst.txt with in local path
  113. open(F, ">$ENV{temp}\\SymbolCDLst.new");
  114. map({print F $_ . "\n";;} @content);
  115. close(F);
  116. return \@content;
  117. }
  118. sub WhoIsTheHacker {
  119. my ($path, $filename) = &FilenameSplitor($_[0]);
  120. my ($msg)=$_[1];
  121. my $dir = cwd();
  122. chdir($path);
  123. my $alias=&LookForHacker($filename);
  124. my $sender = "ntbldi";
  125. my $title = "Mis-match Symbol - $filename";
  126. $msg .= "\nReferenced by : $path\\$filename";
  127. my @receivers = ( $alias,"cc:ntbldi" );
  128. print "@receivers\n";
  129. sendmsg( '-v', $sender, $title, $msg, @receivers );
  130. chdir($dir);
  131. }
  132. sub LookForHacker {
  133. my $file=shift;
  134. my($newfile, $workfile, $DescribeID, $defaultalias, $domain, $alias)=($file);
  135. my(@result, @result2, @Remains);
  136. do {{
  137. $workfile = $newfile;
  138. undef $newfile;
  139. chomp(@result = `sd filelog -m 1 $workfile`);
  140. for (@result) {
  141. if (/(copy|branch) from /) {
  142. $newfile = $';
  143. last;
  144. }
  145. }
  146. }} while("$newfile" ne "");
  147. ## # change 21839 integrate on 2000/11/28 20:28:27 by NTDEV\ntvbl06
  148. ## change 8510 add on 2001/07/23 12:06:06 by REDMOND\rtaboada@RTABOADA-MAIN (binary) 'JPN localized
  149. for (@result) {
  150. if (/change (\d+) \w+ on [\d\/]+ [\d\:]+ by ([^\@]+)\@/) {
  151. ($DescribeID, $defaultalias)=($1, $2);
  152. last;
  153. }
  154. }
  155. if (!defined $defaultalias) {
  156. print "Error: incorrect format for the log";
  157. map({print $_ . "\n"} @result);
  158. return;
  159. }
  160. $defaultalias =~ /(\w+)\\(\w+)/i;
  161. ($domain, $alias)=($1, $2);
  162. chomp(@result2 = `sd describe -s $DescribeID`);
  163. for (@result2) {
  164. next if (!/\S/);
  165. last if (/Affected files/i);
  166. next if (!/^\s+(.+)/);
  167. @Remains = split(/\s+/,$1);
  168. while ($Remains[0]=~/^build/i) {
  169. shift @Remains;
  170. }
  171. if (($Remains[0]=~/[\[\(]\w+[\]\)]/) || ($Remains[1]=~/^\[\-\:]$/)) {
  172. $Remains[0]=~s/[\[\]]//g;
  173. $alias = $Remains[0];
  174. }
  175. }
  176. return $alias;
  177. }
  178. sub CollectSymbolTree {
  179. my $symboltree = shift;
  180. my (%Result, $type, $path);
  181. for $type (qw(dll exe)) {
  182. for $path (`dir $symboltree\\$type /s /b /ad 2>nul`) {
  183. chomp $path;
  184. $path = "$symboltree\\$path" if ($path!~/\\/);
  185. ($path) = &FilenameSplitor($path);
  186. $Result{lc$path} = 1;
  187. }
  188. if (-d "$symboltree\\$type") {
  189. $Result{lc$symboltree} = 1;
  190. }
  191. }
  192. return keys %Result;
  193. }
  194. sub IntellegentFileFinderBackward {
  195. my ($rootpath, $filelistptr) = @_;
  196. my (@files, $found, @result, $file);
  197. chomp(@files = `dir $rootpath /s /b /a-d `);
  198. for $file (@files) {
  199. $found = 0;
  200. next if ($file=~/\_$/);
  201. for (@$filelistptr) {
  202. if ((defined $_) && ($file =~ /$_/i)) {
  203. $found = 1;
  204. last;
  205. }
  206. }
  207. if ($found eq 1) {
  208. push @result, $file;
  209. }
  210. }
  211. undef @$filelistptr;
  212. @$filelistptr = @result;
  213. return;
  214. }
  215. sub FilenameSplitor {
  216. $_[0]=~/^(.+)\\([^\\]+)\s*$/;
  217. my ($path, $filename)=($1, $2);
  218. $path=~s/^\s*//;
  219. $filename=~s/\s*$//;
  220. return (lc$path, lc$filename);
  221. }