Simple MD5 / SH1 Check

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Simple MD5 / SH1 Check

Post by Phil Pendlebury » Wed Mar 21, 2012 2:41 pm

Demonstrates a few dialog features and some other relatively interesting stuff.

The "HashLib.dll" file must be on the script directory. This can be downloaded here: http://www.mjtnet.com/downloads.htm

Code: Select all

//Let>IGNORESPACES=1
//Put Hashlib.dll in script directory
Let>HashLib=%SCRIPT_DIR%\HashLib.dll
Let>Mode=MD5
Let>APP_TITLE=Simple MD5/SHA1

Dialog>Dialog1
object Dialog1: TForm
  Left = 819
  Top = 489
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'Simple MD5/SHA1'
  ClientHeight = 181
  ClientWidth = 425
  Color = clBtnFace
  DefaultMonitor = dmPrimary
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label4: TLabel
    Left = 10
    Top = 112
    Width = 7
    Height = 24
    Color = clRed
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clMaroon
    Font.Height = -19
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentColor = False
    ParentFont = False
  end
  object Label14: TLabel
    Left = 10
    Top = 112
    Width = 7
    Height = 24
    Color = clRed
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clGreen
    Font.Height = -19
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentColor = False
    ParentFont = False
  end
  object Label5: TLabel
    Left = 232
    Top = 8
    Width = 180
    Height = 13
    Caption = 'Simple MD5/SHA1 by Phil Pendlebury'
  end
  object Label1: TLabel
    Left = 10
    Top = 32
    Width = 5
    Height = 13
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlue
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label2: TLabel
    Left = 10
    Top = 8
    Width = 66
    Height = 13
    Caption = 'Mode: MD5'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlue
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 8
    Top = 52
    Width = 328
    Height = 21
    TabOrder = 1
    Text = 'Browse for file to generate MD5'
  end
  object Edit2: TEdit
    Left = 8
    Top = 81
    Width = 328
    Height = 21
    TabOrder = 2
    Text = 'MD5 of file - Hit Write to send MD5 to txt file'
  end
  object Edit3: TEdit
    Left = 8
    Top = 145
    Width = 328
    Height = 21
    TabOrder = 3
    Text = 'Paste MD5 here - Hit Compare to verify matching MD5'
  end
  object MSButton1: tMSButton
    Left = 344
    Top = 50
    Width = 73
    Height = 24
    Hint = 'Browse for file and Generate MD5/SHA1'
    Caption = 'Browse'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 344
    Top = 143
    Width = 73
    Height = 24
    Hint = 'Compare File MD5/SHA1 and Pasted MD5/SHA1'
    Caption = 'Compare'
    Enabled = False
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 344
    Top = 79
    Width = 73
    Height = 24
    Hint = 'Write MD5/SHA1 of selected file to txt file'
    Caption = 'Write'
    Enabled = False
    TabOrder = 5
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MainMenu: tMSMainMenu
    object MenuItem1: tMSMenuItem
      Caption = '&Menu'
      object MenuItem2: tMSMenuItem
        Caption = 'Help'
      end
      object MenuItem3: tMSMenuItem
        Caption = 'About'
      end
      object MenuItem4: tMSMenuItem
        Caption = 'MEAP'
      end
    end
    object MenuItem5: tMSMenuItem
      Caption = 'Mo&de'
      object MenuItem6: tMSMenuItem
        Caption = '&MD5'
        Checked = True
      end
      object MenuItem7: tMSMenuItem
        Caption = '&SHA1'
      end
    end
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Left = 845
  Top = 532
  HelpContext = 5000
  BorderIcons = []
  BorderStyle = bsNone
  Caption = 'MD5 Generating'
  ClientHeight = 62
  ClientWidth = 261
  Color = clBtnFace
  DefaultMonitor = dmPrimary
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 24
    Width = 209
    Height = 16
    Caption = 'Generating MD5 - Please Wait'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clMaroon
    Font.Height = -13
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
end
EndDialog>Dialog2

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,CHECK
AddDialogHandler>Dialog1,MSButton3,OnClick,WRITE
AddDialogHandler>Dialog1,,OnClose,BYE
AddDialogHandler>Dialog1,Edit3,OnChange,TEST
//
AddDialogHandler>Dialog1,MenuItem6,OnClick,SETMD5
AddDialogHandler>Dialog1,MenuItem7,OnClick,SETSHA
//
AddDialogHandler>Dialog1,MenuItem2,OnClick,HELP
AddDialogHandler>Dialog1,MenuItem3,OnClick,ABOUT
AddDialogHandler>Dialog1,MenuItem4,OnClick,MEAP

Show>Dialog1,res

SRT>ABOUT
  Let>MSG_Width=300
  Let>MSG_Height=200
  MDL>Simple MD5/SHA1 v1.11 by Phil Pendlebury%CRLF%%CRLF%http://www.pendlebury.biz
END>ABOUT

SRT>HELP
  Let>MSG_Width=700
  Let>MSG_Height=450
  MDL>Use MD5 or SHA1 Hashes to verify the integrity of a file%CRLF%%CRLF%To switch between MD5 or SHA1 use the dropdown Mode Menu%CRLF%%CRLF%By comparing the MD5 or SHA1 value (hash or checksum) supplied with a downloaded file to the MD5 or SHA1 value generated by this tool, you can verify the integrity of your file%CRLF%%CRLF%*IF YOU ARE VERIFYING A FILE*%CRLF%%CRLF%Select the file to automatically generate an MD5 or SHA1 value%CRLF%The MD5 or SHA1 value will be displayed - (you can also write the MD5 or SHA1 value to a text file)%CRLF%%CRLF%Paste the MD5 or SHA1 you received with the file into the bottom area%CRLF%Hit the button COMPARE to check if the MD5 or SHA1 values match%CRLF%%CRLF%If they match - The file is exactly as it was originally%CRLF%If they do not match - There is something wrong%CRLF%%CRLF%*IF YOU ARE DISTRIBUTING A FILE*%CRLF%%CRLF%First generate an MD5 or SHA1 value with this tool - Write it to a text file using the WRITE button%CRLF%Send the text file that contains the MD5 or SHA1 Hash along with the file itself so that others can verify the integrity
