0

Hi I'm trying to replicate this code in Python for NSIS installer.

m = hashlib.md5("C:\PROGRAM FILES\My Program".encode('utf-16LE'))

It basically encode the string , then apply MD5 hash to it. I have found the MD5 hash plug-in for NSIS. However, I still can't figure out how to convert the string in $0 to a utf-16LE format.

Thank you

Kevin
  • 21
  • 1
  • 3

1 Answers1

0

If you are building a Unicode installer you can use the Crypto plug-in and feed it the string directly:

Unicode True
...
Section
Crypto::HashUTF16LE MD5 "The quick brown fox jumps over the lazy dog"
Pop $0
DetailPrint $0 ; B0986AE6EE1EEFEE8A4A399090126837
SectionEnd

ANSI installers have to write the content to a file and hash the file:

Section
InitPluginsDir
StrCpy $1 "The quick brown fox jumps over the lazy dog"
StrLen $3 $1
IntOp $3 $3 * 2 ; UTF-16 is 2 bytes per code-unit
FileOpen $2 "$PluginsDir\Temp.txt" w
System::Call 'KERNEL32::WriteFile(pr2,wr1,ir3,*i,p0)' ; This converts the string for us
FileClose $2
Crypto::HashFile MD5 "$PluginsDir\Temp.txt"
Pop $0
DetailPrint $0
SectionEnd
Anders
  • 97,548
  • 12
  • 110
  • 164