Jump to content

Recommended Posts

Posted

Hi, i'm trying to make a link decrypter, and i'm having difficulty to decrypt url shorteners such as bit.ly, adf.ly and etc

Using internet explorer i can do, but i wanted to do using _WinHttp functions, because it's more fast!

Anyone can give me an idea how can i do this?

something like:

#include <winhttp.au3>

$hw_open = _WinHttpOpen()
$hw_connect = _WinHttpConnect($hw_open, "http://adf.ly/5XR")
$h_openRequest = _WinHttpSimpleRequest($hw_connect, "POST");...

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)

Thanks a lot.

Posted (edited)

Example for bit.ly (but adf.ly is similar )

Winhttp.au3 >>

to be honest I checked bugmenot.com for a user (--> chiefpower).

But all you have to do is to create a account, get your personal api key and I guess the rest will be easy...

API KEY --> https://bitly.com/a/your_api_key

but with chiefpower you could give it a try.

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include "WinHttp.au3"
#include <Debug.au3>
Opt("MustDeclareVars", 1)
_DebugSetup (@SCRIPTNAME,false,1,@SCRIPTDIR&""&@ScriptName&".LOG")
;~ provider
global $URL_BASE= "api.bit.ly"
;~ short for www.autoit.com
global $URL_HASH="IfDIRp"

global $BITLY_USER="chiefpower"

global $BITLY_API="R_f4df1a4d776791ac7269ca9970856eca"
; Initialize
Global $hOpen = _WinHttpOpen()
; Specify what to connect to
Global $hConnect = _WinHttpConnect($hOpen,$URL_BASE)
; Create request
Global $hRequest = _WinHttpOpenRequest($hConnect, -1, "v3/expand?login="&$BITLY_USER&"&apiKey="&$BITLY_API&"&hash="&$URL_HASH&"&format=txt")
; Send it
_WinHttpSendRequest($hRequest)
; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then
    _DebugOut("Error ocurred for WinHttpReceiveResponse, Error number is " & @error)
Else
    _DebugOut("Server at '"&$URL_BASE&"' processed the request.")
EndIf

Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
    ; Read
    While 1
        $sChunk = _WinHttpReadData($hRequest)
        If @error Then ExitLoop
        $sData &= $sChunk
    WEnd
    _DebugOut("THE LONG URL is:#"&$sData&"#" & @CRLF)
Else
    _DebugOut("Site is experiencing problems.")
EndIf
; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

Here is the bitly api complete URL:

for expanding a short url

;~ http://api.bit.ly/v3/expand?login=chiefp...c7269ca9970856eca&hash=IfDIRp

for shorten a real url (you need to add the protocol always ... took me some time to find out :-) )

;~ http://api.bit.ly/v3/shorten?login=chief...longUrl=http://www.autoit.com

Does this help you?

Edited by Tankbuster
Posted

I'll study the code, and when i finish the decrypter i post here to everyone

thanks a lot for the help!

I found something better :)

There is a API from http://longurl.org/

call : http://api.longurl.org/v2/services

And you will see all known services ! So this means you only need to implement the longurl api and not all others ;)

