Solved

Patch *TWOWORDINLINE*  function

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now