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.

96 lines
2.5 KiB

  1. use strict;
  2. use lib $ENV{RAZZLETOOLPATH};
  3. use Logmsg;
  4. # declare locals
  5. my( $FHashFileName, $NHashFileName, $HashFileName );
  6. my( @FLines, @NLines, @HashLines );
  7. my( $FHash, $NHash, $Junk, $Line, $ThisFile, $ThisHash );
  8. # first, parse the command line
  9. # we require the params to be:
  10. # 1) the old hash temp file
  11. # 2) the new hash temp file
  12. # 3) the hash file to do the replacement in
  13. $FHashFileName = $ARGV[ 0 ];
  14. $NHashFileName = $ARGV[ 1 ];
  15. $HashFileName = $ARGV[ 2 ];
  16. # make sure they all exist
  17. if ( ( ! -e $FHashFileName ) ||
  18. ( ! -e $NHashFileName ) ||
  19. ( ! -e $HashFileName ) ) {
  20. errmsg( "Non-existent file names passed, exiting." );
  21. exit( 1 );
  22. }
  23. # now we can read in our hashes from fhash and nhash
  24. # first, read fhash
  25. # the format is currently: "filename - hash"
  26. # and we only care about the hash
  27. unless ( open( INFILE, $FHashFileName ) ) {
  28. errmsg( "Failed to open $FHashFileName for reading, exiting." );
  29. exit( 1 );
  30. }
  31. @FLines = <INFILE>;
  32. close( INFILE );
  33. # because there's only one hash in the file, just worry about the first line
  34. $FHash = $FLines[ 0 ];
  35. chomp( $FHash );
  36. ( $Junk, $Junk, $FHash ) = split( /\s+/, $FHash );
  37. # now $FHash is the has we want to replace in the master hash file
  38. # next we can read in the hash from nhash
  39. # the format is currently: "hash"
  40. unless ( open( INFILE, $NHashFileName ) ) {
  41. errmsg( "Failed to open $NHashFileName for reading, exiting." );
  42. exit( 1 );
  43. }
  44. @NLines = <INFILE>;
  45. close( INFILE );
  46. # again, just read the first line.
  47. $NHash = $NLines[ 0 ];
  48. chomp( $NHash );
  49. # no need to split, as we have what we need
  50. # now $NHash is what we want to replace the old hash with
  51. # finally, read in the master hash file, then do the replacement
  52. unless( open( INFILE, $HashFileName ) ) {
  53. errmsg( "Failed to open $HashFileName for reading, exiting." );
  54. exit( 1 );
  55. }
  56. @HashLines = <INFILE>;
  57. close( INFILE );
  58. # now re-open the file for writing (NOT appending!)
  59. unless ( open( OUTFILE, ">$HashFileName" ) ) {
  60. errmsg( "Failed to open $HashFileName for reading, exiting." );
  61. exit( 1 );
  62. }
  63. foreach $Line ( @HashLines ) {
  64. chomp( $Line );
  65. # check if this is the line we want to replace
  66. ( $ThisFile, $Junk, $ThisHash ) = split( /\s+/, $Line );
  67. if ( $ThisHash eq $FHash ) {
  68. # replace this line
  69. print( OUTFILE "$ThisFile - $NHash\n" );
  70. } else {
  71. # do nothing to this line
  72. print( OUTFILE "$Line\n" );
  73. }
  74. }
  75. close( OUTFILE );