The respone you could get in JSON or in XML (I choose JSON, simply because I knew a JSON function (provided by http://www.autoit.de/index.php?page=Thread&postID=220606)

I know there is UDF, but I was to confused to include it ....

The code below is a modfied version of the first one.

I guess you will be fine with that universal API, didn't you?

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include "WinHttp.au3"
#include <Debug.au3>
#include <Array.au3>
Opt("MustDeclareVars", 1)
_DebugSetup (@SCRIPTNAME,false,1,@SCRIPTDIR&"\"&@ScriptName&".LOG")
;~ provider
global $URL_BASE= "api.longurl.org"
global $URL_SHORT="http://bit.ly/3XK22P"
;~ http://api.longurl.org/v2/expand?url=http%3A%2F%2Fis.gd%2Fw&format=json
; Initialize
Global $hOpen = _WinHttpOpen()
; Specify what to connect to
Global $hConnect = _WinHttpConnect($hOpen,$URL_BASE)
;~ Encode URL for logurl
global $URL_ENCODED=_URIEncode($URL_SHORT)
_DebugOut("Encoded:"&$URL_ENCODED)
_DebugOut("Decoded:"&_URIDecode($URL_ENCODED))
; Create request
Global $hRequest = _WinHttpOpenRequest($hConnect, -1, "v2/expand?url="&$URL_ENCODED&"&format=json")
; Send it
_WinHttpSendRequest($hRequest)
; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then
    _DebugOut("Error ocurred for WinHttpReceiveResponse, Error number is " & @error)
Else
    _DebugOut("Server at '"&$URL_BASE&"' processed the request.")
EndIf
Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
    ; Read
    While 1
        $sChunk = _WinHttpReadData($hRequest)
        If @error Then ExitLoop
        $sData &= $sChunk
    WEnd
    _DebugOut("THE LONG URL is:#"&$sData&"#" & @CRLF)
global $aUrl_Json = _JSON_Decode($sData)
;~  _ArrayDisplay($aUrl_Json,"Hauptobjekt")
global $Url_Json = stringreplace($aUrl_Json[0][1],"\","")
_DebugOut("THE LONG URL is:#"&$Url_Json&"#" & @CRLF)
Else
    _DebugOut("Site is experiencing problems.")
EndIf
; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

Func _URIEncode($sData)
    ; Prog@ndy
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"")
    Local $nChar
    $sData=""
    For $i = 1 To $aData[0]
;~       ConsoleWrite($aData[$i] & @CRLF)
        $nChar = Asc($aData[$i])
        Switch $nChar
            Case 45, 46, 48-57, 65 To 90, 95, 97 To 122, 126
                $sData &= $aData[$i]
            Case 32
                $sData &= "+"
            Case Else
                $sData &= "%" & Hex($nChar,2)
        EndSwitch
    Next
    Return $sData
EndFunc
Func _URIDecode($sData)
    ; Prog@ndy
    Local $aData = StringSplit(StringReplace($sData,"+"," ",0,1),"%")
    $sData = ""
    For $i = 2 To $aData[0]
        $aData[1] &= Chr(Dec(StringLeft($aData[$i],2))) & StringTrimLeft($aData[$i],2)
    Next
    Return BinaryToString(StringToBinary($aData[1],1),4)
EndFunc

Func _JSON_Decode($sString)
    Local $aVal, $sOldStr = $sString, $b
local  $aNextArrayVal[2]
    $sString = StringStripCR(StringStripWS($sString, 7))
    If Not StringRegExp($sString, "(?i)^\{.+}$") Then Return SetError(1, 0, 0)
    Local $aArray[1][2], $iIndex = 0
    $sString = StringMid($sString, 2)
    Do
        $b = False
        $aVal = StringRegExp($sString, '^"([^"]+)"\s*:\s*(["{[]|[-+]?\d+(?:(?:\.\d+)?[eE][+-]\d+)?|true|false|null)', 2) ; Get value & next token
        If @error Then
            ConsoleWrite("!> StringRegExp Error getting next Value." & @CRLF)
            ConsoleWrite($sString & @CRLF)
            $sString = StringMid($sString, 2) ; maybe it works when the string is trimmed by 1 char from the left ?
            ContinueLoop
        EndIf
        $aArray[$iIndex][0] = $aVal[1] ; Key
        $sString = StringMid($sString, StringLen($aVal[0]))
        Switch $aVal[2] ; Value Type (Array, Object, String) ?
            Case '"' ; String
                ; Value -> Array subscript. Trim String after that.
                $aArray[$iIndex][1] = StringMid($sString, 2, StringInStr($sString, """", 1, 2) - 2)
                $sString = StringMid($sString, StringLen($aArray[$iIndex][1]) + 3)
                ReDim $aArray[$iIndex + 2][2]
                $iIndex += 1
            Case '{' ; Object
                ; Recursive function call which will decode the object and return it.
                ; Object -> Array subscript. Trim String after that.
                $aArray[$iIndex][1] = _JSON_Decode($sString)
                $sString = StringMid($sString, @extended + 2)
                If StringLeft($sString, 1) = "," Then $sString = StringMid($sString, 2)
                $b = True
                ReDim $aArray[$iIndex + 2][2]
                $iIndex += 1
            Case '[' ; Array
                ; Decode Array
                $sString = StringMid($sString, 2)
                Local $aRet[1], $iArIndex = 0 ; create new array which will contain the Json-Array.
                Do
                    $sString = StringStripWS($sString, 3) ; Trim Leading & trailing spaces
                    $aNextArrayVal = StringRegExp($sString, '^\s*(["{[]|\d+(?:(?:\.\d+)?[eE]\+\d+)?|true|false|null)', 2)
                    Switch $aNextArrayVal[1]
                        Case '"' ; String
                            ; Value -> Array subscript. Trim String after that.
                            $aRet[$iArIndex] = StringMid($sString, 2, StringInStr($sString, """", 1, 2) - 2)
                            $sString = StringMid($sString, StringLen($aRet[$iArIndex]) + 3)
                        Case "{" ; Object
                            ; Recursive function call which will decode the object and return it.
                            ; Object -> Array subscript. Trim String after that.
                            $aRet[$iArIndex] = _JSON_Decode($sString)
                            $sString = StringMid($sString, @extended + 2)
                        Case "["
                            MsgBox(0, "", "Array in Array. WTF is up with this JSON shit?")
                            MsgBox(0, "", "This should not happen! Please post this!")
                            Exit 0xDEADBEEF
                        Case Else
                            ConsoleWrite("Array Else (maybe buggy?)" & @CRLF)
                            $aRet[$iArIndex] = $aNextArrayVal[1]
                    EndSwitch
                    ReDim $aRet[$iArIndex + 2]
                    $iArIndex += 1
                    $sString = StringStripWS($sString, 3) ; Leading & trailing
                    If StringLeft($sString, 1) = "]" Then ExitLoop
                    $sString = StringMid($sString, 2)
                Until False
                $sString = StringMid($sString, 2)
                ReDim $aRet[$iArIndex]
                $aArray[$iIndex][1] = $aRet
                ReDim $aArray[$iIndex + 2][2]
                $iIndex += 1
            Case Else ; Number, bool
                ; Value (number (int/flaot), boolean, null) -> Array subscript. Trim String after that.
                $aArray[$iIndex][1] = $aVal[2]
                ReDim $aArray[$iIndex + 2][2]
                $iIndex += 1
                $sString = StringMid($sString, StringLen($aArray[$iIndex][1]) + 2)
        EndSwitch
        If StringLeft($sString, 1) = "}" Then
            StringMid($sString, 2)
            ExitLoop
        EndIf
        If Not $b Then $sString = StringMid($sString, 2)
    Until False
    ReDim $aArray[$iIndex][2]
    Return SetError(0, StringLen($sOldStr) - StringLen($sString), $aArray)
EndFunc   ;==>_JSON_Decode

Ah, I forgot the encodedURL is from :

I'm looking forward to see you code.

Posted

I'm looking forward to see you code.

man, this is magic!

What you want to see my code? you did all the work! :)

all credits are your!

thank you very much, this is a very nice code!

this week i finished everything and post it here =)

;)

  • 7 months later...
Posted

golfinhu & Tankbuster

I'm a bit late but an easy way for "expand" shortened Urls is to simply ask for his location

:)

#include <WinHttp.au3>

ConsoleWrite ( 'http://ufy.me/09435 : ' & _WinHttpGetUrlLocation ( 'http://ufy.me/09435' ) & @Crlf )
ConsoleWrite ( 'http://tinyurl.com/294gsxz : ' & _WinHttpGetUrlLocation ( 'http://tinyurl.com/294gsxz' ) & @Crlf )
ConsoleWrite ( 'http://bit.ly/UVtwDe : ' & _WinHttpGetUrlLocation ( 'http://bit.ly/UVtwDe' ) & @Crlf )
ConsoleWrite ( 'http://goo.gl/fpcSB : ' & _WinHttpGetUrlLocation ( 'http://goo.gl/fpcSB' ) & @Crlf )
ConsoleWrite ( 'http://is.gd/kojoX8 : ' & _WinHttpGetUrlLocation ( 'http://is.gd/kojoX8' ) & @Crlf )
ConsoleWrite ( 'http://ow.ly/fCPNc : ' & _WinHttpGetUrlLocation ( 'http://ow.ly/fCPNc' ) & @Crlf )
ConsoleWrite ( 'http://x.co/pyGR : ' & _WinHttpGetUrlLocation ( 'http://x.co/pyGR' ) & @Crlf )
ConsoleWrite ( 'http://gg.gg/zga : ' & _WinHttpGetUrlLocation ( 'http://gg.gg/zga' ) & @Crlf )
ConsoleWrite ( 'http://po.st/YonHpG : ' & _WinHttpGetUrlLocation ( 'http://po.st/YonHpG' ) & @Crlf )
ConsoleWrite ( 'http://tiny.tw/i7m : ' & _WinHttpGetUrlLocation ( 'http://tiny.tw/i7m' ) & @Crlf )

Func _WinHttpGetUrlLocation ( $sUrl )
    Local $hOpen = _WinHttpOpen ( ), $aCrackedUrl = _WinHttpCrackUrl ( $sUrl )
    _WinHttpSetOption ( $hOpen, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_NEVER )
    Local $hConnect = _WinHttpConnect ( $hOpen, $aCrackedUrl[2] )
    Local $hRequest = _WinHttpOpenRequest ( $hConnect, Default, $aCrackedUrl[6] )
    _WinHttpSendRequest ( $hRequest )
    _WinHttpReceiveResponse ( $hRequest )
    Local $sLocation = _WinHttpQueryHeaders ( $hRequest, $WINHTTP_QUERY_LOCATION )
    _WinHttpCloseHandle ( $hRequest )
    _WinHttpCloseHandle ( $hConnect )
    _WinHttpCloseHandle ( $hOpen )
    Return $sLocation
EndFunc ;==> _WinHttpGetUrlLocation ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Posted

Hi,

Can someone explain to me what a link decrypter is supposed to do? :sweating:

a link decrypter is supposed to retrieve the real url of an encrypted url like those who are shortened.

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...