1 (изменено: Dixxx, 2011-12-18 01:19:33)

Тема: AHK: Авторизация Вконтакте

Всем привет. Нашёл на просторах интернета пример авторизации ВК, лично у меня не работает, не могу разобраться что именно исправить. Помогите пожалуйста.

Gui, Color, Default
Gui, Add, Edit, x82 y70 w145 h17 vmail,Введите e'mail
Gui, Add, Edit, x82 y97 w145 h17 vpass password,Введите пароль
Gui, Add, Button,genter x150 y122 w82 h22 +default,Вход
Gui, Show,x0 y0 w250 h150,Vkontakte
Return
GuiClose:
ExitApp
return
enter:
Gui,Submit,NoHide
passw := pass
If (!if)
{
passw:=""
}
mail := EncodeURL(mail)
pass := EncodeURL(pass)
otvet := connect("http://vkontakte.ru/login.php","Content-Type: application/x-www-form-urlencoded`nX-Requested-With: XMLHttpRequest`nContent-Transfer-Encoding: binary`nCookie:remixsid=nonenone","op=a_login_attempt")
reg=captcha_sid":"(.*?)"
loop{
If RegExMatch(otvet,reg,sid_catpcha){
URLDownloadToFile,http://vkontakte.ru/captcha.php?s=1&sid=%sid_catpcha1%,captcha.jpg
captcha := ""
captcha()
loop{
If captcha{
break
}
}
otvet := connect("http://vkontakte.ru/login.php","Content-Type: application/x-www-form-urlencoded`nX-Requested-With: XMLHttpRequest`nContent-Transfer-Encoding: binary`nCookie:remixsid=nonenone","op=a_login_attempt&captcha_sid=" sid_catpcha1 "&captcha_key=" EncodeURL(captcha))
}else{
break
}
}
httpQueryDwFlags := (INTERNET_FLAG_NO_COOKIES:= 0x00080000|INTERNET_FLAG_DONT_CACHE:=0x04000000|INTERNET_FLAG_NO_CACHE_WRITE:=0x04000000|INTERNET_FLAG_RELOAD:=0x80000000)
reconn_post:="act=login&q=1&al_frame=1&expire=&captcha_sid=&captcha_key=&from_host=vkontakte.ru&email=" mail "&pass=" pass
reconn_data:=http_win(fake_reconn_data:="","http://login.vk.com/?act=login",reconn_post)
RegExMatch(reconn_data, "remixsid=(.*?);",sid)
httpQueryDwFlags := (INTERNET_FLAG_NO_COOKIES:= 0x00080000|INTERNET_FLAG_DONT_CACHE:=0x04000000|INTERNET_FLAG_NO_CACHE_WRITE:=0x04000000|INTERNET_FLAG_RELOAD:=0x80000000|INTERNET_FLAG_NO_AUTO_REDIRECT:= 0x00200000)
if sid1=deleted
{
msgbox 0,%name%,Неверный пароль..
return
}else{
Gui,Destroy
cookie :="Content-Type: application/x-www-form-urlencoded`nX-Requested-With: XMLHttpRequest`nContent-Transfer-Encoding: binary`nCookie:remixchk=5; remixsid=" sid1
sleep 2000
otvet:= connect("http://vkontakte.ru/feed.php",cookie,"")
RegExMatch(otvet, "id=(.*?),", myid)
If (myid1==""){
}

2

Re: AHK: Авторизация Вконтакте

Где-то рядом с местом нахождения сего скрипта должна лежать функция EncodeURL()

3

Re: AHK: Авторизация Вконтакте

С этим разобрался, но вот с самописной connect не получается, вроде как она есть в этой библиотеке, но всё равно выдаёт ошибку:|

; <COMPILER: v1.0.48.5>

httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="")
{






   global httpQueryOps, httpAgent, httpProxy, httpProxyByPass, httpQueryReferer, httpQueryAcceptType
       , httpQueryDwFlags

   defaultOps =
   (LTrim Join|
      httpAgent=AutoHotkeyScript|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)
   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)
            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)
      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
}
http_win(byref Result, lpszUrl, POSTDATA="", HEADERS="",fix_HttpQuery="")
{






   global httpQueryOps, httpAgent, httpProxy, httpProxyByPass, httpQueryReferer, httpQueryAcceptType
       , httpQueryDwFlags



   quote="
   trash_quote='

   scr_url:=lpszUrl
   scr_post:=POSTDATA
   scr_head:=HEADERS
   scr_fix:=fix_HttpQuery
   defaultOps:="httpProxy=0|httpProxyByPass=1|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)
   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)
            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 400 500",RetValue)) {
      Result := RetValue " " RetMsg
      return StrLen(Result)
   }

   VarSetCapacity(BytesRead,4,0)
   fsize := 0
   Loop
   {
      bc := A_Index
      VarSetCapacity(buffer%bc%,1024,0)
      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

      if(fix_HttpQuery="")
      {
         varSetCapacity(result,-1)
         result:= RegexReplace(result, quote, trash_quote)
         StringReplace,result,result,`r,,All
      }





   DllCall("WinINet\InternetCloseHandle", "uInt", hRequest)
   DllCall("WinINet\InternetCloseHandle", "uInt", hInternet)
   DllCall("WinINet\InternetCloseHandle", "uInt", hConnect)
   DllCall("FreeLibrary", "UInt", hModule)




   return qwe:=fSize . "|--|--|" res




}

4

Re: AHK: Авторизация Вконтакте

Что-то мне не нравится стиль вашего изложения
В приведенном коде 2 функции:

httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="")
http_win(byref Result, lpszUrl, POSTDATA="", HEADERS="",fix_HttpQuery="")

5

Re: AHK: Авторизация Вконтакте

я вообще запутался