AFAIK for hex it adds CRLFs and spaces, for base64 it adds CRLFs.
So you might want to do something like this:
Code: Select all
vText := RTrim(vText, " `r`n")
vText := StrReplace(vText, "`r`n")
vText := StrReplace(vText, " ")
;vText .= "`r`n" ;add this line, if a trailing CRLF is wanted
Since the raw hex/base64 flags are not supported on Windows XP.
Either drop the flag, and always do StrReplace.
Or check the OS version number, conditionally set the flag, and do StrReplace if necessary.
E.g. something like:
Code: Select all
JEE_HexGet(vAddr, vSize, vCase:="U")
{
local
static vIsVistaPlus := (DllCall("kernel32\GetVersion", "UInt") & 0xFF) >= 6
vCase := "U"
;CRYPT_STRING_NOCRLF := 0x40000000 (not supported by Windows XP)
;CRYPT_STRING_HEXRAW := 0xC ;to return raw hex but with a trailing enter (not supported by Windows XP)
;CRYPT_STRING_HEX := 0x4 ;to return space/CRLF-separated text
vFlags := vIsVistaPlus ? 0x4000000C : 0x4
vChars := 0
DllCall("crypt32\CryptBinaryToString", "Ptr",vAddr, "UInt",vSize, "UInt",vFlags, "Ptr",0, "UInt*",vChars)
VarSetCapacity(vHex, vChars*2, 0)
DllCall("crypt32\CryptBinaryToString", "Ptr",vAddr, "UInt",vSize, "UInt",vFlags, "Str",vHex, "UInt*",vChars)
if !vIsVistaPlus
{
vHex := StrReplace(vHex, "`r`n")
vHex := StrReplace(vHex, " ")
}
return (vCase = "L") ? vHex : Format("{:U}", vHex)
}
JEE_Base64Get(vAddr, oParams*) ;vAddr, vSize
{
local
static vIsVistaPlus := (DllCall("kernel32\GetVersion", "UInt") & 0xFF) >= 6
if (oParams.Length() = 2)
vSize := oParams.1
if !JEE_StrIsType(oParams.1, "number")
vSize := 0
else if (oParams.1 = 0)
return
else if oParams.HasKey(1)
vSize := oParams.1
else
vSize := 0
if !JEE_StrIsType(vSize, "number")
vSize := 0
;CRYPT_STRING_NOCRLF := 0x40000000
;CRYPT_STRING_BASE64 := 0x1
vChars := 0
vFlags := vIsVistaPlus ? 0x40000001 : 0x1
DllCall("crypt32\CryptBinaryToString", "Ptr",vAddr, "UInt",vSize, "UInt",vFlags, "Ptr",0, "UInt*",vChars)
VarSetCapacity(vBase64, vChars*2, 0)
DllCall("crypt32\CryptBinaryToString", "Ptr",vAddr, "UInt",vSize, "UInt",vFlags, "Str",vBase64, "UInt*",vChars)
return vIsVistaPlus ? vBase64 : StrReplace(vBase64, "`r`n")
}
It would be good if a few of you supported me in getting base64/hex functionality built-in.
Either my code below, or something similar. Cheers.
C++: AHK source code: Base64Get/Base64Put and HexGet/HexPut - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=75&t=64694