Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- str := "Hello, world!"
- base64_encode(str)
- base64_encode(strIn) {
- Static dwFlags := 0x1 ; Base64 without headers
- szStrIn := StrPut(strIn) ; Get size of string
- bufStrIn := Buffer(szStrIn) ; Create a buffer for string
- StrPut(strIn, bufStrIn) ; put string into buffer
- ; Showing that the buffer exists along with pointer and size
- MsgBox "szStrIn: " szStrIn "`nbufStrIn.Ptr: " bufStrIn.Ptr "`nbufStrIn.Size: " bufStrIn.Size
- bufSzStrOut := Buffer(4, 0) ; Create buffer for return string size
- ; Fat arrow function b/c only the last 2 options are changed
- cryptBin2Str(pszString, pcchString) =>
- DllCall("crypt32\CryptBinaryToString" ; https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptbinarytostringw
- ,"Ptr" , bufStrIn.Ptr ; [in] const BYTE *pbBinary,
- ,"UInt" , bufStrIn.Size ; [in] DWORD cbBinary,
- ,"UInt" , dwFlags ; [in] DWORD dwFlags,
- ,"Ptr" , pszString ; [out, optional] LPWSTR pszString,
- ,"UInt*" , pcchString) ; [in, out] DWORD *pcchString
- ; Run bin2str
- ; pszString is null because I need to get return string length
- ; bufSzStrOut receives the calculated length of return string (in TCHARs)
- if !cryptBin2Str(0, bufSzStrOut.Ptr)
- MsgBox "CryptBinaryToString failed"
- ; Get return string length from buffer
- bSize := NumGet(bufSzStrOut.Ptr, 0, "Uint")
- ; I can't even get to here without screwing things up
- ; No error is thrown by the DLL call but bSize is 0
- ; I fcking quit at this. I've wasted hours so far and the only thing I've
- ; succeeded at is failing in accomplishing anything
- MsgBox(bSize)
- ; The rest of the code that I ~WOULD~ have tried if I could actually get the most basic
- ; of DllCalls to work
- ; But I can't because apparently, I ate a bunch of lead paint chips when I was younger
- ; and it has permanently damaged what little bit of smooth brain I actually have
- ; Create a buffer for the return string
- ; Set string size using bSize
- bufStrOut := Buffer(bSize)
- ; Run bin2str again
- ; Pass pointer to string buffer in as well as pointer to size of buffer
- if !cryptBin2Str(bufStrOut.Ptr, bufSzStrOut.Ptr)
- MsgBox "CryptBinaryToString failed"
- ; This should show the base64 encoded string
- MsgBox(StrGet(bufStrOut,,"UTF-8"))
- return
- }
Add Comment
Please, Sign In to add comment