TCode = Record
LoadLib: function( lpLibFileName: PChar): Cardinal; stdcall;
GetProc: function( hModule: Cardinal; lpProcName: pAnsiChar ): Pointer; stdcall;
Param1, Param2, // 1 =
opengl.dll | 2 = glPolygonMode
Param3, // 3 = glClearColor
Param4, Param5, // 5 = user32.dll | 6 = MessageBoxA
Param6, Param7, // 7 = kernel32.dll | 8 = Sleep
Messag: Array[Byte] of Char;
Poly1, Poly2, // 1 = gl_Front_and_Back | 2 = gl_Line }
Sleep: Cardinal;
ClCol: Single;
End;
---
function CODE(P: Pointer): Cardinal; stdcall;
var
Code: TCode;
hDLL: Cardinal;
glPolygonMode: procedure(face: Cardinal; mode: Cardinal); stdcall;
glClearColor: procedure(red: Single; green: Single; blue: Single; alpha: Single); stdcall;
MessageBox: function (hWnd: Cardinal; lpText, lpCaption: PChar;
uType: Cardinal): Integer; stdcall;
Sleep: procedure( ms: Cardinal ); stdcall;
begin
Code := TCode(P^);
hDLL := Code.LoadLib( @Code.Param1[0] );
glPolygonMode := Code.GetProc( hDLL, @Code.Param2[0] );
glClearColor := Code.GetProc( hDLL, @Code.Param3[0] );
hDLL := Code.LoadLib( @Code.Param4[0] );
MessageBox := Code.GetProc( hDLL, @Code.Param5[0] );
MessageBox( 0, @Code.Messag[0], @Code.Param1[0], 0 );
hDLL := Code.LoadLib( @Code.Param6[0] );
Sleep := Code.GetProc( hDLL, @Code.Param7[0] );
while True do
begin
glClearColor( Code.ClCol, Code.ClCol, Code.ClCol, Code.ClCol );
glPolygonMode( Code.Poly1, Code.Poly2 );
Sleep(Code.Sleep);
end;
end;
function CODEEND: Cardinal;
begin
end;
procedure injectCODE(const WindowTitle: String);
var
hProcess,
PID, WB : Cardinal;
Mem: Pointer;
hDll, cs: Cardinal;
code: TCode;
begin
{ermittle code size}
cs := IntegeR(@CodeEnd)-Integer(@Code);
ZeroMemory( @code, SizeOf( TCode ) );
{bereite parameter vor}
with code do
begin
hDll := LoadLibrary( 'kernel32.dll' );
LoadLib := windows.GetProcAddress( hDLL, 'LoadLibraryA' );
GetPRoc := windows.GetProcAddress( hDLL, 'GetProcAddress' );
Move( 'OpenGl32.dll'#0, Param1, 12 );
Move( 'glPolygonMode'#0, Param2, 14 );
Move( 'glClearColor'#0, Param3, 13 );
Poly1 := gl_Front_and_Back;
Poly2 := gl_Line;
Move( 'User32.dll'#0, Param4, 11 );
Move( 'MessageBoxA'#0, Param5, 12 );
Move( 'Injection was successfull'#0, Messag, 26 );
Move( 'Kernel32.dll'#0, Param6, 13 );
Move( 'Sleep'#0, Param7, 6 );
ClCol := 0.0;
Sleep := 10;
end;
{injecten:}
GetWindowThreadProcessId( FindWindow(0, pChar(WindowTitle)), PID );
if PID = 0 then
Exit;
hProcess := OpenProcess( PROCESS_ALL_ACCESS, False, PID );
if hProcess = 0 then
Exit;
try
Mem := VirtualAllocEx( hProcess, nil, SizeOf(TCode) + cs, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
{ MEM: <PARAMETER BLOCK> <CODE BLOCK> }
WriteProcessMemory( hProcess, Mem, @code, SizeOf( TCode ), WB );
WriteProcessMemory( hProcess, Pointer(Integer(Mem)+SizeOf( TCode ) ), @Code, cs, WB );
CreateRemoteThread( hProcess, Nil, 0, Pointer(IntegeR(Mem) + SizeOf( TCode) ), Mem ,0, wb );
finally
CloseHandle( hProcess );
end;
end;