#Requires AutoHotkey v2.0
; 16进制转换的例子【额外添加的】
MsgBox StrGet(CryptStringToBinary("3130", 4), "cp0")  ; --> 10

bin := FileRead(A_ScriptFullPath, "raw")
str := CryptBinaryToString(bin, 0x00000004 | 0x40000000)
MsgBox str
str := RegExReplace(str, "61 61 61 61 61", "62 62 62 62 62")
bin := CryptStringToBinary(str, 4)
FileAppend(bin, "out.ah2", "raw")
; aaaaa


; https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptstringtobinaryw
CryptStringToBinary(str, flag){  ; By Tebayaki
  DllCall("crypt32\CryptStringToBinaryW", "str", str, "uint", StrLen(str), "uint", flag, "ptr", 0, "uint*", &bytes := 0, "ptr", 0, "ptr", 0)
  DllCall("crypt32\CryptStringToBinaryW", "str", str, "uint", StrLen(str), "uint", flag, "ptr", bin := Buffer(bytes), "uint*", bytes, "ptr", 0, "ptr", 0)
  return bin
}
; https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptbinarytostringw
CryptBinaryToString(bin, flag){
  DllCall("crypt32\CryptBinaryToStringW", "ptr", bin, "uint", bin.Size, "uint", flag, "ptr", 0, "uint*", &cnt := 0)
  DllCall("crypt32\CryptBinaryToStringW", "ptr", bin, "uint", bin.Size, "uint", flag, "ptr", str := Buffer(cnt * 2), "uint*", cnt)
  return StrGet(str)
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。