But since a session is terminated anyway when the script closes, this shouldn't be a problem right?
The option could help if you put your computer into sleep or hibernate without closing the script, so the script would still run if you turn on the computer 2 days later.
Sure, it's your forum.
In fact I think that you should definitely change the login/sign up so that standard phpBB spam bots can't login anymore.
For these kinds of logins it can help a lot to learn javascript. The ajax function of jquery is pretty much based on XmlHttpRequest which is extremely similar (if not the same) as WinHttpRequest.
In rare cases (in some flash games) the http requests are actually sent through the swf files without any javascript.
For these cases you could learn some ActionScript and decompile the swf with one of the many decompilers available or you have to reverseengineer it by looking at Fiddler's log.
I have actually done that before. But it's not possible using WinHttpRequest since the functions are expecting null-terminated strings.
I had to build a new HTTPRequest function from scratch involving a ton of complicated DLL-Calls.. But Lexikos helped me A LOT with this. But the function is still not finished... For example I definitely need to add an option to download/upload files in chunks so that there are no problems on low-RAM computers.
Code: Select all
HttpRequest(url,method:="",headers:="",ByRef body:="",proxy:="",pExcludeList:="",httpVersion:="",sessionOptions:="",requestOptions:="") {
;Makes working with the msdn functions easier
static LPCWSTR:="UPTR"
static DWORD:="UInt"
static LPCVOID:="UPTR"
static LPDWORD:="UPTR"
static HINTERNET:="UPTR"
static INTERNET_PORT:="UShort"
static DWORD_PTR:="UPTR"
static LPVOID:="UPTR"
static NULL := 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Not supported so far
asynch := False
VarSetCapacity(callbackValue,A_PtrSize)
;;;;;;;;;;;;;;;;;;;;;
;Crack URL to use it's segments in the upcomming DllCalls
VarSetCapacity(myStruct,60,0)
numput(60,myStruct,0,"Uint") ; this dll function requires this to be set
numput(1,myStruct,8,"Uint") ; SchemeLength
numput(1,myStruct,20,"Uint") ; HostNameLength
;numput(1,myStruct,32,"Uint") ; UserNameLength
;numput(1,myStruct,40,"Uint") ; PasswordLength
numput(1,myStruct,48,"Uint") ; UrlPathLength
numput(1,myStruct,56,"Uint") ; ExtraInfoLength
DllCall("Winhttp.dll\WinHttpCrackUrl","PTR",&url,"UInt",StrLen(url),"UInt",0,"PTR",&myStruct)
scheme := StrGet(NumGet(myStruct,4,"Ptr"),NumGet(myStruct,8,"UInt"))
;userName := StrGet(NumGet(myStruct,28,"Ptr"),NumGet(myStruct,32,"UInt"))
;password := StrGet(NumGet(myStruct,36,"Ptr"),NumGet(myStruct,40,"UInt"))
hostName := StrGet(NumGet(myStruct,16,"Ptr"),NumGet(myStruct,20,"UInt"))
port := NumGet(myStruct,24,"Int")
urlPath := StrGet(NumGet(myStruct,44,"Ptr"),NumGet(myStruct,48,"UInt"))
extraInfo := StrGet(NumGet(myStruct,52,"Ptr"),NumGet(myStruct,56,"UInt"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Make the url parts usable
If (scheme = "https") {
port := (port) ? port : 443
https := True
} Else
https := False
resource := urlPath . extraInfo
;;;;;;;;;;;;;;;;;;;;;;;;;;
;Parse headers and convert them to be usable
addHeaders := ""
acceptedTypes := []
For header, value in headers
{
If (header = "User-Agent")
userAgent := value
Else If (header = "Referer")
referrer := value
Else If (header = "Accept") {
Loop, parse, acceptedTypes, `;
acceptedTypes.Insert(value)
} Else If (header = "Content-Length")
bodySize := value
Else
addHeaders .= header . ": " . value . "`r`n"
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Parse proxy exclude list and make it usable
proxyBypassString := ""
Loop, % pExcludeList.MaxIndex()
proxyBypassString .= pExcludeList[A_Index] . ";"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Initialize WinHttp application
hSession := DllCall("Winhttp.dll\WinHttpOpen"
,LPCWSTR,&userAgent
,DWORD, (proxy) ? 3 : 1
,LPCWSTR,&proxy
,LPCWSTR,(pExcludeList) ? pExcludeList : NULL
,DWORD,asynch)
If (!hSession)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"WinHttp initialization failed"} ;Msgbox,, hSession, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Set session options
For optionKey, optionValue in sessionOptions
{
oResult := DllCall("Winhttp.dll\WinHttpSetOption"
,HINTERNET,hConnect
,DWORD,optionKey
,LPVOID,&optionValue
,DWORD,StrLen(optionValue))
If !(oResult)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Setting session option #" . A_Index . " failed"}
}
;;;;;;;;;;;;;;;;;;;;
;Specify target server
hConnect := DllCall("Winhttp.dll\WinHttpConnect"
,HINTERNET,hSession
,LPCWSTR,&hostName
,INTERNET_PORT,port
,DWORD,0)
If (!hConnect)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Creating connect handle failed"} ;Msgbox,, hConnect, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;
;Create request handle
hRequest := DllCall("Winhttp.dll\WinHttpOpenRequest"
,HINTERNET,hConnect
,LPCWSTR,(method) ? &method : NULL
,LPCWSTR,(resource) ? &resource : NULL
,LPCWSTR,(httpVersion) ? &httpVersion : NULL
,LPCWSTR,(referrer) ? &referrer : NULL
,LPCWSTR,(acceptedTypes.MaxIndex()) ? &acceptedTypes : NULL
,DWORD,(https) ? 0x00800000 : NULL)
If (!hRequest)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Creating request handle failed"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;
;Set request options
For optionKey, optionValue in requestOptions
{
oResult := DllCall("Winhttp.dll\WinHttpSetOption"
,HINTERNET,hConnect
,DWORD,optionKey
,LPVOID,&optionValue
,DWORD,StrLen(optionValue))
If !(oResult)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Setting request option #" . A_Index . " failed"}
}
;;;;;;;;;;;;;;;;;;;;
;Send request to server
bResults := DllCall("Winhttp.dll\WinHttpSendRequest"
,HINTERNET,hRequest
,LPCWSTR,&addHeaders
,DWORD,StrLen(addHeaders)
,LPVOID,&body
,DWORD,(bodySize) ? bodySize : StrLen(body)*2
,DWORD,(bodySize) ? bodySize : StrLen(body)*2
,DWORD_PTR,&callbackValue)
If (!bResults)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Sending the request failed"} ; Msgbox,, bResults 1, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;
;Receive server response
bResults := DllCall("Winhttp.dll\WinHttpReceiveResponse"
,HINTERNET,hRequest
,LPVOID,NULL)
If (!bResults)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Receiving server response failed"} ; Msgbox,, bResults 1, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;;;
;Receive the response body
responseBody := ""
VarSetCapacity(dwDownloaded,8)
Loop {
dwSize := 0
If (!DllCall("Winhttp.dll\WinHttpQueryDataAvailable"
,HINTERNET,hRequest
,LPDWORD,&dwSize)) {
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Getting info about available response data failed"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
} Else
dwSize := Asc(dwSize)
If (!dwSize)
Break
VarSetCapacity(pszOutBuffer,Asc(dwSize)+1,0)
If (!DllCall("Winhttp.dll\WinHttpReadData"
,HINTERNET,hRequest
,LPVOID,&pszOutBuffer
,DWORD,dwSize
,LPDWORD,&dwDownloaded)) {
MsgBox % "error:" A_LastError
} Else {
Loop, % Asc(dwDownloaded)
responseBody .= Chr(NumGet(&pszOutBuffer,A_Index-1,"UChar"))
}
If (!dwDownloaded)
break
If (dwSize <= 0)
Break
}
;;;;;;;;;;;;;;;;;;;;;;;;;;
;Receive response headers
dwSize := 0
bResults := DllCall("Winhttp.dll\WinHttpQueryHeaders"
,HINTERNET,hRequest
,DWORD,22 ;raw
,LPCWSTR, NULL
,LPVOID, NULL
, "UIntP", dwSize
;,LPDWORD, &dwSize
,LPDWORD, NULL)
If (!bResults && A_LastError != 122) ; allow function to proceed if it was a buffer size error
Return % {Body:responseBody,Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Getting the size of the response headers failed"}
If (A_LastError = 122) { ;buffer too small
;lpOutBuffer := new WCHAR[dwSize/sizeof(WCHAR)]
VarSetCapacity(lpOutBuffer, dwSize, 0)
bResults := DllCall("Winhttp.dll\WinHttpQueryHeaders"
,HINTERNET,hRequest
,DWORD,22 ;raw
,LPCWSTR,NULL
,LPVOID, &lpOutBuffer
,"UIntP", dwSize
,LPDWORD, NULL)
}
If (!bResults)
Return % {Body:responseBody,Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Receiving responseheaders failed"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
VarSetCapacity(lpOutBuffer, -1) ; update the internal string length - otherwise script will crash
;;;;;;;;;;;;;;;;;;;;;;;;;
;Parse received statusline and request headers
responseHeaders := Object()
requestLine := Array()
Loop, parse, lpOutBuffer, `n, `r
{
If (!A_LoopField)
Continue
If (A_Index = 1) {
Loop, parse, A_LoopField, %A_Space%
requestLine[A_Index] := A_LoopField
} Else
responseHeaders.Insert(SubStr(A_LoopField,1,InStr(A_LoopField,": ")-1), SubStr(A_LoopField,InStr(A_LoopField,": ")+2))
}
responseHttpVersion := requestLine[1]
statusCode := requestLine[2]
statusText := requestLine[3]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If (A_LastError || ErrorLevel)
Return % {Body:responseBody,Headers:responseHeaders,StatusCode:statusCode,StatusText:statusText,HttpVersion:responseHttpVersion,Error:"An error occurred"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
Return % {Body:responseBody,Headers:responseHeaders,StatusCode:statusCode,StatusText:statusText,HttpVersion:responseHttpVersion,Error:""}
}
Well, I used the function to upload pictures to 250kb.de and normal files to zippyshare.com
But this involved using content-disposition in the body and was pretty complicated stuff until I managed to automate it:
Then I just had to reverse engineer the sites a little bit to find out what content-disposition parameters they were expecting and I ended up with this:
edit: corrected some code mistakes. also edited the first post and removed the content-length headers