Skip to content

Instantly share code, notes, and snippets.

@stuncloud
Last active October 22, 2018 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuncloud/fe46f58620bae665a5a3defccaa3757f to your computer and use it in GitHub Desktop.
Save stuncloud/fe46f58620bae665a5a3defccaa3757f to your computer and use it in GitHub Desktop.
ファイルのハッシュ値(SHA256、MD5)を取得するモジュールです
call FileHash.uws
path = "C:\path\to\uwscpro5302.exe"
msgbox(FileHash.SHA256(path))
msgbox(FileHash.MD5(path))
module FileHash
function SHA256(path)
fileb = getFileBytes(path)
hashb = getHashBytes(fileb, PROGID_SHA256)
result = getHex(hashb)
fend
function MD5(path)
fileb = getFileBytes(path)
hashb = getHashBytes(fileb, PROGID_MD5)
result = getHex(hashb)
fend
function getFileBytes(path)
with createoleobj("ADODB.Stream")
.Open()
.Type = 1
.LoadFromFile(path)
result = .Read()
.Close()
endwith
fend
function getHashBytes(bytes, progid)
with createoleobj(progid)
.ComputeHash_2(bytes)
result = .Hash
.Clear()
endwith
fend
function getHex(bytes)
with createoleobj("MSXML2.DOMDocument")
with .createElement("tmp")
.dataType = "bin.hex"
.nodeTypedValue = bytes
result = .text
endwith
endwith
fend
const PROGID_SHA256 = "System.Security.Cryptography.SHA256Managed"
const PROGID_MD5 = "System.Security.Cryptography.MD5CryptoServiceProvider"
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment