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.

180 lines
3.6 KiB

  1. #---------------------------------------------------------------------
  2. package Updcat;
  3. #
  4. # Copyright (c) Microsoft Corporation. All rights reserved.
  5. #
  6. # Version: 1.00 Update catalogs by adding and/or removing hashes
  7. #---------------------------------------------------------------------
  8. use strict;
  9. use Carp;
  10. use lib $ENV{RAZZLETOOLPATH}. "\\sp";
  11. use File::Temp qw(tempfile);
  12. use vars qw($VERSION);
  13. use Data::Dumper;
  14. $VERSION = '1.00';
  15. my $LastError;
  16. sub GetLastError
  17. {
  18. return $LastError;
  19. }
  20. #
  21. # Parameters:
  22. #
  23. # catalog - path to catalog to update
  24. #
  25. # remove_hashes -
  26. # option 1: an array of hashes
  27. # option 2: path of a file containing hashes
  28. # option 3: undef, no hashes to remove
  29. #
  30. # add_file_signatures -
  31. # option 1: an array of file paths
  32. # option 2: path of file containing file paths
  33. # option 3: undef, no file signatures to add
  34. #
  35. sub Update
  36. {
  37. my $catalog = shift;
  38. my $remove_hashes = shift;
  39. my $add_file_signatures = shift;
  40. my $add_drm_list = shift;
  41. my $command_line = "";
  42. my ($fn1, $fn2);
  43. if ( 'ARRAY' eq ref $remove_hashes &&
  44. @$remove_hashes )
  45. {
  46. my $fh;
  47. ($fh, $fn1) = tempfile();
  48. if ( $! )
  49. {
  50. $LastError = "Failed opening temporary file ($!)";
  51. return;
  52. }
  53. print $fh "$_\n" foreach (@$remove_hashes);
  54. close $fh;
  55. $command_line .= " -d @". $fn1;
  56. }
  57. elsif ( 'SCALAR' eq ref $remove_hashes &&
  58. defined $remove_hashes )
  59. {
  60. $command_line .= " -d @". $$remove_hashes;
  61. }
  62. elsif ( defined $remove_hashes )
  63. {
  64. $command_line .= " -d @". $remove_hashes;
  65. }
  66. if ( 'ARRAY' eq ref $add_file_signatures &&
  67. @$add_file_signatures )
  68. {
  69. my $fh;
  70. ($fh, $fn2) = tempfile();
  71. if ( $! )
  72. {
  73. $LastError = "Failed opening temporary file ($!)";
  74. return;
  75. }
  76. print $fh "$_\n" foreach (@$add_file_signatures);
  77. close $fh;
  78. $command_line .= " -a @". $fn2;
  79. }
  80. elsif ( 'SCALAR' eq ref $add_file_signatures &&
  81. defined $add_file_signatures )
  82. {
  83. $command_line .= " -a @". $$add_file_signatures;
  84. }
  85. elsif ( defined $add_file_signatures )
  86. {
  87. $command_line .= " -a @". $add_file_signatures;
  88. }
  89. if ( !$command_line )
  90. {
  91. carp "Invalid (empty) arguments specified.";
  92. return 1;
  93. }
  94. $command_line = "updcat.exe $catalog $command_line";
  95. my $retval;
  96. sys($command_line) || return;
  97. if ('ARRAY' eq ref $add_drm_list && @$add_drm_list ){
  98. addDrmAttrib($add_drm_list ,$catalog) ||return ;
  99. }
  100. unlink $fn1 if $fn1;
  101. unlink $fn2 if $fn2;
  102. return 1 ;
  103. }
  104. sub addDrmAttrib {
  105. my $drm_file = shift;
  106. my $catalog = shift;
  107. my $cmd_line;
  108. foreach ( @$drm_file) {
  109. $cmd_line = "updcat $catalog -attr $$_[0] DRMLevel $$_[1]";
  110. sys("$cmd_line") || return;
  111. }
  112. return 1;
  113. }
  114. sub sys {
  115. my $cmd_line = shift;
  116. my $retval;
  117. print("Running $cmd_line \n");
  118. system($cmd_line);
  119. if ( $! )
  120. {
  121. $LastError = "Unable to execute updcat.exe ($!)";
  122. return ;
  123. }
  124. elsif ( $? )
  125. {
  126. $LastError = "'$cmd_line' failed (". ($?>>8). ")";
  127. return ;
  128. }
  129. else
  130. {
  131. return 1;
  132. }
  133. }
  134. 1;
  135. __END__
  136. =head1 NAME
  137. <<mypackage>> - <<short description>>
  138. =head1 SYNOPSIS
  139. <<A short code example>>
  140. =head1 DESCRIPTION
  141. <<The purpose and functionality of this module>>
  142. =head1 AUTHOR
  143. <<your alias>>
  144. =head1 COPYRIGHT
  145. Copyright (c) Microsoft Corporation. All rights reserved.
  146. =cut