msgbox

qweqwe

Apr 19th, 2011
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. #Persistent
  3. #NoTrayIcon
  4. #SingleInstance force
  5. SetBatchLines, -1
  6.  
  7.  
  8. AhkDllObject(dll="threads.dll",obj=0){
  9.     static
  10.     IfNotExist, % dll
  11.     {
  12.     msgbox, 16, threads.dll, File doesn't exist!
  13.     ExitApp
  14.     }
  15.     static functions ="
  16. (Join
  17. ahkKey:s|ahkFunction:s=sssssssssss|ahkPostFunction:s=sssssssssss|
  18. ahkdll:ui=sss|ahktextdll:ui=sss|ahkReady:|ahkReload:ui=|
  19. ahkTerminate:i|addFile:ui=sucuc|addScript:ui=sucuc|ahkExec:ui=s|
  20. ahkassign:ui=ss|ahkExecuteLine:ui=uiuiui|ahkFindFunc:ui=s|
  21. ahkFindLabel:ui=s|ahkgetvar:s=sui|ahkLabel:ui=sui|ahkPause:s
  22. )"
  23.     If !(dll){
  24.         Loop % i
  25.         {
  26.             idx:=A_Index
  27.             Loop,Parse,functions,|
  28.             DynaCall(dll%idx% . "\" . A_LoopField)
  29.             DllCall(dll%A_Index% . "\ahkTerminate")
  30.             DllCall("FreeLibrary","UInt",dllmodule%A_Index%)
  31.             obj%A_Index%=
  32.             dll%A_Index%=
  33.             dllmodule%A_Index%=
  34.         }
  35.         i=0
  36.         return
  37.     } else {
  38.     Loop % i
  39.       If (dll=dll%A_Index%)
  40.         return obj%A_Index%
  41.   }
  42.     i++
  43.     dllmodule%i%:=DllCall("LoadLibrary","str",dll)
  44.   if IsObject(obj)
  45.     object:=obj
  46.     else
  47.     object := Object()
  48.     Loop,Parse,functions,|
  49.     {
  50.         object[f:=SubStr(A_LoopField,1,InStr(A_LoopField,":")-1)] := DynaCall(dll "\" f,SubStr(A_LoopField,InStr(A_LoopField,":")+1))
  51.     }
  52.     obj%i%:=object
  53.     dll%i%:=dll
  54.     return obj%i%
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.     Gui  +ToolWindow
  64.     Gui, Add, Edit, x10 y10 w215 vpassword, Input password here `;)
  65.     Gui, Add, Button, x10 y35 w215 gsend_request, Send request
  66.     Gui, Show, w235 h65, Encrypt test
  67.     return
  68.  
  69. send_request:
  70.     GuiControlGet, Password,, password
  71.     URL := "http://msgbox.vkdel.ru/encrypt_data/encrypted.txt"
  72.     httpQuery(Buffer:="", URL)
  73.     varSetCapacity(Buffer, -1)
  74.     Len := StrLen(Buffer)
  75.     size := Crypt_AES(&Buffer, Len, Password, 256, 0)
  76.     Code:=SubStr(Buffer,1,size)
  77.     thread:=AhkdllObject()
  78.     thread.ahktextdll(Code)
  79.     return
  80. return
  81.  
  82.  
  83.  
  84.  
  85.  
  86. Crypt_AES(pData, nSize, sPassword, SID = 256, bEncrypt = True) {
  87.    CALG_AES_256 := 1 + CALG_AES_192 := 1 + CALG_AES_128 := 0x660E
  88.    CALG_SHA1 := 1 + CALG_MD5 := 0x8003
  89.    DllCall("advapi32\CryptAcquireContextA", "UintP", hProv, "Uint", 0, "str"
  90.    , "Microsoft Enhanced RSA and AES Cryptographic Provider" . (A_OSVersion="WIN_XP" ? " (Prototype)" : ""), "Uint", 24, "Uint", 0)
  91.    DllCall("advapi32\CryptCreateHash", "Uint", hProv, "Uint", CALG_SHA1, "Uint", 0, "Uint", 0, "UintP", hHash)
  92.    DllCall("advapi32\CryptHashData", "Uint", hHash, "Uint", &sPassword, "Uint", StrLen(sPassword), "Uint", 0)
  93.    DllCall("advapi32\CryptDeriveKey", "Uint", hProv, "Uint", CALG_AES_%SID%, "Uint", hHash, "Uint", SID<<16, "UintP", hKey)
  94.    DllCall("advapi32\CryptDestroyHash", "Uint", hHash)
  95.    If bEncrypt
  96.       DllCall("advapi32\CryptEncrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize, "Uint", nSize+16)
  97.    Else  DllCall("advapi32\CryptDecrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize)
  98.    DllCall("advapi32\CryptDestroyKey", "Uint", hKey)
  99.    DllCall("advapi32\CryptReleaseContext", "Uint", hProv, "Uint", 0)
  100.    Return   nSize
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. Utf( str ) {
  109.   RawLen := StrLen(str)
  110.  
  111.   BufSize := (RawLen + 1) * 2
  112.   VarSetCapacity(Buf1, BufSize, 0)    ; For UTF-16.
  113.   VarSetCapacity(Buf2, BufSize, 0)    ; For UTF-8.
  114.  
  115.   DllCall("MultiByteToWideChar", "uint", 0, "int", 0, "str", str
  116.                                , "int", -1, "uint", &Buf1, "uint", RawLen + 1)
  117.   DllCall("WideCharToMultiByte", "uint", 65001, "int", 0, "uint", &Buf1
  118.                                , "int", -1, "str", Buf2, "uint", BufSize
  119.                                , "int", 0, "int", 0)
  120.   Return Buf2
  121. }
  122.  
  123. UtfDecode( str ) {
  124.   RawLen := StrLen(str)
  125.  
  126.   Charset := 0    ; Put 1252 or 0
  127.  
  128.   BufSize := (RawLen + 1) * 2
  129.   VarSetCapacity(Buf, BufSize, 0)
  130.  
  131.   DllCall("MultiByteToWideChar", "uint", 65001, "int", 0, "str", str
  132.                                , "int", -1, "uint", &Buf, "uint", RawLen + 1)
  133.   DllCall("WideCharToMultiByte", "uint", Charset, "int", 0, "uint", &Buf, "int", -1
  134.                                , "str", str, "uint", RawLen + 1
  135.                                , "int", 0, "int", 0)
  136.   Return str
  137. }
  138.  
  139. UtfEncode( str ) {
  140.   RawLen := StrLen(str)
  141.  
  142.   BufSize := (RawLen + 1) * 2
  143.   VarSetCapacity(Buf1, BufSize, 0)    ; For UTF-16.
  144.   VarSetCapacity(Buf2, BufSize, 0)    ; For UTF-8.
  145.  
  146.   DllCall("MultiByteToWideChar", "uint", 0, "int", 0, "str", str
  147.                                , "int", -1, "uint", &Buf1, "uint", RawLen + 1)
  148.   DllCall("WideCharToMultiByte", "uint", 65001, "int", 0, "uint", &Buf1
  149.                                , "int", -1, "str", Buf2, "uint", BufSize
  150.                                , "int", 0, "int", 0)
  151.   Return Buf2
  152. }
  153.  
  154. Generate_POST_Body(fields, ByRef postbody, ByRef headers){
  155.    
  156.    ; generate boundary
  157.    static chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  158.    boundary = --
  159.    Loop, 8 {
  160.       Random, RChar, 1, % StrLen(chars)
  161.       boundary .= SubStr(chars, RChar, 1)
  162.    }
  163.  
  164.    ; generate postbody
  165.    #LTrim
  166.    postbody =
  167.    Loop, Parse, fields, `n, `r%A_Space%%A_Tab%
  168.    {
  169.       if RegExMatch(A_LoopField, "i)(?<name>.+?)=(?<isFile>@)?(?<val>.+)", field_)
  170.       {
  171.          postbody = %postbody%
  172.             (Join`r`n
  173.                --%boundary%
  174.                Content-Disposition: form-data; name="%field_name%"
  175.             )
  176.          if field_isFile and FileExist(field_val)
  177.          {
  178.             FileRead, file, %field_val%
  179.                fileType := MimeType(file)
  180.             SplitPath, field_val, filename
  181.             FileGetSize, fileSize, %field_val%
  182.             VarSetCapacity(placeholder, fileSize, 32)
  183.  
  184.             postbody = %postbody%; filename="%filename%"
  185.                (Join`r`n
  186.                  
  187.                   Content-Type: %fileType%
  188.                   Content-Transfer-Encoding: Binary
  189.                )
  190.             field_val := placeholder
  191.          }
  192.          postbody .= "`r`n`r`n" . field_val . "`r`n"
  193.       }
  194.    }
  195.    postbody .= "--" boundary "--`r`n"
  196.    #LTrim Off
  197.    
  198.    ; generate headers
  199.    headers .= (StrLen(headers) ? "`r`n" : "")
  200.       . "Content-type: multipart/form-data; boundary=" boundary "`r`n"
  201.       . "Content-Length: " strlen(postbody)
  202.  
  203.    if field_isFile
  204.       DllCall("RtlMoveMemory"
  205.       , "uInt", (offset:=&postbody+strlen(postbody)-strlen(boundary)-fileSize-8)
  206.       , "uInt", &file
  207.       , "uInt", filesize)
  208.    return boundary
  209. }
  210.  
  211. MimeType(ByRef Binary) {
  212.    MimeTypes:="424d image/bmp|4749463 image/gif|ffd8ffe image/jpeg|89504e4 image/png|4657530"
  213.           . " application/x-shockwave-flash|49492a0 image/tiff"
  214.    @:="0123456789abcdef"
  215.    Loop,8
  216.       hex .= substr(@,(*(a:=&Binary-1+a_index)>>4)+1,1) substr(@,((*a)&15)+1,1)
  217.    Loop,Parse,MimeTypes,|
  218.       if ((substr(hex,1,strlen(n:=RegExReplace(A_Loopfield,"\s.*"))))=n)
  219.          Mime := RegExReplace(A_LoopField,".*?\s")
  220.    Return (Mime!="") ? Mime : "application/octet-stream"
  221. }
  222.  
  223. UrlEncode(str)
  224. { ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release
  225.    b_Format := A_FormatInteger
  226.    data := ""
  227.    SetFormat,Integer,H
  228.    Loop,Parse,str
  229.       if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)<0x30) || (asc(A_LoopField)=0x3d))
  230.          data .= "%" . ((StrLen(c:=SubStr(ASC(A_LoopField),3))<2) ? "0" . c : c)
  231.       Else
  232.          data .= A_LoopField
  233.    SetFormat,Integer,%b_format%
  234.    return data
  235. }
  236.  
  237. UrlDecode(str)
  238. { ; v 0.1 / (w) 28.06.2008 by derRaphael / zLib-Style release
  239.    Loop,Parse,str,`%
  240.       txt := (A_Index=1) ? A_LoopField : txt chr("0x" substr(A_LoopField,1,2)) SubStr(A_LoopField,3)
  241.    return txt
  242. }
  243. ; httpQuery-0-3-5.ahk
  244. httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="")
  245. {   ; v0.3.5 (w) Sep, 8 2008 by Heresy & derRaphael / zLib-Style release
  246.    ; updates Aug, 28 2008    
  247.    ; currently the verbs showHeader, storeHeader, and updateSize are supported in httpQueryOps
  248.    ; in case u need a different UserAgent, Proxy, ProxyByPass, Referrer, and AcceptType just
  249.    ; specify them as global variables - mind the varname for referrer is httpQueryReferer [sic].
  250.    ; Also if any special dwFlags are needed such as INTERNET_FLAG_NO_AUTO_REDIRECT or cache
  251.    ; handling this might be set using the httpQueryDwFlags variable as global
  252.    global httpQueryOps, httpAgent, httpProxy, httpProxyByPass, httpQueryReferer, httpQueryAcceptType
  253.        , httpQueryDwFlags
  254.    ; Get any missing default Values
  255.    defaultOps =
  256.    (LTrim Join|
  257.       httpAgent=AutoHotkeyScript|httpProxy=0|httpProxyByPass=0|INTERNET_FLAG_SECURE=0x00800000
  258.       SECURITY_FLAG_IGNORE_UNKNOWN_CA=0x00000100|SECURITY_FLAG_IGNORE_CERT_CN_INVALID=0x00001000
  259.       SECURITY_FLAG_IGNORE_CERT_DATE_INVALID=0x00002000|SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE=0x00000200
  260.       INTERNET_OPEN_TYPE_PROXY=3|INTERNET_OPEN_TYPE_DIRECT=1|INTERNET_SERVICE_HTTP=3
  261.    )
  262.    Loop,Parse,defaultOps,|
  263.    {
  264.       RegExMatch(A_LoopField,"(?P<Option>[^=]+)=(?P<Default>.*)",http)
  265.       if StrLen(%httpOption%)=0
  266.          %httpOption% := httpDefault
  267.    }
  268.  
  269.    ; Load Library
  270.    hModule := DllCall("LoadLibrary", "Str", "WinINet.Dll")
  271.  
  272.    ; SetUpStructures for URL_COMPONENTS / needed for InternetCrackURL
  273.    ; http://msdn.microsoft.com/en-us/library/aa385420(VS.85).aspx
  274.    offset_name_length:= "4-lpszScheme-255|16-lpszHostName-1024|28-lpszUserName-1024|"
  275.                   . "36-lpszPassword-1024|44-lpszUrlPath-1024|52-lpszExtrainfo-1024"
  276.    VarSetCapacity(URL_COMPONENTS,60,0)
  277.    ; Struc Size               ; Scheme Size                  ; Max Port Number
  278.    NumPut(60,URL_COMPONENTS,0), NumPut(255,URL_COMPONENTS,12), NumPut(0xffff,URL_COMPONENTS,24)
  279.    
  280.    Loop,Parse,offset_name_length,|
  281.    {
  282.       RegExMatch(A_LoopField,"(?P<Offset>\d+)-(?P<Name>[a-zA-Z]+)-(?P<Size>\d+)",iCU_)
  283.       VarSetCapacity(%iCU_Name%,iCU_Size,0)
  284.       NumPut(&%iCU_Name%,URL_COMPONENTS,iCU_Offset)
  285.       NumPut(iCU_Size,URL_COMPONENTS,iCU_Offset+4)
  286.    }
  287.  
  288.    ; Split the given URL; extract scheme, user, pass, authotity (host), port, path, and query (extrainfo)
  289.    ; http://msdn.microsoft.com/en-us/library/aa384376(VS.85).aspx
  290.    DllCall("WinINet\InternetCrackUrlA","Str",lpszUrl,"uInt",StrLen(lpszUrl),"uInt",0,"uInt",&URL_COMPONENTS)
  291.  
  292.    ; Update variables to retrieve results
  293.    Loop,Parse,offset_name_length,|
  294.    {
  295.       RegExMatch(A_LoopField,"-(?P<Name>[a-zA-Z]+)-",iCU_)
  296.       VarSetCapacity(%iCU_Name%,-1)
  297.    }
  298.    nPort:=NumGet(URL_COMPONENTS,24,"uInt")
  299.    
  300.    ; Import any set dwFlags
  301.    dwFlags := httpQueryDwFlags
  302.    ; For some reasons using a selfsigned https certificates doesnt work
  303.    ; such as an own webmin service - even though every security is turned off
  304.    ; https with valid certificates works when
  305.    if (lpszScheme = "https")
  306.       dwFlags |= (INTERNET_FLAG_SECURE|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
  307.                |SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)
  308.  
  309.    ; Check for Header and drop exception if unknown or invalid URL
  310.    if (lpszScheme="unknown") {
  311.       Result := "ERR: No Valid URL supplied."
  312.       Return StrLen(Result)
  313.    }
  314.  
  315.    ; Initialise httpQuery's use of the WinINet functions.
  316.    ; http://msdn.microsoft.com/en-us/library/aa385096(VS.85).aspx
  317.    hInternet := DllCall("WinINet\InternetOpenA"
  318.                   ,"Str",httpAgent,"UInt"
  319.                   ,(httpProxy != 0 ?  INTERNET_OPEN_TYPE_PROXY : INTERNET_OPEN_TYPE_DIRECT )
  320.                   ,"Str",httpProxy,"Str",httpProxyBypass,"Uint",0)
  321.  
  322.    ; Open HTTP session for the given URL
  323.    ; http://msdn.microsoft.com/en-us/library/aa384363(VS.85).aspx
  324.    hConnect := DllCall("WinINet\InternetConnectA"
  325.                   ,"uInt",hInternet,"Str",lpszHostname, "Int",nPort
  326.                   ,"Str",lpszUserName, "Str",lpszPassword,"uInt",INTERNET_SERVICE_HTTP
  327.                   ,"uInt",0,"uInt*",0)
  328.  
  329.    ; Do we POST? If so, check for header handling and set default
  330.    if (Strlen(POSTDATA)>0) {
  331.       HTTPVerb:="POST"
  332.       if StrLen(Headers)=0
  333.          Headers:="Content-Type: application/x-www-form-urlencoded"
  334.    } else ; otherwise mode must be GET - no header defaults needed
  335.       HTTPVerb:="GET"    
  336.  
  337.    ; Form the request with proper HTTP protocol version and create the request handle
  338.    ; http://msdn.microsoft.com/en-us/library/aa384233(VS.85).aspx
  339.    hRequest := DllCall("WinINet\HttpOpenRequestA"
  340.                   ,"uInt",hConnect,"Str",HTTPVerb,"Str",lpszUrlPath . lpszExtrainfo
  341.                   ,"Str",ProVer := "HTTP/1.1", "Str",httpQueryReferer,"Str",httpQueryAcceptTypes
  342.                   ,"uInt",dwFlags,"uInt",Context:=0 )
  343.  
  344.    ; Send the specified request to the server
  345.    ; http://msdn.microsoft.com/en-us/library/aa384247(VS.85).aspx
  346.    sRequest := DllCall("WinINet\HttpSendRequestA"
  347.                   , "uInt",hRequest,"Str",Headers, "uInt",Strlen(Headers)
  348.                   , "Str",POSTData,"uInt",Strlen(POSTData))
  349.  
  350.    VarSetCapacity(header, 2048, 0)  ; max 2K header data for httpResponseHeader
  351.    VarSetCapacity(header_len, 4, 0)
  352.    
  353.    ; Check for returned server response-header (works only _after_ request been sent)
  354.    ; http://msdn.microsoft.com/en-us/library/aa384238.aspx
  355.    Loop, 5
  356.      if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest
  357.       ,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)
  358.       break
  359.  
  360.    If (headerRequest=1) {
  361.       VarSetCapacity(res,headerLength:=NumGet(header_len),32)
  362.       DllCall("RtlMoveMemory","uInt",&res,"uInt",&header,"uInt",headerLength)
  363.       Loop,% headerLength
  364.          if (*(&res-1+a_index)=0) ; Change binary zero to linefeed
  365.             NumPut(Asc("`n"),res,a_index-1,"uChar")
  366.       VarSetCapacity(res,-1)
  367.    } else
  368.       res := "timeout"
  369.  
  370.    ; Get 1st Line of Full Response
  371.    Loop,Parse,res,`n,`r
  372.    {
  373.       RetValue := A_LoopField
  374.       break
  375.    }
  376.    
  377.    ; No Connection established - drop exception
  378.    If (RetValue="timeout") {
  379.       html := "Error: timeout"
  380.       return -1
  381.    }
  382.    ; Strip protocol version from return value
  383.    RetValue := RegExReplace(RetValue,"HTTP/1\.[01]\s+")
  384.    
  385.     ; List taken from http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
  386.    HttpRetCodes := "100=Continue|101=Switching Protocols|102=Processing (WebDAV) (RFC 2518)|"
  387.               . "200=OK|201=Created|202=Accepted|203=Non-Authoritative Information|204=No"
  388.               . " Content|205=Reset Content|206=Partial Content|207=Multi-Status (WebDAV)"
  389.               . "|300=Multiple Choices|301=Moved Permanently|302=Found|303=See Other|304="
  390.               . "Not Modified|305=Use Proxy|306=Switch Proxy|307=Temporary Redirect|400=B"
  391.               . "ad Request|401=Unauthorized|402=Payment Required|403=Forbidden|404=Not F"
  392.               . "ound|405=Method Not Allowed|406=Not Acceptable|407=Proxy Authentication "
  393.               . "Required|408=Request Timeout|409=Conflict|410=Gone|411=Length Required|4"
  394.               . "12=Precondition Failed|413=Request Entity Too Large|414=Request-URI Too "
  395.               . "Long|415=Unsupported Media Type|416=Requested Range Not Satisfiable|417="
  396.               . "Expectation Failed|418=I'm a teapot (RFC 2324)|422=Unprocessable Entity "
  397.               . "(WebDAV) (RFC 4918)|423=Locked (WebDAV) (RFC 4918)|424=Failed Dependency"
  398.               . " (WebDAV) (RFC 4918)|425=Unordered Collection (RFC 3648)|426=Upgrade Req"
  399.               . "uired (RFC 2817)|449=Retry With|500=Internal Server Error|501=Not Implem"
  400.               . "ented|502=Bad Gateway|503=Service Unavailable|504=Gateway Timeout|505=HT"
  401.               . "TP Version Not Supported|506=Variant Also Negotiates (RFC 2295)|507=Insu"
  402.               . "fficient Storage (WebDAV) (RFC 4918)|509=Bandwidth Limit Exceeded|510=No"
  403.               . "t Extended (RFC 2774)"
  404.    
  405.    ; Gather numeric response value
  406.    RetValue := SubStr(RetValue,1,3)
  407.    
  408.    ; Parse through return codes and set according informations
  409.    Loop,Parse,HttpRetCodes,|
  410.    {
  411.       HttpReturnCode := SubStr(A_LoopField,1,3)    ; Numeric return value see above
  412.       HttpReturnMsg  := SubStr(A_LoopField,5)      ; link for additional information
  413.       if (RetValue=HttpReturnCode) {
  414.          RetMsg := HttpReturnMsg
  415.          break
  416.       }
  417.    }
  418.  
  419.    ; Global HttpQueryOps handling
  420.    if strlen(HTTPQueryOps)>0 {
  421.       ; Show full Header response (usefull for debugging)
  422.       if (instr(HTTPQueryOps,"showHeader"))
  423.          MsgBox % res
  424.       ; Save the full Header response in a global Variable
  425.       if (instr(HTTPQueryOps,"storeHeader"))
  426.          global HttpQueryHeader := res
  427.       ; Check for size updates to export to a global Var
  428.       if (instr(HTTPQueryOps,"updateSize")) {
  429.          Loop,Parse,res,`n
  430.             If RegExMatch(A_LoopField,"Content-Length:\s+?(?P<Size>\d+)",full) {
  431.                global HttpQueryFullSize := fullSize
  432.                break
  433.             }
  434.          if (fullSize+0=0)
  435.             HttpQueryFullSize := "size unavailable"
  436.       }
  437.    }
  438.  
  439.    ; Check for valid codes and drop exception if suspicious
  440.    if !(InStr("100 200 201 202 302",RetValue)) {
  441.       Result := RetValue " " RetMsg
  442.       return StrLen(Result)
  443.    }
  444.  
  445.    VarSetCapacity(BytesRead,4,0)
  446.    fsize := 0
  447.    Loop            ; the receiver loop - rewritten in the need to enable
  448.    {               ; support for larger file downloads
  449.       bc := A_Index
  450.       VarSetCapacity(buffer%bc%,1024,0) ; setup new chunk for this receive round
  451.       ReadFile := DllCall("wininet\InternetReadFile"
  452.                   ,"uInt",hRequest,"uInt",&buffer%bc%,"uInt",1024,"uInt",&BytesRead)
  453.       ReadBytes := NumGet(BytesRead)    ; how many bytes were received?
  454.       If ((ReadFile!=0)&&(!ReadBytes))  ; we have had no error yet and received no more bytes
  455.          break                         ; we must be done! so lets break the receiver loop
  456.       Else {
  457.          fsize += ReadBytes            ; sum up all chunk sizes for correct return size
  458.          sizeArray .= ReadBytes "|"
  459.       }
  460.       if (instr(HTTPQueryOps,"updateSize"))
  461.          Global HttpQueryCurrentSize := fsize
  462.    }
  463.    sizeArray := SubStr(sizeArray,1,-1)   ; trim last PipeChar
  464.    
  465.    VarSetCapacity(result,fSize+1,0)      ; reconstruct the result from above generated chunkblocks
  466.    Dest := &result                       ; to a our ByRef result variable
  467.    Loop,Parse,SizeArray,|
  468.       DllCall("RtlMoveMemory","uInt",Dest,"uInt",&buffer%A_Index%,"uInt",A_LoopField)
  469.       , Dest += A_LoopField
  470.      
  471.    DllCall("WinINet\InternetCloseHandle", "uInt", hRequest)   ; close all opened
  472.    DllCall("WinINet\InternetCloseHandle", "uInt", hInternet)
  473.    DllCall("WinINet\InternetCloseHandle", "uInt", hConnect)
  474.    DllCall("FreeLibrary", "UInt", hModule)                    ; unload the library
  475.    return fSize                          ; return the size - strings need update via VarSetCapacity(res,-1)
  476. }
  477.  
  478. MD5( ByRef V, L=0 ) { ; www.autohotkey.com/forum/viewtopic.php?p=275910#275910
  479.  VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX )
  480.  DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,V, UInt,L ? L : VarSetCapacity(V) )
  481.  DllCall( "advapi32\MD5Final", Str,MD5_CTX )
  482.  Loop % StrLen( Hex:="123456789ABCDEF0" )
  483.   N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
  484. Return MD5
  485. }
Advertisement
Add Comment
Please, Sign In to add comment