Solved

Patch *TWOWORDINLINE*  function

Posted on 1997-01-16
1
555 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 200 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

iCloud Drive was introduced after iOS 8 was launched last year. This drive is Apple’s online storage device that lets users sync their files and access them from all their Apple devices.   There is a lot of data that is not automatically backed up…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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