How do I generate hashes?

This forum is for the discussion of dumping games. Get help with your dumping here.

Moderator: Moderators

Post Reply
Blai
Posts: 7
Joined: Fri Nov 20, 2015 6:29 am

How do I generate hashes?

Post by Blai »

Hi,

I have dumped a couple of rare discs and would like to post their hashes but I have absolutely no clue about how to do it.

Can anyone point me out on how to generate hashes for the dumped tracks?

Thank you
User avatar
atreyu187
Posts: 462
Joined: Mon Jul 25, 2011 8:13 pm

Re: How do I generate hashes?

Post by atreyu187 »

CLRMame Pro is what you need to do them all. It is what maddog had me use when I used to have a DC
User avatar
majorpbx
Posts: 327
Joined: Mon Apr 18, 2016 10:15 pm

Re: How do I generate hashes?

Post by majorpbx »

I use PowerShell to generate the hash values. I borrowed some code from the link mentioned below. All you have to do is update the following code section to whatever path your files exist in.

Replace everything between the "" with your path and run the code from PowerShell ISE or save it as a ".ps1" and run let it loose. :)

Code: Select all

$Test  = "C:\DreamCast\Crazy Taxi"
CRC32 code borrowed from greg zakharov at http://poshcode.org/4946

Full code with a bit of error handling thrown in to account for files that are in use by other programs.

Code: Select all

$Test  = "C:\DreamCast\Crazy Taxi"
$Files = (Get-ChildItem $Test -Recurse).fullname

Write-Host $Test

ForEach ($File in $Files) {

Try {
     $New_CRC32 = Get-Crc32 $File
     $New_CRC32 = $New_CRC32 -replace ("0x","")
     $New_CRC32 = $New_CRC32.PadLeft(8,'0')
     $New_CRC32 = $New_CRC32.ToLower()
     }
     Catch {
            $New_CRC32 = "ERROR"
            }


$File_Name   = (Get-Item $File).Name
$File_Size   = (Get-Item $File).Length


Try {
     $File_MD5    = (Get-FileHash $File -Algorithm MD5 -ErrorAction Stop).Hash
     $File_MD5    = $File_MD5.ToLower()
     }
     Catch {
            $File_MD5 = "ERROR"
            }


Try {
     $File_SHA1   = (Get-FileHash $File -Algorithm SHA1 -ErrorAction Stop).Hash
     $File_SHA1   = $File_SHA1.ToLower()
     }
     Catch {
            $File_SHA1 = "ERROR"
            }


Write-Host $File_Name "size" $File_Size "crc" $New_CRC32 "md5" $File_MD5 "sha1" $File_SHA1

}


Set-Alias crc32 Get-Crc32
 
$asm = Add-Type -Mem @'
   [DllImport("ntdll.dll")]
   internal static extern UInt32 RtlComputeCrc32(
       UInt32 InitialCrc,
       Byte[] Buffer,
       Int32 Length
   );
   
   public static String ComputeCrc32(String file) {
     UInt32 crc32 = 0;
     Int32  read;
     Byte[] buf = new Byte[4096];
     
     using (FileStream fs = File.OpenRead(file)) {
       while ((read = fs.Read(buf, 0, buf.Length)) != 0)
         crc32 = RtlComputeCrc32(crc32, buf, read);
     }
           
     return ("0x" + crc32.ToString("X", CultureInfo.CurrentCulture));
   }
'@ -Name Check -NameSpace Crc32 -Using System.IO, System.Globalization -PassThru
 
function Get-Crc32 {
  <#
    .NOTES
        Author: greg zakharov
  #>
  param(
    [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
    [ValidateScript({Test-Path $_})]
    [String]$FileName
  )
 
  $FileName = cvpa $FileName
  $asm::ComputeCrc32($FileName)
}

If the code refuses to run you may have to run the script with one of these commands.

in PowerShell ISE:

Code: Select all

Set-ExecutionPolicy ByPass
or if you are running it from ".ps1" you may want to launch it from CMD prompt with this:

Code: Select all

powershell -ExecutionPolicy ByPass -File script.ps1


P.S. By the way, it's worth mentioning that if you trade the two lines below it perfectly formats it for copy and pasting it to a code call out on this site...

Replace this:

Code: Select all

Write-Host $File_Name "size" $File_Size "crc" $New_CRC32 "md5" $File_MD5 "sha1" $File_SHA1
With this:

Code: Select all

Write-Host $File_Name "[color=red]size" $File_Size "[/color] [color=green]crc" $New_CRC32 "[/color] [color=blue]md5" $File_MD5 "[/color] [color=red]sha1" $File_SHA1 "[/color]"

Enjoy.... :wink:
Blai
Posts: 7
Joined: Fri Nov 20, 2015 6:29 am

Re: How do I generate hashes?

Post by Blai »

Thanks majorpbx
Post Reply