Source code of Windows XP (NT5)
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.

94 lines
2.0 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. # <c:\disallow\candidate1.exe>...
  13. # <c:\disallow\candidaten.exe>
  14. #
  15. #
  16. # Version: <1.00> 06/04/2001 : VishnuP
  17. #----------------------------------------------------------------#
  18. $VERSION = '1.00';
  19. if ($#ARGV < 1) {
  20. die "usage: perl webbblade.pl <webbladehashesp.h> <candidate1.exe> <candidate2.exe> ...\n";
  21. }
  22. $headerfile = shift;
  23. open(WEBBLADE, $headerfile) || die "cannot open file for reading\n";
  24. @hasharray = ();
  25. %hashes = ();
  26. foreach $candidate (@ARGV) {
  27. if (-e $candidate) {
  28. #
  29. # first calculate the hash for each candidate.exe etc.
  30. # even if one fails, exit
  31. #
  32. $hashcmd = "hash.exe $candidate";
  33. $output = `$hashcmd`;
  34. if ($output =~ m/Hashing Succeeded:([0-9a-fA-F]{32,32})/){
  35. $hash = $1;
  36. }
  37. else {
  38. print "\nHashing failed for file $candidate with the following message ... $output\n";
  39. die "\n Please remove the offending files and rerun the script\n";
  40. }
  41. $hashquote = "\"$hash\"";
  42. $hashes{$hashquote} = 1;
  43. }
  44. else {
  45. die "\n$candidate not found\n";
  46. }
  47. }
  48. $firstline = 1;
  49. while (<WEBBLADE>){
  50. if (/([\"0-9a-fA-F]{34,34})/){
  51. if ($firstline == 0){
  52. $hashes{$1} = 1;
  53. }
  54. }
  55. else {
  56. $poundDefine = $_;
  57. }
  58. $firstline = 0;
  59. }
  60. close(WEBBLADE);
  61. #
  62. # then sort it
  63. #
  64. @sortedHasharray = sort (keys %hashes);
  65. #
  66. # for atomicity, make a temp file and copy it onto webbladehashesp.h
  67. #
  68. open(TMP, ">$headerfile.tmp") || die "cannot open temporary file for writing\n";
  69. $allhashes = join(",\\\n", @sortedHasharray);
  70. print TMP "$poundDefine";
  71. print TMP "$allhashes";
  72. close(TMP);
  73. $copycmd = "copy /Y $headerfile.tmp $headerfile";
  74. print `$copycmd`;
  75. unlink("$headerfile.tmp");