uses typinfo;
function getwindowLongEx(hProcess:THandle;wnd:hwnd):cardinal;
const Procsize=200;
type PPThread=^TPThread;
TPThread=packed
record
Proc:
array[0..Procsize-1]
of char;
wndproc:cardinal;
wnd:hwnd;
getWindowLong:
function(wnd:hwnd;param:integer):cardinal;
stdcall;
end;
function RemoteThread(param:PPThread):integer;
stdcall;
begin
param^.wndproc:=param^.getWindowLong(param^.wnd,gwl_wndproc);
result:=0;
end;
procedure dispRT;
asm nop
end;
var lib:hmodule;
PThread:TPThread;
mThread:PPThread;
source:pointer;
ThreadID,temp:cardinal;
hThread:THandle;
begin
source:=@RemoteThread;
move(source^,PThread.Proc[0],integer(@dispRT)-integer(source));
lib:=getmodulehandle('
user32.dll');
PThread.getWindowLong:=getprocaddress(lib,'
GetWindowLongA');
Pthread.wnd:=wnd;
PThread.wndproc:=0;
mThread:=virtualallocEx(hProcess,
nil,sizeof(TPThread),MEM_Commit
or MEM_Reserve,Page_Execute_READWrite);
writeprocessmemory(hProcess,mThread,@PThread,sizeof(TPThread),temp);
hThread:=createremotethread(hProcess,
nil,0,mThread,mThread,0,ThreadID);
if waitforsingleobject(hThread,2000)=Wait_Object_0
then
begin
readprocessmemory(hProcess,mThread,@PThread,sizeof(TPThread),temp);
result:=PThread.wndproc;
closehandle(hThread);
virtualfreeEx(hProcess,mThread,0,Mem_Release);
end else
result:=0;
end;
function changeProperty(wnd:hwnd;AClass:TClass;PropName:
string;Value:Integer):boolean;
type TSetProc=packed
record
case Boolean
of
TRUE:(SetProc:Pointer);
FALSE:(Pos:word; Ident:Word);
end;
var wndproc:cardinal;
obj,inst:pointer;
setp:TSetProc;
hProcess:Thandle;
PID,temp:Cardinal;
begin
getwindowthreadProcessID(wnd,PID);
try
hProcess:=openprocess(Process_ALL_ACCESS,false,PID);
if hProcess<>0
then
begin
try
wndProc:=getwindowlongEx(hProcess,wnd);
obj:=pointer(wndproc+9);
setp.SetProc:=getpropinfo(AClass,PropName).SetProc;
if setp.ident<>$FF00
then setp.SetProc:=getpropinfo(AClass,PropName).GetProc;
if setp.ident=$FF00
then
begin
if readprocessmemory(hProcess,obj,@inst,4,temp)
then
begin
inst:=pointer(cardinal(inst)+setp.Pos);
result:=writeProcessMemory(hProcess,inst,@value,4,temp);
end else
result:=false;
end else
result:=false;
finally
closehandle(hProcess);
end;
end else
result:=false;
except
result:=false;
end;
end;