#include <Memory.au3>
#include <WinAPI.au3>
; trancexxx, minx
Opt("GUIOnEventMode", 1)
Local	$iWidth = 480, $iHeight = 270, _								; Bei 16:9 Verhältnis
		$hGUI = GUICreate("480p Rauschen", $iWidth, $iHeight), _
		$hPic = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight), _ 		; Durch Pic bleibt das Bild immer erhalten
		$tBits = DllStructCreate("int[" & $iWidth*$iHeight & "]"), _ 	; Struct mit der maximalen Auflösung
		$pBits = DllStructGetPtr($tBits), _								; Pointer der Struct
		$hBitmap, $aCall, $iHMsg, _										; Container für Zeichnung
		$hPicHandle = GUICtrlGetHandle($hPic), _						; Handle für das Message-Empfangen
		$tRandom = DllStructCreate("dword"), _							; Struct / Pointer für zufällige Farbe
		$pRandom = DllStructGetPtr($tRandom)
; GUI anzeigen und $GUI_EVENT_CLOSE registrieren
GUISetOnEvent(-3, "_Quit")
GUISetState()
; Pointer der verwendeten Funktionen initialisieren, Speicher & Buffer für Anweisungen reservieren
Local 	$pRtlRandomEx = KernelCallNull("ntdll.dll", "RtlRandomEx"), _
		$pRtlMoveMemory = KernelCallNull("kernel32.dll", "RtlMoveMemory"), _
		$pSendMessageW = KernelCallNull("user32.dll", "SendMessageW"), _
		$pDeleteObject = KernelCallNull("gdi32.dll", "DeleteObject"), _
		$pCreateBitmap = KernelCallNull("gdi32.dll", "CreateBitmap"), _
		$pRemoteCode = _MemVirtualAlloc(0, 512, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE), _
		$tCodeBuffer = DllStructCreate("byte[512]", $pRemoteCode)
; Code zusammenstellen (ein wenig aufgeräumt). Direkt-OP erspaart ASM-UDF.
;			OP		Wert								ASM
DllStructSetData($tCodeBuffer, 1, _
			"0x" 	& _									; Hex-Header
			"33DB" 	& _									; XOR ebx, ebx
			"68" 	& Swap($pRandom) & _		  		; PUSH $pRandom
			"B8" 	& Swap($pRtlRandomEx) & _ 			; MOV eax, RtlRandomEx
			"FFD0" 	& _									; CALL eax
			"8BCB" 	& _									; MOV ecx, ebx
			"69C9" 	& "04000000" & _					; IMUL ecx, 4
			"81C1" 	& Swap($pBits) & _		 			; ADD ecx, $pBits
			"68" 	& "03000000" & _			 		; PUSH 3 bytes
			"68" 	& Swap($pRandom) & _		 	 	; PUSH $pRandom
			"51" 	& _							 		; PUSH ecx
			"B8" 	& Swap($pRtlMoveMemory) & _			; MOV eax, RtlMoveMemory
			"FFD0" 	& _									; CALL eax
			"43" 	& _							 		; INC ebx
			"81FB" 	& Swap($iWidth*$iHeight) & _		; CMP ebx, $iWidth * $iHeight
			"75" 	& "CB" & _						  	; JNE -53 bytes
			"68" 	& Swap($pBits) & _					; PUSH $pBits
			"68" 	& "20000000" & _					; PUSH BitsPerPel
			"68" 	& "01000000" & _			 		; PUSH Planes
			"68" 	& Swap($iHeight) & _				; PUSH $iHeight
			"68" 	& Swap($iWidth) & _					; PUSH $iWidth
			"B8" 	& Swap($pCreateBitmap) & _			; MOV eax, CreateBitmap
			"FFD0" 	& _									; CALL eax
			"50" 	& _							 		; PUSH eax
			"68" 	& "00000000" & _			 		; PUSH IMAGE_BITMAP
			"68" 	& "72010000" & _ 					; PUSH $STM_SETIMAGE
			"68" 	& Swap($hPicHandle) & _				; PUSH $hPicHandle
			"B8" 	& Swap($pSendMessageW) & _			; MOV eax, SendMessageW
			"FFD0" 	& _									; CALL eax
			"50" 	& _							 		; PUSH eax
			"B8" 	& Swap($pDeleteObject) & _			; MOV eax, DeleteObject
			"FFD0" 	& _									; CALL eax
			"C3" 	  _									; RET
			)
;
While Sleep(10)
	; Programm aufrufen
	DllCall("user32.dll","int","CallWindowProcW","ptr",$pRemoteCode,"int",0,"int",0,"int",0,"int",0)
	; Keine Angst, ConsoleWrite() dauert nur .2ms im Schnitt
	ConsoleWrite("- Rnd Str Val: " & DllStructGetData($tRandom, 1) & @CRLF)
WEnd
;
Func KernelCallNull($hDll, $sFunction)
	Local $aCall = DllCall("kernel32.dll","ptr","GetProcAddress","ptr",_WinAPI_GetModuleHandle($hDll),"str",$sFunction)
	Return $aCall[0]
EndFunc
;
Func Swap($iV)
	Return Hex(Binary($iV))
EndFunc
;
Func _Quit()
	Exit
EndFunc ;==>_Quit