With all the craze surrounding PDC 2005 and availability of many downloads (RC of Visual Studio 2005 is already available!) for both MSDN subscribers and general public it is now appropriate to improve upon the ruby script that validates MSDN downloads using Microsoft provided SHA1 hash. This time I have added the ability to provide a text file with the list of file names and hashes to validate. The format of the file is simple:

full_path_to_file_for_validation|hash_lowercase

In order to use this file you call msdnh like so:

msdnh.rb --list list_file_name.txt

Script is slightly bigger than the last time:

require 'digest/sha1'
def validate(file, hash)
  hsh = Digest::SHA1.new
  File.open(file, "rb") { |f| hsh << f.read(1024*1024) while !f.eof? }
  if hash.downcase != hsh.hexdigest
    puts "Hashes do NOT match, file '#{file}' is invalid."
  else
    puts "Hashes match, file '#{file}' is valid."
  end
end
if ARGV.length != 2
  puts "Usage: msdnh (--list file_with_list | file_to_hash hash_as_hex)"
elsif ARGV[0] == "--list" && File.exist?(ARGV[1])
  File.new(ARGV[1], "r").readlines.each { |line| validate(*line.split('|')) }
else
  validate(ARGV[0], ARGV[1])
end

Enjoy!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments