SetFunction()

6 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 2 years 6 months ago
Joined: 2014-04-21 21:15
SetFunction()

I am trying to use IExec->SetFunction() but can't seem to get it to work.

  1. VOID
  2. SetUpSetFunction()
  3. {
  4. IExec->Forbid();
  5. OldOpenWorkbenchObject=(ULONG)IExec->SetFunction(WorkbenchBase,(long)-0x60,(unsigned long (*)())WEOpenWorkbenchObject);
  6. IExec->Permit();
  7. }
  8.  
  9.  
  10. BOOL
  11. WEOpenWorkbenchObject(STRPTR Name,Tag tag1,...)
  12. {
  13. IDOS->Printf("WEOpenWorkbenchObject() %s\n",Name);
  14.  
  15. return(TRUE);
  16. }
  17.  
  18.  
  19. VOID
  20. ShutDownSetFunction()
  21. {
  22. if (!OldOpenWorkbenchObject)
  23. return;
  24.  
  25. IExec->Forbid();
  26. IExec->SetFunction(WorkbenchBase,(long)-0x60,(unsigned long (*)())OldOpenWorkbenchObject);
  27. IExec->Permit();
  28. }

I want to catch when someone opens a Workbench window (double click on DH0: icon or a drawer) to open my own window. The offset is from the pragmas. The examples I found use both positive and negative values. Tried both.

Is "OpenWorkbenchObjectA" the correct function to be patching?

I tried to also patch DisplayBeep() from IntuitionBase to make sure it was the right function to patch. Can't get that to work either.

Any ideas? OS4 examples?

salass00
salass00's picture
Offline
Last seen: 7 months 1 day ago
Joined: 2011-02-03 11:27
SetFunction() is only for

SetFunction() is only for patching the legacy 68k jumptable of a library (code passed in must be 68k code or a trap instruction that redirects to a PPC function). SetFunction() is only really useful if the library you want to patch is 68k-only or if for some reason you want your patch to only apply to 68k programs using the library.

To patch PPC interfaces you need to use SetMethod().

Also all standard PPC library functions have a "hidden" first parameter which is the interface pointer (don't forget to add this) and if the function is a varargs function you need to use VARARGS68K in the function definition.

salass00
salass00's picture
Offline
Last seen: 7 months 1 day ago
Joined: 2011-02-03 11:27
For some examples on how to

For some examples on how to use SetMethod() you can look at the td64patch and sashimi source codes:

http://os4depot.net/index.php?function=showfile&file=driver/storage/td64patch.lha
http://os4depot.net/index.php?function=showfile&file=development/debug/sashimi.lha

AND
AND's picture
Offline
Last seen: 7 years 6 months ago
Joined: 2011-01-20 12:22
OpenWorkbenchObject() is not

OpenWorkbenchObject() is not what you are looking for.
Take a look at the workbench.library autodoc.
Workbench opens its windows via Intuition OpenWindow() passing a NewWindow struct.
So if you want to intercept opening a WB window, you need to patch OpenWindow() and check for the flags (look at intuition.h, struct Window/struct NewWindow) and the caller.

But this is by no means recommended to do. It is a hack.

SetFunction() was originally designed to fix bugs, when the OS was still in ROM. And this is done by SetPatch().
SetFunction()/SetMethod() is not meant for (3rd party) developers.

mritter0
mritter0's picture
Offline
Last seen: 2 years 6 months ago
Joined: 2014-04-21 21:15
I got it working with some

I got it working with some functions for testing (DisplayBeep()).

OpenWindow, OpenWindowTagList, and OpenWindowTags do not catch opening of Workbench windows.

xenic
xenic's picture
Offline
Last seen: 2 years 7 months ago
Joined: 2011-05-07 04:52
@mritter

@mritter
I don't think patching a system library is a good idea or even necessary. Check out the Intuition function "StartScreenNotifyTags()". If you set the screen to WorkBench with the SNA_Pubname tag and then set the notification type with the SNOTIFY_AFTER_OPENWINDOW, you should get notification when Workbench opens a window. I haven't used it myself but there is no reason it shouldn't work.

X1000 - OS 4.1FE

Log in or register to post comments