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.

101 lines
2.3 KiB

  1. #----------------------------------------------------------------#
  2. # Script: webbblade.pl
  3. #
  4. # (c) 2001 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script has the effect of updating the hash array
  7. # WebBladeDisallowedHashes in webbladehashesp.h with the hash
  8. # value for the exe specified as an argument.
  9. # webbladehashesp.h should be writable (opened for edit).
  10. # usage: perl webbpade.pl
  11. # <g:\nt\base\win32\client\webbladehashesp.h>
  12. # <root directory of exes to block>
  13. #
  14. #
  15. # Version: <1.00> 06/04/2001 : VishnuP
  16. #----------------------------------------------------------------#
  17. use File::Find;
  18. $VERSION = '1.00';
  19. if ($#ARGV < 1) {
  20. die "usage: perl webbblade.pl <webbladehashesp.h> <root directory of exes to block>";
  21. }
  22. $headerfile = shift;
  23. $dirname = shift;
  24. open(WEBBLADE, $headerfile) || die "cannot open file for reading\n";
  25. @hasharray = ();
  26. @filearray = ();
  27. %hashes = ();
  28. find sub {
  29. ($FileName = $File::Find::name) =~ s/\//\\/g;
  30. if ($FileName =~ m/exe/){
  31. push(@filearray, $FileName)}
  32. }, $dirname;
  33. foreach $file (@filearray) {
  34. #
  35. # first calculate the hash for each file.
  36. # even if one fails, exit
  37. #
  38. print "$file \n";
  39. $hashcmd = "hash.exe $file";
  40. $output = `$hashcmd`;
  41. if ($output =~ m/Hashing Succeeded:([0-9a-fA-F]{32,32})/){
  42. $hash = $1;
  43. }
  44. else {
  45. print "\nHashing failed for file $file with the following message ... $output\n";
  46. die "\n Please remove the offending files and rerun the script\n";
  47. }
  48. $hashquote = "\"$hash\"";
  49. $hashes{$hashquote} = 1;
  50. }
  51. $firstline = 1;
  52. while (<WEBBLADE>){
  53. if (/([\"0-9a-fA-F]{34,34})/){
  54. if ($firstline == 0){
  55. $hashes{$1} = 1;
  56. }
  57. }
  58. else {
  59. $poundDefine = $_;
  60. }
  61. $firstline = 0;
  62. }
  63. close(WEBBLADE);
  64. #
  65. # then sort it
  66. #
  67. @sortedHasharray = sort (keys %hashes);
  68. print "\nThere were $#sortedHasharray unique hashes in $dirname \n";
  69. #
  70. # for atomicity, make a temp file and copy it onto webbladehashesp.h
  71. #
  72. open(TMP, ">$headerfile.tmp") || die "cannot open temporary file for writing\n";
  73. $allhashes = join(",\\\n", @sortedHasharray);
  74. print TMP "$poundDefine";
  75. print TMP "$allhashes";
  76. close(TMP);
  77. $copycmd = "copy /Y $headerfile.tmp $headerfile";
  78. print `$copycmd`;
  79. unlink("$headerfile.tmp");