You last visited: Today at 10:35
Advertisement
Help With _WinAPI_CreateProcess
Discussion on Help With _WinAPI_CreateProcess within the AutoIt forum part of the Coders Den category.
02/15/2014, 18:20
#1
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
Help With _WinAPI_CreateProcess
Hi all i'm working on an own LolLauncher to run as many clients as i want, but i have problems with _WinAPI_CreateProcess.
The Launcher is a server that accept a conection of a client, then recv packets from it and response.
Can't make it work as the Original Launcher.
Here's the code:
Code:
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <WinAPI.au3>
Func ArrayofByte($binary)
Local $binaryLen = StringLen($binary) -2
Local $ArrayLen = ($binaryLen/2)
Local $string = ""
Local $mid = 3
Local $n = 1
If (Mod($binaryLen,2) = 0) Then
For $i = 0 To $ArrayLen
$n+=1
If $n > 1 Then
$string = $string & StringMid($binary,$mid,2) & " "
$n = 1
Else
$string = $string & StringMid($binary,$mid,2)
EndIf
$mid +=2
Next
Return $string
Else
Return -1
EndIf
EndFunc
Func Translate($binary)
$binary = ArrayofByte($binary)
$mid = 1
Local $result = ""
$len = stringlen($binary)
For $i = 0 to $len
$str=StringMid($binary,$mid,2)
$str=Int("0x"&$str)
If $str >20 Then
If $i = 12 Then
If Chr($str) = 2 Or Chr($str) = 1 Then
$result = $result & " "
EndIf
Else
$result = $result & Chr($str)
EndIf
EndIf
$mid+=3
Next
Return $result
EndFunc
Global $edit
Main()
Func Main()
Local $tSTARTUPINFO = DllStructCreate($tagSTARTUPINFO)
Local $DETACHED_PROCESS = 0x00000008
Local $tPROCESS_INFORMATION = DllStructCreate($tagPROCESS_INFORMATION)
_WinAPI_CreateProcess("C:\Program Files (x86)\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\0.0.1.71\deploy\LolClient.exe"," -runtime .\ -nodebug META-INF\AIR\application.xml .\ -- 8393",0,0,False,$DETACHED_PROCESS,0,0,DllStructGetPtr($tSTARTUPINFO),DllStructGetPtr($tPROCESS_INFORMATION))
Local $szIPADDRESS = "127.0.0.1"
Local $nPORT = 8393 ;we listen at port 8393 since LolClient will try to connect to that port
Local $ClientSocket, $Client, $szIP_Accepted,$LSocket,$League
Local $msg, $recv
TCPStartup()
$ClientSocket = TCPListen($szIPADDRESS, $nPORT)
; If the Socket creation fails, exit.
If $ClientSocket = -1 Then Exit
GUICreate("LolLauncher Test", 300, 200, 100, 100)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
GUISetState()
$Client = -1
;Wait for and Accept a connection
Do
$Client = TCPAccept($ClientSocket)
Until $Client <> -1
; Get IP of client connecting
$szIP_Accepted = SocketToPort($Client)
GUICtrlSetData($edit,"Client connected port: "&$szIP_Accepted)
While 1
$msg = GUIGetMsg()
; GUI Closed
;--------------------
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
;all messages are sent in 16 bytes long
$recv = TCPRecv($Client, 16,1)
; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
If @error Then ExitLoop
If StringLen($recv) > 0 Then ;if we received data
DecodePacket($recv,$Client)
EndIf
WEnd
If $Client <> -1 Then TCPCloseSocket($Client)
TCPShutdown()
EndFunc
Func SocketToIP($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
Return $aRet
EndFunc ;==>SocketToIP
Func SocketToPort($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "ushort", "ntohs", "ushort", DllStructGetData($sockaddr, 2))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
Return $aRet
EndFunc ;==>SocketToPort
Func DecodePacket($RecvData,$socket)
Switch ($RecvData)
Case "0x10000000010000000400000000000000"
GUICtrlSetData($edit,"Alive Packet received, response sent")
SendOk($socket)
Case "0x10000000010000000000000031000000"
GUICtrlSetData($edit,"Received Launch Client Waiting buffer")
Do
$rec = TCPRecv($socket,255,1);we will receive the League of Legends Parameters
$traduccion = Translate($rec)
GUICtrlSetData($edit,"Received command: "&$traduccion)
Until StringLen($rec) > 0
SendOk($socket)
LaunchAndAcceptConection($traduccion)
Case "0x10000000010000000000000032000000"
GUICtrlSetData($edit,"Received Launch Client Waiting buffer")
Do
$rec = TCPRecv($socket,255,1)
$traduccion = Translate($rec)
GUICtrlSetData($edit,"Received command: "&$traduccion)
Until StringLen($rec) > 0
SendOk($socket)
LaunchAndAcceptConection($traduccion)
Case "0x10000000010000000000000033000000"
GUICtrlSetData($edit,"Received Launch Client Waiting buffer")
Do
$rec = TCPRecv($socket,255,1)
$traduccion = Translate($rec)
GUICtrlSetData($edit,"Received command: "&$traduccion)
Until StringLen($rec) > 0
SendOk($socket)
LaunchAndAcceptConection($traduccion)
EndSwitch
EndFunc
Func LaunchAndAcceptConection($param)
$process = "C:\Program Files (x86)\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.9\deploy\League of Legends.exe"
$format = StringFormat("""C:\Program Files (x86)\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.9\deploy\League of Legends.exe "" ""8394"" ""LolLauncher.exe"" ""C:\Program Files (x86)\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\0.0.1.71\deploy\LolClient.exe"" ""%s""",$param)
$WorkingDir = "C:\Program Files (x86)\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.9\deploy"
Local $tSTARTUPINFO = DllStructCreate($tagSTARTUPINFO)
Local $DETACHED_PROCESS = 0x00000008
Local $tPROCESS_INFORMATION = DllStructCreate($tagPROCESS_INFORMATION)
_WinAPI_CreateProcess($process,$format,0,0,False,$DETACHED_PROCESS,0,$WorkingDir,DllStructGetPtr($tSTARTUPINFO),DllStructGetPtr($tPROCESS_INFORMATION))
#cs
Local $oPORT = 8394
Local $szIPADDRESS = "127.0.0.1",$LeagueLegends
Local $LeagueSocket = TCPConnect($szIPADDRESS, $oPORT)
TCPSend($LeagueSocket,"0x10000000010000000400000000000000")
#ce
EndFunc
Func SendWhatsUp($socket)
$data="0x10000000010000000400000000000000"
TCPSend($socket,$data)
EndFunc
Func SendOk($socket)
$data = "0x10000000010000000500000000000000"
TCPSend($socket,$data)
EndFunc
And here Images from ollydbg:
Original Launcher calling CreateProcess
Stack Info before Creating the Process:
CommandLine Sent:
Now Mine Launcher
Stack Info before Creating Process:
CommandLine in dump:
Don't Know why these is up there:
Why the parameters i sent to CreateProcess looks like crap? or are incomplete, Please i need a reply to continue with this
02/15/2014, 18:41
#2
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
instead of overblowing the script with stuff, you won't be able to use for now, you should to to keep it as simple as possible...
first of all, why do you need to use createprocess?
there are way more easy alternatives (like run or shellexecute)... since they are native autoit code, they will be more performant btw :P
2nd hint for you as a threadstarter:
give a short explanation of what you're actually tryin to do... all you told us were some ideas which got nothing to do with the problem.
instead of pasting dozens of pictures (which are absolutely useless for non lol players), you might just name the problem in a single word or phrase...
02/15/2014, 20:35
#3
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
Quote:
Originally Posted by
lolkop
instead of overblowing the script with stuff, you won't be able to use for now, you should to to keep it as simple as possible...
first of all, why do you need to use createprocess?
there are way more easy alternatives (like run or shellexecute)... since they are native autoit code, they will be more performant btw :P
2nd hint for you as a threadstarter:
give a short explanation of what you're actually tryin to do... all you told us were some ideas which got nothing to do with the problem.
instead of pasting dozens of pictures (which are absolutely useless for non lol players), you might just name the problem in a single word or phrase...
cause with run i had the same problem :/
All times are GMT +2. The time now is 10:35 .