home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-12 | 8.1 KB | 395 lines | [TEXT/R*ch] |
- /* NAME:
- UninstallCode.c
-
- WRITTEN BY:
- Dair Grant
-
- DESCRIPTION:
- Routines for uninstalling various code resources.
-
- ___________________________________________________________________________
- */
- //=============================================================================
- // Include files
- //-----------------------------------------------------------------------------
- #include <Gestalt.h>
- #include <Timer.h>
- #include "ES.h"
- #include "ES Address Table.h"
- #include "ExtensionShell.h"
- #include "UninstallCode.h"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Private function prototypes
- //-----------------------------------------------------------------------------
- void UninstallTrapPatch(short i);
- void UninstallGestaltSelector(short i);
- void UninstallShutdownTask(short i);
- void UninstallVBLTask(short i);
- void UninstallLowMemFilter(short i);
- void UninstallCodeBlock(short i);
- void UninstallTimeManagerTask(short i);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Global variables
- //-----------------------------------------------------------------------------
- extern ESParamBlock gTheParamBlock;
- extern ESAddressTable *gTheESAddressTable;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallCode : Try and uninstall a code resource from gTheParamBlock.
- //-----------------------------------------------------------------------------
- void UninstallCode(short i)
- {
-
-
- // Case out on the type of the code, and call the uninstall routine
- switch(gTheParamBlock.theCodeResources[i].codeType) {
- case kTrapPatchType:
- UninstallTrapPatch(i);
- break;
-
- case kGestaltSelectorType:
- UninstallGestaltSelector(i);
- break;
-
- case kShutdownTaskType:
- UninstallShutdownTask(i);
- break;
-
- case kVBLTaskType:
- UninstallVBLTask(i);
- break;
-
- case kLowMemFilterType:
- UninstallLowMemFilter(i);
- break;
-
- case kCodeBlockType:
- UninstallCodeBlock(i);
- break;
-
- case kTimeManagerTaskType:
- UninstallTimeManagerTask(i);
- break;
-
- default:
- ;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallTrapPatch : Uninstall a trap patch.
- //-----------------------------------------------------------------------------
- // Note : We check the value currently held in the dispatch table. If
- // it's still the same as our address, then it's safe to remove
- // our routine. We do this just by replacing the dispatch table
- // entry with the old value we originally replaced.
- //-----------------------------------------------------------------------------
- void UninstallTrapPatch(short i)
- { ProcPtr currentCode, oldCodeAddress, currentDispatch;
- short trapWord;
- TrapType trapType;
- Handle theHnd;
-
-
-
-
- // Find out what we need to know
- trapWord = gTheParamBlock.theCodeResources[i].theCodeThing.theTrapPatch.trapWord;
- currentCode = (ProcPtr) gTheParamBlock.theCodeResources[i].theAddress;
- oldCodeAddress = gTheESAddressTable->theTable[i];
- trapType = (trapWord & 0x0800) ? ToolTrap : OSTrap;
-
-
-
- // Compare the value in the dispatch table with our own code. If they match,
- // then it's safe to remove the patch. Otherwise we're stuck.
- currentDispatch = (ProcPtr) StripAddress((Ptr) NGetTrapAddress(trapWord, trapType));
- if (currentDispatch == currentCode)
- {
- // Overwrite the dispatch table entry with the old address.
- NSetTrapAddress((UniversalProcPtr) StripAddress(oldCodeAddress), trapWord, trapType);
-
-
- // Recover a handle to the code we installed, and throw it away
- theHnd = RecoverHandle((Ptr) currentCode);
- DisposeHandle(theHnd);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallGestaltSelector : Uninstall a Gestalt Selector.
- //-----------------------------------------------------------------------------
- // Note : We can only remove Gestalt Selectors if we've got System 7.5.
- //
- // Depending on your Gestalt.h, you may need to comment out
- // the local definition of DeleteGestaltValue.
- //-----------------------------------------------------------------------------
- extern pascal OSErr DeleteGestaltValue(OSType selector)
- THREEWORDINLINE(0x303C, 0x0203, 0xABF1);
- void UninstallGestaltSelector(short i)
- { OSErr theErr;
- AGestaltSelector *theGestaltInfo;
- Handle theHnd;
-
-
-
- if (gTheParamBlock.systemVersion >= 0x0750)
- {
- // Remove the selector
- theGestaltInfo = &gTheParamBlock.theCodeResources[i].theCodeThing.theGestaltSelector;
- theErr = DeleteGestaltValue(theGestaltInfo->theSelector);
-
-
- // Recover a handle to the code we installed, and throw it away
- theHnd = RecoverHandle(gTheParamBlock.theCodeResources[i].theAddress);
- DisposeHandle(theHnd);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallShutdownTask : Uninstall a Shutdown Task.
- //-----------------------------------------------------------------------------
- void UninstallShutdownTask(short i)
- { Handle theHnd;
-
-
- // Remove the shutdown task
- ShutDwnRemove(NewShutDwnProc(gTheParamBlock.theCodeResources[i].theAddress));
-
-
- // Recover a handle to the code and dispose of it
- theHnd = RecoverHandle(gTheParamBlock.theCodeResources[i].theAddress);
- DisposeHandle(theHnd);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallVBLTask : Uninstall a VBL task.
- //-----------------------------------------------------------------------------
- void UninstallVBLTask(short i)
- { Handle theHnd;
-
-
- // Remove the VBL task
- VRemove((QElemPtr) gTheParamBlock.theCodeResources[i].theAddress);
-
-
- // Recover a handle to the code and dispose of it
- theHnd = RecoverHandle(gTheParamBlock.theCodeResources[i].theAddress);
- DisposeHandle(theHnd);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallLowMemFilter : Remove a low-memory filter.
- //-----------------------------------------------------------------------------
- void UninstallLowMemFilter(short i)
- { Handle theHnd;
- ProcPtr theEntryPoint, currentHead, oldHead, ourCode;
-
-
-
-
- // Get the address of the filter chain
- theEntryPoint = (ProcPtr) gTheParamBlock.theCodeResources[i].theCodeThing.theLowMemFilter.theEntryPoint;
-
-
-
- // Find out where everything else is
- currentHead = (ProcPtr) *((ProcPtr *) theEntryPoint);
- oldHead = gTheESAddressTable->theTable[i];
- ourCode = (ProcPtr) gTheParamBlock.theCodeResources[i].theAddress;
-
-
-
- // Compare the value at the head of the chain with our own code. If
- // they match, then we can remove our filter. Otherwise we're stuck.
- if (currentHead == ourCode)
- {
- // Overwrite the entry at the head of the chain with the original
- *((ProcPtr *) theEntryPoint) = oldHead;
-
-
-
- // Recover a handle to our code, and throw it away
- theHnd = RecoverHandle((Ptr) ourCode);
- DisposeHandle(theHnd);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallCodeBlock : Remove a block of code.
- //-----------------------------------------------------------------------------
- void UninstallCodeBlock(short i)
- { ProcPtr theCode;
- Handle theHnd;
-
-
-
-
- // Get the pointer to the code block
- theCode = (ProcPtr) gTheParamBlock.theCodeResources[i].theAddress;
-
-
- // Recover a handle to the code and dispose of it
- theHnd = RecoverHandle((Ptr) theCode);
- DisposeHandle(theHnd);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // UninstallTimeManagerTask : Remove a Time Manager task.
- //-----------------------------------------------------------------------------
- void UninstallTimeManagerTask(short i)
- { Handle theHnd;
-
-
-
- // Remove the Time Manager task
- RmvTime((QElemPtr) gTheParamBlock.theCodeResources[i].theAddress);
-
-
- // Recover a handle to the code and dispose of it
- theHnd = RecoverHandle(gTheParamBlock.theCodeResources[i].theAddress);
- DisposeHandle(theHnd);
- }
-