Hoocking TObjectList.GetItem

c++ / delphi package - dll injection and api hooking
Post Reply
Hechicero
Posts: 4
Joined: Thu Jul 29, 2004 4:31 pm

Hoocking TObjectList.GetItem

Post by Hechicero »

Hi,
I really need help. I want to hook a protected Method. In particular TObjectList.GetItem. I tried many things but I couldnt do it.
Help please!

Esteban Calabria.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Here's some code about how I'm hooking TListView.UpdateColumn, which also is a protected method:

Code: Select all

var UpdateColumnNextHook : procedure (Self: TObject; index: integer) = nil;

procedure UpdateColumnHookProc(Self: TObject; index: integer);
begin
  if (Self is TDBListView) and (TDBListView(Self).FDB <> nil) then
       TDBListView(Self).HackedUpdateColumn(index)
  else UpdateColumnNextHook(Self, index);
end;

constructor TDBListView.Create(AOwner: TComponent);
begin
  if @UpdateColumnNextHook = nil then
    HookCode(@TDBListView.UpdateColumn, @UpdateColumnHookProc, @UpdateColumnNextHook);
  inherited;
end;
Does that help? Basically you have to add a first "Self: TObject" parameter, because methods always have that (but it's hidden).
Hechicero
Posts: 4
Joined: Thu Jul 29, 2004 4:31 pm

Post by Hechicero »

The problem is that the method getItem from TObjectList is protected. If I create a descendent class and hook the super class procedure I get an Unidentified Identifier getItems

This doesnt work for instance. Neither inside a TObjListFriens(TObjectList) or in anyplace outside TObjectList unit

constructor TObjListFriend.Create;
begin
HookCode(@TObjectList.GetItem,@MyGetItem,@f);
end;


I want to be hable to do something like

constructor TObjListFriend.Create;
begin
HookCode(@inherited GetItem,@MyGetItem,@f);
end;
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

This compiles fine for me:

Code: Select all

type
  TObjListFriends = class (TObjectList)
  end;

initialization
  HookCode(@TObjListFriends.GetItem, ...
If you don't overwrite the protected method, then TObjListFriends.GetItem is exactly the method that you want to hook.
Hechicero
Posts: 4
Joined: Thu Jul 29, 2004 4:31 pm

Thanks

Post by Hechicero »

Thanks! It seems that works!!!
Post Reply