END>HELP

SRT>MEAP
  ExecuteFile>http://www.meap.biz
END>MEAP

SRt>DoBrowse
 SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
 GetDialogProperty>Dialog1,MSButton1,Filename,str_Filename
 IF>str_Filename=
   GOTO>SkipIt
 ELSE
   SetDialogProperty>Dialog1,Edit1,Text,str_Filename
   //
   Show>Dialog2
   //
   IF>Mode=MD5
     LibFunc>Hashlib,FileMD5,r,%str_Filename%,buf
     Mid>r_2,1,r,hash
   ENDIF
   IF>Mode=SHA1
     LibFunc>Hashlib,FileSHA1,r,%str_Filename%,buf
     Mid>r_2,1,r,hash
   ENDIF
   //
   CloseDialog>Dialog2
   //
   Let>hash={Lower(%hash%)}
   SetDialogProperty>Dialog1,Edit2,Text,%hash%
   GOSUB>GetPathnFile
   SetDialogProperty>Dialog1,Label1,Caption,Generated %Mode%: %file_name_only%
   SetDialogProperty>Dialog1,MSButton3,Enabled,True
 ENDIF
 Label>SkipIt
END>DoBrowse

SRT>TEST
  GetDialogProperty>Dialog1,Edit3,Text,MD5Paste
  IF>%MD5Paste%=Paste %Mode% here - Hit Compare to verify matching %Mode%
    SetDialogProperty>Dialog1,MSButton2,Enabled,False
  ELSE
    Let>MD5Paste={Lower(%MD5Paste%)}
    SetDialogProperty>Dialog1,Edit3,Text,MD5Paste
    SetDialogProperty>Dialog1,MSButton2,Enabled,True
  ENDIF
END>TEST

SRT>CHECK
  GetDialogProperty>Dialog1,Edit2,Text,MD5Gen
   IF>%MD5Gen%=%MD5Paste%
    SetDialogProperty>Dialog1,Label4,Caption,
    SetDialogProperty>Dialog1,Label14,Caption,%Mode% Compare = Match!
  ELSE
    SetDialogProperty>Dialog1,Label14,Caption,
    SetDialogProperty>Dialog1,Label4,Caption,%Mode% Compare = No Match!
  ENDIF
END>CHECK

SRT>WRITE
  Let>MSG_Width=380
  Let>MSG_Height=240
  GetDialogProperty>Dialog1,Edit2,Text,MD5Line
  WriteLn>%path_only%%file_noext%_%Mode%.txt,Blah,%file_name_only% %Mode% - Generated by Simple MD5/SHA1%CRLF%
  WriteLn>%path_only%%file_noext%_%Mode%.txt,Blah,***** BEGIN %Mode% *****
  WriteLn>%path_only%%file_noext%_%Mode%.txt,Blah,%MD5Line%
  WriteLn>%path_only%%file_noext%_%Mode%.txt,Blah,***** END %Mode% *****%CRLF%
  MDL>%Mode% Value for:%CRLF%%CRLF%%file_name_only%%CRLF%%CRLF%Written to file:%CRLF%%CRLF%%path_only%%file_noext%_%Mode%.txt
END>WRITE

SRT>GetPathnFile
  Separate>%str_Filename%,\,file_bits
  Let>file_end=file_bits_Count
  Let>file_name_only=file_bits_%file_end%
  StringReplace>%str_Filename%,%file_name_only%,,path_only
  //
  Separate>%file_name_only%,.,name_bits
  Let>file_ext=name_bits_2
  StringReplace>%file_name_only%,.%file_ext%,,file_noext
END>GetPathnFile

SRT>SETMD5
  Let>Mode=MD5
  SetDialogProperty>Dialog1,MenuItem6,Checked,True
  SetDialogProperty>Dialog1,MenuItem7,Checked,False
  GOSUB>MODESETD
END>SETMD5

SRT>SETSHA
  Let>Mode=SHA1
  SetDialogProperty>Dialog1,MenuItem7,Checked,True
  SetDialogProperty>Dialog1,MenuItem6,Checked,False
  GOSUB>MODESETD
END>SETSHA

SRT>MODESETD
  SetDialogProperty>Dialog2,Label1,Caption,Generating %Mode% - Please Wait
  //
  SetDialogProperty>Dialog1,Edit1,Text,Browse for file to generate %Mode%
  SetDialogProperty>Dialog1,Edit2,Text,%Mode% of file - Hit Write to send %Mode% to txt file
  SetDialogProperty>Dialog1,Edit3,Text,Paste %Mode% here - Hit Compare to verify matching %Mode%
  //
  SetDialogProperty>Dialog1,Label2,Caption,Mode: %Mode%
  SetDialogProperty>Dialog1,MSButton3,Enabled,False
  SetDialogProperty>Dialog1,Label14,Caption,
  SetDialogProperty>Dialog1,Label4,Caption,
END>MODESETD

SRT>BYE
  Exit>0
END>BYE
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Sat Mar 24, 2012 2:47 pm

Added conversion of all hashes to lower case so that upper case and lower case values will always be matched. Also added few other small fixes and messages.
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts