msgbox

facebook auth??! :)

Jan 29th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoTrayIcon
  2. #SingleInstance force
  3.  
  4.   ;httpProxy := "157.85.34.94:8080"
  5.   user := ""
  6.   pass := ""
  7.  
  8.   httpQueryOps:="storeHeader"
  9.   httpAgent := "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7"
  10.   httpQueryDwFlags:=(INTERNET_FLAG_NO_COOKIES:=0x00080000|INTERNET_FLAG_NO_AUTO_REDIRECT:=0x00200000|INTERNET_FLAG_SECURE=0x00800000)
  11.  
  12.   httpQuery(data:="", "http://m.facebook.com")
  13.   varSetCapacity(data, -1)
  14.   form := regexreplace(data, ".*post_form_id"" value=""(.*?)"".*", "$1")
  15.   time := regexreplace(data, ".*m_ts"" value=""(.*?)"".*", "$1")
  16.   some := regexreplace(data, ".*li"" value=""(.*?)"".*", "$1")
  17.   char := regexreplace(data, ".*charset_test"" value=""(.*?)"".*", "$1")
  18.  
  19.   link := "https://m.facebook.com/login.php?refid=8"
  20.   httpQueryDwFlags:=(INTERNET_FLAG_SECURE=0x00800000)
  21.   post := "post_form_id=" form "&email=" user "&pass=" pass "&m_ts=" time "&li=" some "&charset_test=" char "&login=Войти&version=1&ajax=1&width=1280&pxr=1&gps=1"
  22.   httpQuery(data:="", lpszUrl:=link, POSTDATA:=post)
  23.   varSetCapacity(data, -1)
  24.   data := UTF82Ansi(data)
  25.   user := regexreplace(data, ".*logout"">(.*?)</a> \((.*?)\)</span>.*", "$2")
  26.  
  27.   if (user)
  28.   {
  29.     msgbox, 64, Success!, Authorized as %user%!
  30.   }
  31.   else
  32.   {
  33.     msgbox, 64, Fail!, Not autorized, try again!
  34.   }
  35. ExitApp
  36.  
  37.  
  38.  
  39.  
  40. EncodeURL( p_data, p_reserved=true, p_encode=true )
  41. {
  42.    old_FormatInteger := A_FormatInteger
  43.    SetFormat, Integer, hex
  44.  
  45.    unsafe =
  46.       ( Join LTrim
  47.          25000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20
  48.          22233C3E5B5C5D5E607B7C7D7F808182838485868788898A8B8C8D8E8F9091929394
  49.          95969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6
  50.          B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8
  51.          D9DADBDCDDDEDF7EE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9
  52.          FAFBFCFDFEFF
  53.       )
  54.        
  55.    if ( p_reserved )
  56.       unsafe = %unsafe%24262B2C2F3A3B3D3F40
  57.    
  58.    if ( p_encode )
  59.       loop, % StrLen( unsafe )//2
  60.       {
  61.          StringMid, token, unsafe, A_Index*2-1, 2
  62.          StringReplace, p_data, p_data, % Chr( "0x" token ), `%%token%, all
  63.       }
  64.    else
  65.       loop, % StrLen( unsafe )//2
  66.       {
  67.          StringMid, token, unsafe, A_Index*2-1, 2
  68.          StringReplace, p_data, p_data, `%%token%, % Chr( "0x" token ), all
  69.       }
  70.        
  71.    SetFormat, Integer, %old_FormatInteger%
  72.  
  73.    return, p_data
  74. }
  75.  
  76. DecodeURL( p_data )
  77. {
  78.    return, EncodeURL( p_data, true, false )
  79. }
  80. Ansi2Oem(sString)
  81. {
  82.    Ansi2Unicode(sString, wString, 0)
  83.    Unicode2Ansi(wString, zString, 1)
  84.    Return zString
  85. }
  86.  
  87. Oem2Ansi(zString)
  88. {
  89.    Ansi2Unicode(zString, wString, 1)
  90.    Unicode2Ansi(wString, sString, 0)
  91.    Return sString
  92. }
  93.  
  94. Ansi2UTF8(sString)
  95. {
  96.    Ansi2Unicode(sString, wString, 0)
  97.    Unicode2Ansi(wString, zString, 65001)
  98.    Return zString
  99. }
  100.  
  101. UTF82Ansi(zString)
  102. {
  103.    Ansi2Unicode(zString, wString, 65001)
  104.    Unicode2Ansi(wString, sString, 0)
  105.    Return sString
  106. }
  107.  
  108. Ansi2Unicode(ByRef sString, ByRef wString, CP = 0)
  109. {
  110.      nSize := DllCall("MultiByteToWideChar"
  111.       , "Uint", CP
  112.       , "Uint", 0
  113.       , "Uint", &sString
  114.       , "int",  -1
  115.       , "Uint", 0
  116.       , "int",  0)
  117.  
  118.    VarSetCapacity(wString, nSize * 2)
  119.  
  120.    DllCall("MultiByteToWideChar"
  121.       , "Uint", CP
  122.       , "Uint", 0
  123.       , "Uint", &sString
  124.       , "int",  -1
  125.       , "Uint", &wString
  126.       , "int",  nSize)
  127. }
  128.  
  129. Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
  130. {
  131.      nSize := DllCall("WideCharToMultiByte"
  132.       , "Uint", CP
  133.       , "Uint", 0
  134.       , "Uint", &wString
  135.       , "int",  -1
  136.       , "Uint", 0
  137.       , "int",  0
  138.       , "Uint", 0
  139.       , "Uint", 0)
  140.  
  141.    VarSetCapacity(sString, nSize)
  142.  
  143.    DllCall("WideCharToMultiByte"
  144.       , "Uint", CP
  145.       , "Uint", 0
  146.       , "Uint", &wString
  147.       , "int",  -1
  148.       , "str",  sString
  149.       , "int",  nSize
  150.       , "Uint", 0
  151.       , "Uint", 0)
  152. }
  153.  
  154.  
  155.  
  156. httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="")
  157. {   global httpQueryOps, httpAgent, httpProxy, httpProxyByPass, httpQueryReferer, httpQueryAcceptType
  158.        , httpQueryDwFlags
  159.    defaultOps =
  160.    (LTrim Join|
  161.       httpAgent=script|httpProxy=0|httpProxyByPass=0|INTERNET_FLAG_SECURE=0x00800000
  162.       SECURITY_FLAG_IGNORE_UNKNOWN_CA=0x00000100|SECURITY_FLAG_IGNORE_CERT_CN_INVALID=0x00001000
  163.       SECURITY_FLAG_IGNORE_CERT_DATE_INVALID=0x00002000|SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE=0x00000200
  164.       INTERNET_OPEN_TYPE_PROXY=3|INTERNET_OPEN_TYPE_DIRECT=1|INTERNET_SERVICE_HTTP=3
  165.    )
  166.    Loop,Parse,defaultOps,|
  167.    {
  168.       RegExMatch(A_LoopField,"(?P<Option>[^=]+)=(?P<Default>.*)",http)
  169.       if StrLen(%httpOption%)=0
  170.          %httpOption% := httpDefault
  171.    }
  172.  
  173.    hModule := DllCall("LoadLibrary", "Str", "WinINet.Dll")
  174.  
  175.    offset_name_length:= "4-lpszScheme-255|16-lpszHostName-1024|28-lpszUserName-1024|"
  176.                   . "36-lpszPassword-1024|44-lpszUrlPath-1024|52-lpszExtrainfo-1024"
  177.    VarSetCapacity(URL_COMPONENTS,60,0)
  178.    NumPut(60,URL_COMPONENTS,0), NumPut(255,URL_COMPONENTS,12), NumPut(0xffff,URL_COMPONENTS,24)
  179.    
  180.    Loop,Parse,offset_name_length,|
  181.    {
  182.       RegExMatch(A_LoopField,"(?P<Offset>\d+)-(?P<Name>[a-zA-Z]+)-(?P<Size>\d+)",iCU_)
  183.       VarSetCapacity(%iCU_Name%,iCU_Size,0)
  184.       NumPut(&%iCU_Name%,URL_COMPONENTS,iCU_Offset)
  185.       NumPut(iCU_Size,URL_COMPONENTS,iCU_Offset+4)
  186.    }
  187.  
  188.    DllCall("WinINet\InternetCrackUrlA","Str",lpszUrl,"uInt",StrLen(lpszUrl),"uInt",0,"uInt",&URL_COMPONENTS)
  189.  
  190.    Loop,Parse,offset_name_length,|
  191.    {
  192.       RegExMatch(A_LoopField,"-(?P<Name>[a-zA-Z]+)-",iCU_)
  193.       VarSetCapacity(%iCU_Name%,-1)
  194.    }
  195.    nPort:=NumGet(URL_COMPONENTS,24,"uInt")
  196.    
  197.    dwFlags := httpQueryDwFlags
  198.    if (lpszScheme = "https")
  199.       dwFlags |= (INTERNET_FLAG_SECURE|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
  200.                |SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)
  201.  
  202.    if (lpszScheme="unknown") {
  203.       Result := "ERR: No Valid URL supplied."
  204.       Return StrLen(Result)
  205.    }
  206.  
  207.    hInternet := DllCall("WinINet\InternetOpenA"
  208.                   ,"Str",httpAgent,"UInt"
  209.                   ,(httpProxy != 0 ?  INTERNET_OPEN_TYPE_PROXY : INTERNET_OPEN_TYPE_DIRECT )
  210.                   ,"Str",httpProxy,"Str",httpProxyBypass,"Uint",0)
  211.  
  212.    hConnect := DllCall("WinINet\InternetConnectA"
  213.                   ,"uInt",hInternet,"Str",lpszHostname, "Int",nPort
  214.                   ,"Str",lpszUserName, "Str",lpszPassword,"uInt",INTERNET_SERVICE_HTTP
  215.                   ,"uInt",0,"uInt*",0)
  216.  
  217.    if (Strlen(POSTDATA)>0) {
  218.       HTTPVerb:="POST"
  219.       if StrLen(Headers)=0
  220.          Headers:="Content-Type: application/x-www-form-urlencoded"
  221.    } else
  222.       HTTPVerb:="GET"    
  223.  
  224.    hRequest := DllCall("WinINet\HttpOpenRequestA"
  225.                   ,"uInt",hConnect,"Str",HTTPVerb,"Str",lpszUrlPath . lpszExtrainfo
  226.                   ,"Str",ProVer := "HTTP/1.1", "Str",httpQueryReferer,"Str",httpQueryAcceptTypes
  227.                   ,"uInt",dwFlags,"uInt",Context:=0 )
  228.  
  229.    sRequest := DllCall("WinINet\HttpSendRequestA"
  230.                   , "uInt",hRequest,"Str",Headers, "uInt",Strlen(Headers)
  231.                   , "Str",POSTData,"uInt",Strlen(POSTData))
  232.  
  233.    VarSetCapacity(header, 2048, 0)  ; max 2K header data for httpResponseHeader
  234.    VarSetCapacity(header_len, 4, 0)
  235.    
  236.    Loop, 5
  237.      if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest
  238.       ,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)
  239.       break
  240.  
  241.    If (headerRequest=1) {
  242.       VarSetCapacity(res,headerLength:=NumGet(header_len),32)
  243.       DllCall("RtlMoveMemory","uInt",&res,"uInt",&header,"uInt",headerLength)
  244.       Loop,% headerLength
  245.          if (*(&res-1+a_index)=0) ; Change binary zero to linefeed
  246.             NumPut(Asc("`n"),res,a_index-1,"uChar")
  247.       VarSetCapacity(res,-1)
  248.    } else
  249.       res := "timeout"
  250.  
  251.    Loop,Parse,res,`n,`r
  252.    {
  253.       RetValue := A_LoopField
  254.       break
  255.    }
  256.    
  257.    If (RetValue="timeout") {
  258.       html := "Error: timeout"
  259.       return -1
  260.    }
  261.    RetValue := RegExReplace(RetValue,"HTTP/1\.[01]\s+")
  262.    
  263.    RetValue := SubStr(RetValue,1,3)
  264.    
  265.    if strlen(HTTPQueryOps)>0 {
  266.       if (instr(HTTPQueryOps,"showHeader"))
  267.          MsgBox % res
  268.       if (instr(HTTPQueryOps,"storeHeader"))
  269.          global HttpQueryHeader := res
  270.       if (instr(HTTPQueryOps,"updateSize")) {
  271.          Loop,Parse,res,`n
  272.             If RegExMatch(A_LoopField,"Content-Length:\s+?(?P<Size>\d+)",full) {
  273.                global HttpQueryFullSize := fullSize
  274.                break
  275.             }
  276.          if (fullSize+0=0)
  277.             HttpQueryFullSize := "size unavailable"
  278.       }
  279.    }
  280.  
  281.    if !(InStr("100 200 201 202 302 500 502",RetValue)) {
  282.       Result := RetValue " " RetMsg
  283.       return StrLen(Result)
  284.    }
  285.  
  286.    VarSetCapacity(BytesRead,4,0)
  287.    fsize := 0
  288.    Loop            
  289.    {  bc := A_Index
  290.       VarSetCapacity(buffer%bc%,1024,0) ; setup new chunk for this receive round
  291.       ReadFile := DllCall("wininet\InternetReadFile"
  292.                   ,"uInt",hRequest,"uInt",&buffer%bc%,"uInt",1024,"uInt",&BytesRead)
  293.       ReadBytes := NumGet(BytesRead)  
  294.       If ((ReadFile!=0)&&(!ReadBytes))  
  295.          break                      
  296.       Else {
  297.          fsize += ReadBytes  
  298.          sizeArray .= ReadBytes "|"
  299.       }
  300.       if (instr(HTTPQueryOps,"updateSize"))
  301.          Global HttpQueryCurrentSize := fsize
  302.    }
  303.    sizeArray := SubStr(sizeArray,1,-1)  
  304.    
  305.    VarSetCapacity(result,fSize+1,0)      
  306.    Dest := &result            
  307.    Loop,Parse,SizeArray,|
  308.       DllCall("RtlMoveMemory","uInt",Dest,"uInt",&buffer%A_Index%,"uInt",A_LoopField)
  309.       , Dest += A_LoopField
  310.      
  311.    DllCall("WinINet\InternetCloseHandle", "uInt", hRequest)  
  312.    DllCall("WinINet\InternetCloseHandle", "uInt", hInternet)
  313.    DllCall("WinINet\InternetCloseHandle", "uInt", hConnect)
  314.    DllCall("FreeLibrary", "UInt", hModule)              
  315.    return fSize
  316. }
  317.  
  318. Generate_POST_Body(fields, ByRef postbody, ByRef headers){
  319.    
  320.    ; generate boundary
  321.    static chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  322.    boundary = --
  323.    Loop, 8 {
  324.       Random, RChar, 1, % StrLen(chars)
  325.       boundary .= SubStr(chars, RChar, 1)
  326.    }
  327.  
  328.    ; generate postbody
  329.    #LTrim
  330.    postbody =
  331.    Loop, Parse, fields, `n, `r%A_Space%%A_Tab%
  332.    {
  333.       if RegExMatch(A_LoopField, "i)(?<name>.+?)=(?<isFile>@)?(?<val>.+)", field_)
  334.       {
  335.          postbody = %postbody%
  336.             (Join`r`n
  337.                --%boundary%
  338.                Content-Disposition: form-data; name="%field_name%"
  339.             )
  340.          if field_isFile and FileExist(field_val)
  341.          {
  342.             FileRead, file, %field_val%
  343.                fileType := MimeType(file)
  344.             SplitPath, field_val, filename
  345.             FileGetSize, fileSize, %field_val%
  346.             VarSetCapacity(placeholder, fileSize, 32)
  347.  
  348.             postbody = %postbody%; filename="%filename%"
  349.                (Join`r`n
  350.                  
  351.                   Content-Type: %fileType%
  352.                )
  353.             field_val := placeholder
  354.          }
  355.          postbody .= "`r`n`r`n" . field_val . "`r`n"
  356.       }
  357.    }
  358.    postbody .= "--" boundary "--`r`n"
  359.    #LTrim Off
  360.    
  361.    ; generate headers
  362.    headers .= (StrLen(headers) ? "`r`n" : "")
  363.       . "Content-type: multipart/form-data; boundary=" boundary "`r`n"
  364.       . "Content-Length: " strlen(postbody)
  365.  
  366.    if field_isFile
  367.       DllCall("RtlMoveMemory"
  368.       , "uInt", (offset:=&postbody+strlen(postbody)-strlen(boundary)-fileSize-8)
  369.       , "uInt", &file
  370.       , "uInt", filesize)
  371.    return boundary
  372. }
  373.  
  374. MimeType(ByRef Binary) {
  375.    MimeTypes:="424d image/bmp|4749463 image/gif|ffd8ffe image/jpeg|89504e4 image/png|4657530"
  376.           . " application/x-shockwave-flash|49492a0 image/tiff"
  377.    @:="0123456789abcdef"
  378.    Loop,8
  379.       hex .= substr(@,(*(a:=&Binary-1+a_index)>>4)+1,1) substr(@,((*a)&15)+1,1)
  380.    Loop,Parse,MimeTypes,|
  381.       if ((substr(hex,1,strlen(n:=RegExReplace(A_Loopfield,"\s.*"))))=n)
  382.          Mime := RegExReplace(A_LoopField,".*?\s")
  383.    Return (Mime!="") ? Mime : "application/octet-stream"
  384. }
Advertisement
Add Comment
Please, Sign In to add comment