Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 20, 2023
1 parent 39669b7 commit 2054def
Showing 1 changed file with 31 additions and 90 deletions.
121 changes: 31 additions & 90 deletions ahk/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5791,66 +5791,8 @@
Critical "Off"
}
; LC_* functions are substantially from Libcrypt
; Modified from https://github.com/ahkscript/libcrypt.ahk
; Ref: https://www.autohotkey.com/boards/viewtopic.php?t=112821
; Original License:
; The MIT License (MIT)
;
; Copyright (c) 2014 The ahkscript community (ahkscript.org)
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
LC_Base64_Encode_Text(Text_, Encoding_ := "UTF-8")
{
Bin_ := Buffer(StrPut(Text_, Encoding_))
LC_Base64_Encode(&Base64_, &Bin_, StrPut(Text_, Bin_, Encoding_) - 1)
return Base64_
}
LC_Base64_Decode_Text(Text_, Encoding_ := "UTF-8")
{
Len_ := LC_Base64_Decode(&Bin_, &Text_)
return StrGet(StrPtr(Bin_), Len_, Encoding_)
}
LC_Base64_Encode(&Out_, &In_, In_Len)
{
return LC_Bin2Str(&Out_, &In_, In_Len, 0x40000001)
}
LC_Base64_Decode(&Out_, &In_)
{
return LC_Str2Bin(&Out_, &In_, 0x1)
}
LC_Bin2Str(&Out_, &In_, In_Len, Flags_)
{
DllCall("Crypt32.dll\CryptBinaryToString", "Ptr", In_, "UInt", In_Len, "UInt", Flags_, "Ptr", 0, "UInt*", &Out_Len := 0)
VarSetStrCapacity(&Out_, Out_Len * 2)
DllCall("Crypt32.dll\CryptBinaryToString", "Ptr", In_, "UInt", In_Len, "UInt", Flags_, "Str", Out_, "UInt*", &Out_Len)
return Out_Len
}
LC_Str2Bin(&Out_, &In_, Flags_)
{
DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", StrPtr(In_), "UInt", StrLen(In_), "UInt", Flags_, "Ptr", 0, "UInt*", &Out_Len := 0, "Ptr", 0, "Ptr", 0)
VarSetStrCapacity(&Out_, Out_Len)
DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", StrPtr(In_), "UInt", StrLen(In_), "UInt", Flags_, "Str", Out_, "UInt*", &Out_Len, "Ptr", 0, "Ptr", 0)
return Out_Len
}
; End of libcrypt code
b64decode(pszString) {
b64decode(&pszString) {
; TODO load DLL globally for performance
; REF: https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptstringtobinaryw
; [in] LPCSTR pszString, A pointer to a string that contains the formatted string to be converted.
Expand All @@ -5860,40 +5802,39 @@
; [in, out] DWORD *pcbBinary, A pointer to a DWORD variable that, on entry, contains the size, in bytes, of the pbBinary buffer. After the function returns, this variable contains the number of bytes copied to the buffer. If this value is not large enough to contain all of the data, the function fails and GetLastError returns ERROR_MORE_DATA.
; [out] DWORD *pdwSkip, A pointer to a DWORD value that receives the number of characters skipped to reach the beginning of the -----BEGIN ...----- header. If no header is present, then the DWORD is set to zero. This parameter is optional and can be NULL if it is not needed.
; [out] DWORD *pdwFlags A pointer to a DWORD value that receives the flags actually used in the conversion. These are the same flags used for the dwFlags parameter. In many cases, these will be the same flags that were passed in the dwFlags parameter. If dwFlags contains one of the following flags, this value will receive a flag that indicates the actual format of the string. This parameter is optional and can be NULL if it is not needed.
return LC_Base64_Decode_Text(pszString)
; if (pszString = "") {
; return ""
; }
;
; cchString := StrLen(pszString)
;
; dwFlags := 0x00000001 ; CRYPT_STRING_BASE64: Base64, without headers.
; getsize := 0 ; When this is NULL, the function returns the required size in bytes (for our first call, which is needed for our subsequent call)
if (pszString = "") {
return ""
}
cchString := StrLen(pszString)
dwFlags := 0x00000001 ; CRYPT_STRING_BASE64: Base64, without headers.
getsize := 0 ; When this is NULL, the function returns the required size in bytes (for our first call, which is needed for our subsequent call)
; buff_size := 0 ; The function will write to this variable on our first call
; pdwSkip := 0 ; We don't use any headers or preamble, so this is zero
; pdwFlags := 0 ; We don't need this, so make it null
;
; ; The first call calculates the required size. The result is written to pbBinary
; success := DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", StrPtr(pszString), "UInt", cchString, "UInt", dwFlags, "UInt", getsize, "UIntP", buff_size, "Int", pdwSkip, "Int", pdwFlags )
; if (success = 0) {
; return ""
; }
;
; ; We're going to give a pointer to a variable to the next call, but first we want to make the buffer the correct size using VarSetCapacity using the previous return value
; ret := Buffer(buff_size, 0)
;; granted := VarSetStrCapacity(&ret, buff_size)
;
; ; Now that we know the buffer size we need and have the variable's capacity set to the proper size, we'll pass a pointer to the variable for the decoded value to be written to
;
; success := DllCall( "Crypt32.dll\CryptStringToBinary", "Ptr", StrPtr(pszString), "UInt", cchString, "UInt", dwFlags, "Ptr", ret, "UIntP", buff_size, "Int", pdwSkip, "Int", pdwFlags )
; if (success=0) {
; return ""
; }
;
; return StrGet(ret, "UTF-8")
pdwSkip := 0 ; We don't use any headers or preamble, so this is zero
pdwFlags := 0 ; We don't need this, so make it null
; The first call calculates the required size. The result is written to pbBinary
success := DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", StrPtr(pszString), "UInt", cchString, "UInt", dwFlags, "UInt", getsize, "UIntP", &buff_size := 0, "Int", pdwSkip, "Int", pdwFlags )
if (success = 0) {
return ""
}
; We're going to give a pointer to a variable to the next call, but first we want to make the buffer the correct size using VarSetCapacity using the previous return value
ret := Buffer(buff_size)
; Now that we know the buffer size we need and have the variable's capacity set to the proper size, we'll pass a pointer to the variable for the decoded value to be written to
success := DllCall( "Crypt32.dll\CryptStringToBinary", "Ptr", StrPtr(pszString), "UInt", cchString, "UInt", dwFlags, "Ptr", ret.Ptr, "UIntP", &buff_size, "Int", pdwSkip, "Int", pdwFlags )
if (success=0) {
return ""
}
return StrGet(ret, "UTF-8")
}
{% for hotkey in hotkeys %}
{{ hotkey.keyname }}::
Expand All @@ -5908,7 +5849,7 @@
:{{ hotstring.options }}:{{ hotstring.trigger }}::
hostring_{{ hotstring._id }}_func(hs) {
replacement_b64 := "{{ hotstring._replacement_as_b64 }}"
replacement := b64decode(replacement_b64)
replacement := b64decode(&replacement_b64)
Send(replacement)
}
{% else %}
Expand Down

0 comments on commit 2054def

Please sign in to comment.