Solved

Patch *TWOWORDINLINE*  function

Posted on 1997-01-16
1
550 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

17 Experts available now in Live!

Get 1:1 Help Now