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.

381 lines
12 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: bindiff.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script is an example of a perl script in the NT postbuild
  7. # environment.
  8. #
  9. # Version: 1.00 (06/13/2000) : (dmiura) Add international complience
  10. #---------------------------------------------------------------------
  11. # Set Package
  12. package bindiff;
  13. # Set the script name
  14. $ENV{script_name} = 'bindiff.pl';
  15. # Set version
  16. $VERSION = '1.00';
  17. # Set required perl version
  18. require 5.003;
  19. # Use section
  20. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  21. use GetParams;
  22. use strict;
  23. no strict 'vars';
  24. use LocalEnvEx;
  25. use Logmsg;
  26. # Require section
  27. require Exporter;
  28. # Global variable section
  29. my( $ScriptName, $LogFile, $Return, $Argument, $AppendMode );
  30. my( $MyBinaries, $ExitCode );
  31. my( $DataFile, $SnapShotFile, $SnapShotFileBak, $SnapShotFileBakName );
  32. my( $ShapShotFileBakName, $DiffFile, $AltDiffFile, $TmpDiffFile, $FirstPass );
  33. my( $FirstPassFile );
  34. my( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime );
  35. my( $ctime, $blksize, $blocks );
  36. my( $ShortDiffFileName );
  37. sub Main {
  38. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  39. # Begin Main code section
  40. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  41. # Return when you want to exit on error
  42. # <Implement your code here>
  43. # before anything, if we're running first pass, we don't want to generate
  44. # bindiff files
  45. $FirstPassFile = $ENV{ "_NTPostBld" } . "\\congeal_scripts\\firstpass.txt";
  46. undef( $FirstPass );
  47. if ( -e $FirstPassFile ) { $FirstPass = "TRUE"; }
  48. # Check command line option
  49. if (defined $append) {$AppendMode = "-a"};
  50. $ExitCode = 0;
  51. $Logmsg::DEBUG = 1; # set to 1 to activate logging of dbgmsg's
  52. $DataFile = $ENV{_NTPostBld} . "\\build_logs\\CdData.txt";
  53. if ( -e "$DataFile\.full" ) { $DataFile .= "\.full"; }
  54. $SnapShotFile = $ENV{_NTPostBld} . "\\build_logs\\BinSnapShot.txt";
  55. $SnapShotFileBak = $ENV{_NTPostBld} . "\\build_logs\\BinSnapShot.bak";
  56. $SnapShotFileBakName = $SnapShotFileBak;
  57. if ( $SnapShotFileBak =~ /.*\\([^\\]+?)$/ ) { $SnapShotFileBakName = $1; }
  58. $DiffFile = $ENV{_NTPostBld} . "\\build_logs\\BinDiff.txt";
  59. $ShortDiffFileName = "BinDiff";
  60. $TmpDiffFile = $ENV{_NTPostBld} . "\\build_logs\\BinDiff1.txt";
  61. $AltDiffFile = $ENV{_NTPostBld} . "\\build_logs\\BinDiff2.txt";
  62. unless ( $AppendMode ) { &DeleteFile( $DiffFile ); }
  63. &DeleteFile( $SnapShotFileBak );
  64. # move the old snap shot file
  65. if ( -e $SnapShotFile ) { system( "ren $SnapShotFile $SnapShotFileBakName" ); }
  66. # parse CdData.txt to get our list of files
  67. &ReadDataFile();
  68. # if the backup exists, we need to compare now
  69. if ( -e $SnapShotFileBak ) {
  70. system( "windiff $SnapShotFileBak $SnapShotFile -Fx $TmpDiffFile" );
  71. system( "perl \%RazzleToolPath\%\\PostBuildScripts\\GenDiff.pl $AppendMode" );
  72. }
  73. # uniqify the bindiff.txt file
  74. if ( -e $DiffFile ) {
  75. system( "perl \%RazzleToolPath\%\\PostBuildScripts\\unique.pl -i\:$DiffFile " .
  76. "-o\:$AltDiffFile" );
  77. system( "copy $AltDiffFile $DiffFile" );
  78. }
  79. # save off each bindiff.txt for debugging
  80. &SaveFile ($ShortDiffFileName);
  81. # if we're first, pass delete the bindiff.txt file
  82. if ( $FirstPass eq "TRUE" ) { &DeleteFile( $DiffFile ); }
  83. # delete the old backup file
  84. &DeleteFile( $SnapShotFileBak );
  85. # delete the temporary diff file
  86. &DeleteFile( $TmpDiffFile );
  87. QuitGracefully:
  88. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  89. $ctime, $blksize, $blocks ) = stat( $DiffFile );
  90. #I don't think we want to delete 0-lenght bindiffs, but there may
  91. #be implications I don't realize, so I'm leaving the code in for now. Wade
  92. #if ( $size == 0 ) {
  93. # logmsg( "Zero length bindiff file, deleting ..." );
  94. # if (-e $DiffFile) {
  95. # system( "del $DiffFile" );
  96. # }
  97. #
  98. #}
  99. $ENV{errors} = "$ExitCode";
  100. return;
  101. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  102. # End Main code section
  103. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  104. }
  105. # <Implement your subs here>
  106. sub ReadDataFile
  107. {
  108. my( @DataLines, $Line, $FileName, $Junk );
  109. my( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime );
  110. my( $ctime, $blksize, $blocks );
  111. unless ( open( INFILE, $DataFile ) ) {
  112. errmsg( "Failed to open $DataFile, exiting." );
  113. $ExitCode++;
  114. goto QuitGracefully;
  115. }
  116. @DataLines = <INFILE>;
  117. close( INFILE );
  118. unless ( open( OUTFILE, ">$SnapShotFile" ) ) {
  119. errmsg( "Failed to open $SnapShotFile for write, exiting." );
  120. $ExitCode++;
  121. goto QuitGracefully;
  122. }
  123. foreach $Line ( @DataLines ) {
  124. if ( $Line =~ /\;/ ) { next; }
  125. ( $FileName, $Junk ) = split( /\s+/, $Line );
  126. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  127. $ctime, $blksize, $blocks ) = stat( $ENV{_NTPostBld} . "\\" . $FileName );
  128. print( OUTFILE "$ENV{_NTPostBld}\\$FileName , $size , $mtime\n" );
  129. }
  130. # add the ddk files brute force
  131. @DataLines = `\@for \/f \%a in \(\'dir \/b \/s \/a-d $ENV{_NTPostBld}\\ddk_flat\'\) do \@echo \%a , \%\~za , \%\~ta`;
  132. foreach $Line ( @DataLines ) {
  133. ( $FileName, $Junk ) = split( /\s+/, $Line );
  134. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  135. $ctime, $blksize, $blocks ) = stat( $FileName );
  136. print( OUTFILE "$FileName , $size , $mtime\n" );
  137. }
  138. # add the shimdll files brute force
  139. @DataLines = `\@for \/f \%a in \(\'dir \/b \/s \/a-d $ENV{_NTPostBld}\\shimdll\'\) do \@echo \%a , \%\~za , \%\~ta`;
  140. foreach $Line ( @DataLines ) {
  141. ( $FileName, $Junk ) = split( /\s+/, $Line );
  142. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  143. $ctime, $blksize, $blocks ) = stat( $FileName );
  144. print( OUTFILE "$FileName , $size , $mtime\n" );
  145. }
  146. # add adminpak files
  147. if ( lc $ENV{_BuildArch} eq 'x86' ) {
  148. my $adminddf = $ENV{_NTPostBld} . "\\adminpak\\adminpak.ddf";
  149. unless ( open( INFILE, "<$adminddf" ) ) {
  150. errmsg( "Failed to open $adminddf for write, exiting." );
  151. $ExitCode++;
  152. goto QuitGracefully;
  153. }
  154. @DataLines = <INFILE>;
  155. close( INFILE );
  156. foreach $Line ( @DataLines ) {
  157. chomp $Line;
  158. if ( $Line =~ /^\./ ) { next; }
  159. $FileName = "$ENV{_NTPostBld}\\" . $Line;
  160. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  161. $ctime, $blksize, $blocks ) = stat( $FileName );
  162. print( OUTFILE "$FileName , $size , $mtime\n" );
  163. }
  164. }
  165. close( OUTFILE );
  166. }
  167. sub SaveFile
  168. {
  169. my( $FileName ) = @_;
  170. my( $DirName ) = "$ENV{_NTPostBld}\\build_logs\\Bindiff_logs";
  171. my( $Return );
  172. my( $MaxNum ) = 0;
  173. my( $NextNum ) = 0;
  174. $Return = 0;
  175. $Return = system( "md $DirName" ) unless -d $DirName;
  176. if ( $Return != 0 ) {
  177. logmsg( "Failed to make $DirName." );
  178. }
  179. # Find the next available integer to distinguish bindiff files
  180. foreach (<$DirName\\$FileName*.txt>) {
  181. if (/BinDiff(\d+)\.txt$/) {
  182. $MaxNum = $1 if $1 >= $MaxNum;
  183. }
  184. }
  185. $NextNum = $MaxNum + 1;
  186. $DiffFileSave = "$DirName\\$FileName$NextNum.txt";
  187. $Return = system( "copy $DiffFile $DiffFileSave" );
  188. if ( $Return != 0) {
  189. logmsg( "Failed to copy $DiffFile to $DiffFileSave" );
  190. }
  191. }
  192. sub DeleteFile
  193. {
  194. my( $FileName ) = @_;
  195. my( $Return );
  196. $Return = 0;
  197. if ( -e $FileName ) {
  198. $Return = system( "del /f $FileName" );
  199. if ( $Return != 0 ) {
  200. logmsg( "Failed to delete $FileName, will append." );
  201. }
  202. }
  203. return( $Return );
  204. }
  205. sub ValidateParams {
  206. #<Add your code for validating the parameters here>
  207. }
  208. # <Add your usage here>
  209. sub Usage {
  210. print <<USAGE;
  211. Purpose of program
  212. Usage: $0 [-a -l lang]
  213. -a Append mode
  214. -l Language
  215. -? Displays usage
  216. Example:
  217. $0 -l jpn
  218. USAGE
  219. }
  220. sub GetParams {
  221. # Step 1: Call pm getparams with specified arguments
  222. &GetParams::getparams(@_);
  223. # Step 2: Set the language into the enviroment
  224. $ENV{lang}=$lang;
  225. # Step 3: Call the usage if specified by /?
  226. if ($HELP) {
  227. &Usage();
  228. exit 1;
  229. }
  230. }
  231. # Cmd entry point for script.
  232. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  233. # Step 1: Parse the command line
  234. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  235. &GetParams ('-o', 'al:', '-p', 'append lang', @ARGV);
  236. # Include local environment extensions
  237. &LocalEnvEx::localenvex('initialize');
  238. # Set lang from the environment
  239. $lang=$ENV{lang};
  240. # Validate the option given as parameter.
  241. &ValidateParams;
  242. # Step 4: Call the main function
  243. &bindiff::Main();
  244. # End local environment extensions.
  245. &LocalEnvEx::localenvex('end');
  246. }
  247. # -------------------------------------------------------------------------------------------
  248. # Script: template_script.pl
  249. # Purpose: Template perl perl script for the NT postbuild environment
  250. # SD Location: %sdxroot%\tools\postbuildscripts
  251. #
  252. # (1) Code section description:
  253. # CmdMain - Developer code section. This is where your work gets done.
  254. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  255. #
  256. # (2) Reserved Variables -
  257. # $ENV{HELP} - Flag that specifies usage.
  258. # $ENV{lang} - The specified language. Defaults to USA.
  259. # $ENV{logfile} - The path and filename of the logs file.
  260. # $ENV{logfile_bak} - The path and filename of the logfile.
  261. # $ENV{errfile} - The path and filename of the error file.
  262. # $ENV{tmpfile} - The path and filename of the temp file.
  263. # $ENV{errors} - The scripts errorlevel.
  264. # $ENV{script_name} - The script name.
  265. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  266. # postbuild operates on.
  267. #
  268. # (3) Reserved Subs -
  269. # Usage - Use this sub to discribe the scripts usage.
  270. # ValidateParams - Use this sub to verify the parameters passed to the script.
  271. #
  272. # (4) Call other executables or command scripts by using:
  273. # system "foo.exe";
  274. # Note that the executable/script you're calling with system must return a
  275. # non-zero value on errors to make the error checking mechanism work.
  276. #
  277. # Example
  278. # if (system("perl.exe foo.pl -l $lang")){
  279. # errmsg("perl.exe foo.pl -l $lang failed.");
  280. # # If you need to terminate function's execution on this error
  281. # goto End;
  282. # }
  283. #
  284. # (5) Log non-error information by using:
  285. # logmsg "<log message>";
  286. # and log error information by using:
  287. # errmsg "<error message>";
  288. #
  289. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  290. # by a member of the international build team (ntbintl).
  291. #
  292. # -------------------------------------------------------------------------------------------
  293. =head1 NAME
  294. B<mypackage> - What this package for
  295. =head1 SYNOPSIS
  296. <An code example how to use>
  297. =head1 DESCRIPTION
  298. <Use above example to describe this package>
  299. =head1 INSTANCES
  300. =head2 <myinstances>
  301. <Description of myinstances>
  302. =head1 METHODS
  303. =head2 <mymathods>
  304. <Description of mymathods>
  305. =head1 SEE ALSO
  306. <Some related package or None>
  307. =head1 AUTHOR
  308. <Your Name <your e-mail address>>
  309. =cut
  310. 1;