Hooking UpdateWindow !?

c++ / delphi package - dll injection and api hooking
Post Reply
neji
Posts: 155
Joined: Wed Mar 09, 2005 11:39 am
Contact:

Hooking UpdateWindow !?

Post by neji »

Hello, I want to write Text in a game Window, so i used Textout() and it worked. Because the Gamewindow is updated very often, my text only flickers one time and then disappears. When I use Timer for showing the text, i can read it, but its still flickering.

my Question :

Can I hook the UpdateWindow Function of the game to write my text automatically everytime the window is updated?

I've tried the following :

dll :

Code: Select all

var UpdateWindowHookNext : function (HWND : Cardinal) : Boolean; stdcall;

function UpdateWindowHookProc(HWND : Cardinal) : Boolean; stdcall;
var
  myDC : HDC;
begin
  myDC := GetDC(HWND);
  SetBkColor(myDC,RGB(0,0,0));
  SetBkMode(myDC, TRANSPARENT);
  SetTextColor(myDC,RGB(255,0,0));
  TextOut(myDC,10,5,'Hallo Welt',StrLen('Hallo Welt'));
  ReleaseDC(HWND,myDC);
  result := UpdateWindowHookNext(HWND);
end;

begin
HookAPI(user32,'UpdateWindow',@UpdateWindowHookProc,@UpdateWindowHookNext);
end.
application :

Code: Select all

uses madCodeHook, madKernel;

procedure TForm1.btnClick(Sender: TObject);
begin
  if process('appname.exe').IsValid then
    if InjectLibrary(PROCESS('appname.exe').Handle.Handle,'UpdateWindowHook.dll') then
      showmessage('injected');
end;

procedure TForm1.btnasdfClick(Sender: TObject);
begin
  UninjectLibrary(PROCESS('appname.exe').Handle.Handle,'UpdateWindowHook.dll');
end;
The Dll is injected fine in the game but i see nothing on the screen :(
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

The big question is: How does the game paint the screen? If it's using BitBlt, you should probably be hooking BitBlt. UpdateWindow is not the right API in this case, I'd say. You need to hook that API which the game uses the draw the screen - whatever that API is (I don't know).
neji
Posts: 155
Joined: Wed Mar 09, 2005 11:39 am
Contact:

Post by neji »

ive disassembled the game with w32dasm and looked into the imported functions....the only one, that could be used for repainting is UpdateWindow :(
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

UpdateWindow doesn't repaint anything. It just sends WM_PAINT messages. As a result of those messages the window gets redrawn. But the real redrawing is done with other APIs.
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

madshi wrote:UpdateWindow doesn't repaint anything. It just sends WM_PAINT messages. As a result of those messages the window gets redrawn. But the real redrawing is done with other APIs.
Maybe DirectX nor OpenGL?
Post Reply