?
Solved

Patch *TWOWORDINLINE*  function

Posted on 1997-01-16
1
Medium Priority
?
566 Views
Last Modified: 2012-06-27
I want to patch a MacOS function which is declared like this:
   extern ... MacOSFunction(...)
      TWOWORDINLINE(...,...);
With *ONEWORDINLINE* functions, I known I must use Get/SetToolTrapAddress(). But for *TWO/THREEWORDINLINE functions, how can I do ?
0
Comment
Question by:bod
1 Comment
 

Accepted Solution

by:
mummu earned 400 total points
ID: 1535223
When a function is declared as ONEWORDINLINE, that word is a reference to an A-Trap. As you are aware, Get/SetToolTrapAddress retrieves or sets the function pointer referenced by that A-Trap.

Some toolbox functions, however, do not have individual trap words but are referenced through a subsidiary dispatch function. This is very common with File Manager routines, for example.

When such a function is called, what actually happens is that a "selector" is pushed onto the stack and then the A-Trap of a selector dispatch routine is called. That dispatch routine then looks at the selector and determines what subsidiary function to call.

This is what a TWOWORDINLINE function is. The first word is the selector code that gets pushed onto the stack. The second is the A-trap of the dispatch routine.

For example, PBGetCatInfoSync is declared as TWOWORDINLINE {0x7009, 0xA260}

0x7009 is the selector code and
0xA260 is the _HFSDispatch A-trap.

When the routine is called, it pushes 0x7009 onto the stack and then jumps to the address referenced by _HFSDispatch. _HFSDispatch then looks at the selector code and dispatches the call to the PBGetCatInfoSync call as appropriate.

Most of the HFS PB calls are actually calls to _HFSDispatch.

In this case, on a 68K machine, you can patch _HFSDispatch, check to see if the selector code is the one you're interested in, do what you need to do, and then pass anything else on to the old _HFSDispatch. This should work with any TWOWORDINLINE functions.

However, InsideMac: PPC System Software states that it isn't possible to individually patch selector-based functions on a PowerPC so if you have to do this, you should write it in 680x0 code.

In general, patching a TWOWORDINLINE function is fairly risky and you must be very careful when doing it. If at all possible, you should try to find an alternative way to do it.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create a default user profile for Mac OS X 10.7/10.8 Create a user account on OS X that will be a template for every other user of that computer. I usually call it “profile” and make it an administrator account for the time being. 1. Install a…
Set up iPhone and iPad email signatures to always send in high-quality HTML with this step-by step guide.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question