Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pause::pause
- MoveWin:
- PostMessage, 0xA1, 2
- return
- decodehash(hash)
- {
- hash:=substr(hash,-4) . substr(hash,5,-8)
- return strrev(hash)
- }
- strrev(Str) {
- DllCall("msvcrt\_" ( A_IsUnicode ? "wcs" : "str" ) "rev", "UInt",&Str, "CDecl")
- return Str
- }
- Text_AES(ByRef sResult, pData, nSize, sPassword, SID = 256, bEncrypt = True)
- {
- VarSetCapacity(sResult, bEncrypt ? nSize+16 : nSize)
- DllCall("RtlMoveMemory", "Uint", &sResult, "Uint", pData, "Uint", nSize)
- nSize := Crypt_AES(&sResult, nSize, sPassword, SID, bEncrypt)
- NumPut(0, sResult, nSize, "char"), VarSetCapacity(sResult,-1)
- Return nSize
- }
- Hex4Bin(p, l)
- {
- VarSetCapacity(h,l*2)
- o:=A_FormatInteger
- SetFormat, Integer, H
- Loop, %l%
- h.=SubStr(*p++,-1)
- SetFormat, Integer, %o%
- StringReplace, h, h, x, 0, All
- Return h
- }
- Ansi2UTF8(sString)
- {
- Ansi2Unicode(sString, wString, 0)
- Unicode2Ansi(wString, zString, 65001)
- Return zString
- }
- UTF82Ansi(zString)
- {
- Ansi2Unicode(zString, wString, 65001)
- Unicode2Ansi(wString, sString, 0)
- Return sString
- }
- Ansi2Unicode(ByRef sString, ByRef wString, CP = 0)
- {
- nSize := DllCall("MultiByteToWideChar"
- , "Uint", CP
- , "Uint", 0
- , "Uint", &sString
- , "int", -1
- , "Uint", 0
- , "int", 0)
- VarSetCapacity(wString, nSize * 2)
- DllCall("MultiByteToWideChar"
- , "Uint", CP
- , "Uint", 0
- , "Uint", &sString
- , "int", -1
- , "Uint", &wString
- , "int", nSize)
- }
- Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
- {
- nSize := DllCall("WideCharToMultiByte"
- , "Uint", CP
- , "Uint", 0
- , "Uint", &wString
- , "int", -1
- , "Uint", 0
- , "int", 0
- , "Uint", 0
- , "Uint", 0)
- VarSetCapacity(sString, nSize)
- DllCall("WideCharToMultiByte"
- , "Uint", CP
- , "Uint", 0
- , "Uint", &wString
- , "int", -1
- , "str", sString
- , "int", nSize
- , "Uint", 0
- , "Uint", 0)
- }
- Bin4Hex(ByRef b, h)
- {
- VarSetCapacity(b,l:=StrLen(h)//2)
- Loop, %l%
- NumPut("0x" . SubStr(h,2*A_Index-1,2),b,A_Index-1,"Uchar")
- NumPut(0,b,l,"Uchar"), VarSetCapacity(b,-1)
- Return l
- }
- Crypt_AES(pData, nSize, sPassword, SID = 256, bEncrypt = True) {
- CALG_AES_256 := 1 + CALG_AES_192 := 1 + CALG_AES_128 := 0x660E
- CALG_SHA1 := 1 + CALG_MD5 := 0x8003
- DllCall("advapi32\CryptAcquireContextA", "UintP", hProv, "Uint", 0, "str"
- , "Microsoft Enhanced RSA and AES Cryptographic Provider" . (A_OSVersion="WIN_XP" ? " (Prototype)" : ""), "Uint", 24, "Uint", 0)
- DllCall("advapi32\CryptCreateHash", "Uint", hProv, "Uint", CALG_SHA1, "Uint", 0, "Uint", 0, "UintP", hHash)
- DllCall("advapi32\CryptHashData", "Uint", hHash, "Uint", &sPassword, "Uint", StrLen(sPassword), "Uint", 0)
- DllCall("advapi32\CryptDeriveKey", "Uint", hProv, "Uint", CALG_AES_%SID%, "Uint", hHash, "Uint", SID<<16, "UintP", hKey)
- DllCall("advapi32\CryptDestroyHash", "Uint", hHash)
- If bEncrypt
- DllCall("advapi32\CryptEncrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize, "Uint", nSize+16)
- Else DllCall("advapi32\CryptDecrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize)
- DllCall("advapi32\CryptDestroyKey", "Uint", hKey)
- DllCall("advapi32\CryptReleaseContext", "Uint", hProv, "Uint", 0)
- Return nSize
- }
- write_bin(byref bin,filename,size){
- filename:=SubStr(filename, 1, 200)
- h := DllCall("CreateFile","str",filename,"Uint",0x40000000
- ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
- IfEqual h,-1, SetEnv, ErrorLevel, -1
- ; IfNotEqual ErrorLevel,0,ExitApp ; couldn't create the file
- r := DllCall("SetFilePointerEx","Uint",h,"Int64",0,"UInt *",p,"Int",0)
- IfEqual r,0, SetEnv, ErrorLevel, -3
- IfNotEqual ErrorLevel,0, {
- t = %ErrorLevel% ; save ErrorLevel to be returned
- DllCall("CloseHandle", "Uint", h)
- ErrorLevel = %t% ; return seek error
- }
- result := DllCall("WriteFile","UInt",h,"Str",bin,"UInt"
- ,size,"UInt *",Written,"UInt",0)
- h := DllCall("CloseHandle", "Uint", h)
- return, 1
- }
- BinaryToString(ByRef bin, sz=-1, fmt=4) { ; return base64 or formatted-hex
- n := sz>0 ? sz : VarSetCapacity(bin)
- DllCall("Crypt32.dll\CryptBinaryToStringA", UInt,&bin, UInt,n, UInt,fmt, UInt,0, UIntP,cp, "CDECL UInt") ; get size
- VarSetCapacity(str,cp)
- DllCall("Crypt32.dll\CryptBinaryToStringA", UInt,&bin, UInt,n, UInt,fmt, UInt,&str, UIntP,cp, "CDECL UInt")
- Return str
- }
- Utf( str ) {
- RawLen := StrLen(str)
- BufSize := (RawLen + 1) * 2
- VarSetCapacity(Buf1, BufSize, 0) ; For UTF-16.
- VarSetCapacity(Buf2, BufSize, 0) ; For UTF-8.
- DllCall("MultiByteToWideChar", "uint", 0, "int", 0, "str", str
- , "int", -1, "uint", &Buf1, "uint", RawLen + 1)
- DllCall("WideCharToMultiByte", "uint", 65001, "int", 0, "uint", &Buf1
- , "int", -1, "str", Buf2, "uint", BufSize
- , "int", 0, "int", 0)
- Return Buf2
- }
- UtfDecode( str ) {
- RawLen := StrLen(str)
- Charset := 0 ; Put 1252 or 0
- BufSize := (RawLen + 1) * 2
- VarSetCapacity(Buf, BufSize, 0)
- DllCall("MultiByteToWideChar", "uint", 65001, "int", 0, "str", str
- , "int", -1, "uint", &Buf, "uint", RawLen + 1)
- DllCall("WideCharToMultiByte", "uint", Charset, "int", 0, "uint", &Buf, "int", -1
- , "str", str, "uint", RawLen + 1
- , "int", 0, "int", 0)
- Return str
- }
- UtfEncode( str ) {
- RawLen := StrLen(str)
- BufSize := (RawLen + 1) * 2
- VarSetCapacity(Buf1, BufSize, 0) ; For UTF-16.
- VarSetCapacity(Buf2, BufSize, 0) ; For UTF-8.
- DllCall("MultiByteToWideChar", "uint", 0, "int", 0, "str", str
- , "int", -1, "uint", &Buf1, "uint", RawLen + 1)
- DllCall("WideCharToMultiByte", "uint", 65001, "int", 0, "uint", &Buf1
- , "int", -1, "str", Buf2, "uint", BufSize
- , "int", 0, "int", 0)
- Return Buf2
- }
- UrlEncode(str)
- { ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release
- b_Format := A_FormatInteger
- data := ""
- SetFormat,Integer,H
- Loop,Parse,str
- if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)<0x30) || (asc(A_LoopField)=0x3d))
- data .= "%" . ((StrLen(c:=SubStr(ASC(A_LoopField),3))<2) ? "0" . c : c)
- Else
- data .= A_LoopField
- SetFormat,Integer,%b_format%
- return data
- }
- UrlDecode(str)
- { ; v 0.1 / (w) 28.06.2008 by derRaphael / zLib-Style release
- Loop,Parse,str,`%
- txt := (A_Index=1) ? A_LoopField : txt chr("0x" substr(A_LoopField,1,2)) SubStr(A_LoopField,3)
- return txt
- }
- httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="")
- { global httpQueryOps, httpAgent, httpProxy, httpProxyByPass, httpQueryReferer, httpQueryAcceptType
- , httpQueryDwFlags
- defaultOps =
- (LTrim Join|
- httpAgent=script|httpProxy=0|httpProxyByPass=0|INTERNET_FLAG_SECURE=0x00800000
- SECURITY_FLAG_IGNORE_UNKNOWN_CA=0x00000100|SECURITY_FLAG_IGNORE_CERT_CN_INVALID=0x00001000
- SECURITY_FLAG_IGNORE_CERT_DATE_INVALID=0x00002000|SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE=0x00000200
- INTERNET_OPEN_TYPE_PROXY=3|INTERNET_OPEN_TYPE_DIRECT=1|INTERNET_SERVICE_HTTP=3
- )
- Loop,Parse,defaultOps,|
- {
- RegExMatch(A_LoopField,"(?P<Option>[^=]+)=(?P<Default>.*)",http)
- if StrLen(%httpOption%)=0
- %httpOption% := httpDefault
- }
- hModule := DllCall("LoadLibrary", "Str", "WinINet.Dll")
- offset_name_length:= "4-lpszScheme-255|16-lpszHostName-1024|28-lpszUserName-1024|"
- . "36-lpszPassword-1024|44-lpszUrlPath-1024|52-lpszExtrainfo-1024"
- VarSetCapacity(URL_COMPONENTS,60,0)
- NumPut(60,URL_COMPONENTS,0), NumPut(255,URL_COMPONENTS,12), NumPut(0xffff,URL_COMPONENTS,24)
- Loop,Parse,offset_name_length,|
- {
- RegExMatch(A_LoopField,"(?P<Offset>\d+)-(?P<Name>[a-zA-Z]+)-(?P<Size>\d+)",iCU_)
- VarSetCapacity(%iCU_Name%,iCU_Size,0)
- NumPut(&%iCU_Name%,URL_COMPONENTS,iCU_Offset)
- NumPut(iCU_Size,URL_COMPONENTS,iCU_Offset+4)
- }
- DllCall("WinINet\InternetCrackUrlA","Str",lpszUrl,"uInt",StrLen(lpszUrl),"uInt",0,"uInt",&URL_COMPONENTS)
- Loop,Parse,offset_name_length,|
- {
- RegExMatch(A_LoopField,"-(?P<Name>[a-zA-Z]+)-",iCU_)
- VarSetCapacity(%iCU_Name%,-1)
- }
- nPort:=NumGet(URL_COMPONENTS,24,"uInt")
- dwFlags := httpQueryDwFlags
- if (lpszScheme = "https")
- dwFlags |= (INTERNET_FLAG_SECURE|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
- |SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)
- if (lpszScheme="unknown") {
- Result := "ERR: No Valid URL supplied."
- Return StrLen(Result)
- }
- hInternet := DllCall("WinINet\InternetOpenA"
- ,"Str",httpAgent,"UInt"
- ,(httpProxy != 0 ? INTERNET_OPEN_TYPE_PROXY : INTERNET_OPEN_TYPE_DIRECT )
- ,"Str",httpProxy,"Str",httpProxyBypass,"Uint",0)
- hConnect := DllCall("WinINet\InternetConnectA"
- ,"uInt",hInternet,"Str",lpszHostname, "Int",nPort
- ,"Str",lpszUserName, "Str",lpszPassword,"uInt",INTERNET_SERVICE_HTTP
- ,"uInt",0,"uInt*",0)
- if (Strlen(POSTDATA)>0) {
- HTTPVerb:="POST"
- if StrLen(Headers)=0
- Headers:="Content-Type: application/x-www-form-urlencoded"
- } else
- HTTPVerb:="GET"
- hRequest := DllCall("WinINet\HttpOpenRequestA"
- ,"uInt",hConnect,"Str",HTTPVerb,"Str",lpszUrlPath . lpszExtrainfo
- ,"Str",ProVer := "HTTP/1.1", "Str",httpQueryReferer,"Str",httpQueryAcceptTypes
- ,"uInt",dwFlags,"uInt",Context:=0 )
- sRequest := DllCall("WinINet\HttpSendRequestA"
- , "uInt",hRequest,"Str",Headers, "uInt",Strlen(Headers)
- , "Str",POSTData,"uInt",Strlen(POSTData))
- VarSetCapacity(header, 2048, 0) ; max 2K header data for httpResponseHeader
- VarSetCapacity(header_len, 4, 0)
- Loop, 5
- if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest
- ,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)
- break
- If (headerRequest=1) {
- VarSetCapacity(res,headerLength:=NumGet(header_len),32)
- DllCall("RtlMoveMemory","uInt",&res,"uInt",&header,"uInt",headerLength)
- Loop,% headerLength
- if (*(&res-1+a_index)=0) ; Change binary zero to linefeed
- NumPut(Asc("`n"),res,a_index-1,"uChar")
- VarSetCapacity(res,-1)
- } else
- res := "timeout"
- Loop,Parse,res,`n,`r
- {
- RetValue := A_LoopField
- break
- }
- If (RetValue="timeout") {
- html := "Error: timeout"
- return -1
- }
- RetValue := RegExReplace(RetValue,"HTTP/1\.[01]\s+")
- HttpRetCodes := "100=Continue|101=Switching Protocols|102=Processing (WebDAV) (RFC 2518)|"
- . "200=OK|201=Created|202=Accepted|203=Non-Authoritative Information|204=No"
- . " Content|205=Reset Content|206=Partial Content|207=Multi-Status (WebDAV)"
- . "|300=Multiple Choices|301=Moved Permanently|302=Found|303=See Other|304="
- . "Not Modified|305=Use Proxy|306=Switch Proxy|307=Temporary Redirect|400=B"
- . "ad Request|401=Unauthorized|402=Payment Required|403=Forbidden|404=Not F"
- . "ound|405=Method Not Allowed|406=Not Acceptable|407=Proxy Authentication "
- . "Required|408=Request Timeout|409=Conflict|410=Gone|411=Length Required|4"
- . "12=Precondition Failed|413=Request Entity Too Large|414=Request-URI Too "
- . "Long|415=Unsupported Media Type|416=Requested Range Not Satisfiable|417="
- . "Expectation Failed|418=I'm a teapot (RFC 2324)|422=Unprocessable Entity "
- . "(WebDAV) (RFC 4918)|423=Locked (WebDAV) (RFC 4918)|424=Failed Dependency"
- . " (WebDAV) (RFC 4918)|425=Unordered Collection (RFC 3648)|426=Upgrade Req"
- . "uired (RFC 2817)|449=Retry With|500=Internal Server Error|501=Not Implem"
- . "ented|502=Bad Gateway|503=Service Unavailable|504=Gateway Timeout|505=HT"
- . "TP Version Not Supported|506=Variant Also Negotiates (RFC 2295)|507=Insu"
- . "fficient Storage (WebDAV) (RFC 4918)|509=Bandwidth Limit Exceeded|510=No"
- . "t Extended (RFC 2774)"
- RetValue := SubStr(RetValue,1,3)
- Loop,Parse,HttpRetCodes,|
- {
- HttpReturnCode := SubStr(A_LoopField,1,3)
- HttpReturnMsg := SubStr(A_LoopField,5)
- if (RetValue=HttpReturnCode) {
- RetMsg := HttpReturnMsg
- break
- }
- }
- if strlen(HTTPQueryOps)>0 {
- if (instr(HTTPQueryOps,"showHeader"))
- MsgBox % res
- if (instr(HTTPQueryOps,"storeHeader"))
- global HttpQueryHeader := res
- if (instr(HTTPQueryOps,"updateSize")) {
- Loop,Parse,res,`n
- If RegExMatch(A_LoopField,"Content-Length:\s+?(?P<Size>\d+)",full) {
- global HttpQueryFullSize := fullSize
- break
- }
- if (fullSize+0=0)
- HttpQueryFullSize := "size unavailable"
- }
- }
- if !(InStr("100 200 201 202 302",RetValue)) {
- Result := RetValue " " RetMsg
- return StrLen(Result)
- }
- VarSetCapacity(BytesRead,4,0)
- fsize := 0
- Loop
- { bc := A_Index
- VarSetCapacity(buffer%bc%,1024,0) ; setup new chunk for this receive round
- ReadFile := DllCall("wininet\InternetReadFile"
- ,"uInt",hRequest,"uInt",&buffer%bc%,"uInt",1024,"uInt",&BytesRead)
- ReadBytes := NumGet(BytesRead)
- If ((ReadFile!=0)&&(!ReadBytes))
- break
- Else {
- fsize += ReadBytes
- sizeArray .= ReadBytes "|"
- }
- if (instr(HTTPQueryOps,"updateSize"))
- Global HttpQueryCurrentSize := fsize
- }
- sizeArray := SubStr(sizeArray,1,-1)
- VarSetCapacity(result,fSize+1,0)
- Dest := &result
- Loop,Parse,SizeArray,|
- DllCall("RtlMoveMemory","uInt",Dest,"uInt",&buffer%A_Index%,"uInt",A_LoopField)
- , Dest += A_LoopField
- DllCall("WinINet\InternetCloseHandle", "uInt", hRequest)
- DllCall("WinINet\InternetCloseHandle", "uInt", hInternet)
- DllCall("WinINet\InternetCloseHandle", "uInt", hConnect)
- DllCall("FreeLibrary", "UInt", hModule)
- return fSize
- }
- MD5( ByRef V, L=0 ) { ; www.autohotkey.com/forum/viewtopic.php?p=275910#275910
- VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX )
- DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,V, UInt,L ? L : VarSetCapacity(V) )
- DllCall( "advapi32\MD5Final", Str,MD5_CTX )
- Loop % StrLen( Hex:="123456789ABCDEF0" )
- N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
- Return MD5
- }
Advertisement
Add Comment
Please, Sign In to add comment