home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
init
/
rwatcher.sit
/
RWatcher.a
< prev
next >
Wrap
Text File
|
1988-11-14
|
9KB
|
395 lines
title 'RWatcher'
;_______________________________________________________________________
;
; RWatcher - Resource Watching INIT.
;
; Version 1.0. November, 1988.
;
; John Norstad
; Academic Computing and Network Services
; Northwestern University
; 2129 Sheridan Road
; Evanston, IL 60208
;
; Bitnet: jln@nuacc
; Internet: jln@nuacc.acns.nwu.edu
;
; Copyright ⌐ 1988, John Norstad. Permission is granted to make and
; distribute copies of this software, its source code, and documentation,
; provided this copyright notice is preserved on all copies.
; The software cannot, however, be sold or distributed for profit.
; The software has no warranty, express or implied. Use it at your
; own risk.
;_______________________________________________________________________
;_______________________________________________________________________
;
; RWatcher is a very simple INIT that patches the AddResource and
; ChangedResource system traps. The patches watch for attempts to
; create or modify any of a list of resources. If such an attempt
; is made the patches beep 10 times and exit to shell (quit the
; offending application).
;
; The list of resources to be monitored is specified in the RLIS 128
; resource on the INIT file. This list can be easily modified with
; ResEdit.
;_______________________________________________________________________
;_______________________________________________________________________
;
; RWatcher is written in MPW Assembler.
;
; Use the following MPW commands to build the INIT resource:
;
; asm -wb -l -pagesize 73,105 RWatcher.a
; link RWatcher.a.o ::ShowInit:ShowInit.a.o ╢
; -t INIT -rt INIT=0 -sg RWatcher -ra RWatcher=$10 -o RWatcher
;_______________________________________________________________________
main
; Imports.
import ShowInit
; Include Files.
print off
Include 'Traps.A'
Include 'SysEqu.A'
Include 'ToolEqu.A'
print on
eject
title 'Constants and Assembly Options'
;_______________________________________________________________________
;
; Constants and Assembly Options.
;_______________________________________________________________________
iconID equ 128 ; resource id of ICN#
addResTrap equ $1ab ; AddResource trap number
chaResTrap equ $1aa ; ChangedResource trap number
rListType equ 'RLIS' ; resource type of resource list
rListID equ 128 ; resource id of resource list
numBeeps equ 10 ; number of beeps if bad rsrc found
beepDuration equ 10 ; beep duration
; The RLIS 128 resource is a zero byte terminated list of resource
; descriptions. The following constants describe the contents of
; each element of the list. Two "wild card" flags permit matching
; any resource id and/or size for a given resource type.
rLisType equ 0 ; offset of resource type
rLisID equ 4 ; offset of resource ID
rLisSize equ 6 ; offset of resource size
rLisFlags equ 10 ; offset of resource flags
rLisAnyID equ 7 ; bit number of any ID flag
rLisAnySize equ 6 ; bit number of any size flag
rLisLen equ 12 ; length of resource info
eject
title 'Global Variables'
;_______________________________________________________________________
;
; Global Variables.
;_______________________________________________________________________
; The following instruction is the first one executed when the INIT runs
; at boot time. It branches around the patch code to the initialization
; code.
Header:
bra Init
; The INIT installs the patches as a single non-relocatable block in
; the system heap. The contents of this block begin here.
BlockBegin:
; The following three global variables are initialized by the INIT.
AddResOldAddr:
ds.l 1 ; old AddResource trap address
ChaResOldAddr:
ds.l 1 ; old ChangedResource trap address
RListHandle:
ds.l 1 ; handle to RLIS 128 resource list
eject
title 'AddResPatch - AddResource Patch'
;_______________________________________________________________________
;
; AddResPatch - AddResource Patch
;_______________________________________________________________________
; Stack frame record template.
AddResFrame record {oldA6},decrement
theData ds.l 1 ; handle to data
theType ds.l 1 ; type
theID ds.w 1 ; id
name ds.l 1 ; ptr to name
retAddr ds.l 1 ; return address
oldA6 ds.l 1 ; old A6
size equ *
endr
; Patch entry point.
with AddResFrame
AddResPatch:
; Create stack frame and save registers.
link a6,#size
movem.l d3-d4/a2,-(sp)
; Load registers for CheckRes:
;
; d3 = resource type (from param list).
; d4 = resource id (from param list).
; a2 = handle to data (from param list).
move.l theType(a6),d3 ; type
move.w theID(a6),d4 ; id
move.l theData(a6),a2 ; handle
; Call CheckRes to compare against resource list.
bsr.s CheckRes
; Exit. Restore registers, unlink, and call old trap.
movem.l (sp)+,d3-d4/a2
unlk a6
move.l AddResOldAddr,a0 ; old trap address
jmp (a0)
endwith
eject
title 'ChaResPatch - ChangedResource Patch'
;_______________________________________________________________________
;
; ChaResPatch - ChangedResource Patch
;_______________________________________________________________________
; Stack frame record template.
ChaResFrame record {oldA6},decrement
theResource ds.l 1 ; handle to resource
retAddr ds.l 1 ; return address
oldA6 ds.l 1 ; old A6
theID ds.w 1 ; id
theType ds.l 1 ; type
name ds.b 256 ; name
size equ *
endr
; Patch entry point.
with ChaResFrame
ChaResPatch:
; Create stack frame and save registers.
link a6,#size
movem.l d3-d4/a2,-(sp)
; Call GetResInfo to get resource type and id.
move.l theResource(a6),-(sp)
pea theID(a6)
pea theType(a6)
pea name(a6)
_GetResInfo
; Load registers for CheckRes:
;
; d3 = resource type (from GetResInfo).
; d4 = resource id (from GetResInfo).
; a2 = handle to data (from param list).
move.l theType(a6),d3
move.w theID(a6),d4
move.l theResource(a6),a2
; Call CheckRes to compare against resource list.
bsr.s CheckRes
; Exit. Restore registers, unlink, and call old trap.
movem.l (sp)+,d3-d4/a2
unlk a6
move.l ChaResOldAddr,a0 ; old trap address
jmp (a0)
endwith
eject
title 'CheckRes - Check Resource Procedure'
;_______________________________________________________________________
;
; CheckRes - Check Resource Procedure.
;
; This procedure is called by both patches. It compares a resource
; to the RLIS 128 list.
;
; Entry: (d3) = resource type.
; (d4) = resource id.
; (a2) = handle to resource data.
;
; Exit: If match found: Beep numBeep times and exit to shell.
; If no match found: Return to caller.
;_______________________________________________________________________
CheckRes:
; Call GetHandleSize to get (d0) = handle size.
move.l a2,a0
_GetHandleSize
; Walk RLIS 128 resource, comparing type, id, and size.
move.l RListHandle,a2
move.l (a2),a2 ; (a2) = ptr to RLIS 128 resource
Loop:
tst.b (a2)
bnz.s CheckType ; if not end of list
rts ; no match - return to caller
CheckType:
cmp.l rLisType(a2),d3
bne.s NextRsrc ; if different types
CheckID:
btst #rLisAnyID,rLisFlags(a2)
bnz.s CheckSize ; if any id specified
cmp.w rLisID(a2),d4
bne.s NextRsrc ; if different ids
CheckSize:
btst #rLisAnySize,rLisFlags(a2)
bnz.s BadRsrc ; if any size specified
cmp.l rLisSize(a2),d0
beq.s BadRsrc ; if same sizes
NextRsrc:
lea rLisLen(a2),a2 ; advance to next rsrc in list
bra Loop
; Bad resource found. Beep numBeeps times and exit to shell.
BadRsrc:
move.w #numBeeps-1,d3
BeepLoop:
move.w #beepDuration,-(sp)
_SysBeep
dbra d3,BeepLoop
_ExitToShell
blockSize equ *-BlockBegin
eject
title 'Init - Initialization'
;_______________________________________________________________________
;
; Init - Initialization.
;_______________________________________________________________________
Init:
; Show the icon.
move.w #iconID,-(sp)
jsr ShowInit
; Load the RLIS 128 resource and detach it. The RLIS 128 resource must
; have the system heap attribute set. It should be unlocked but
; non-purgeable.
sub.l #4,sp
move.l #rListType,-(sp)
move.w #rListID,-(sp)
_GetResource ; load RLIS 128
move.l (sp)+,d0
bz.s Exit ; if error
move.l d0,a3 ; (a3) = handle to RLIS 128
move.l a3,-(sp)
_DetachResource ; detach rsrc
; Allocate new non-relocatable system heap block to hold data and patches.
move.l #blockSize,d0
_NewPtr ,sys
move.l a0,a2 ; (a2) = ptr to block
; Copy data and patches to the block.
lea BlockBegin,a0
move.l a2,a1
move.l #blockSize,d0
_BlockMove
; Save handle to resource list in data area.
move.l a3,RListHandle-BlockBegin(a2)
; Get and save old AddResource and ChangedResource trap addresses.
move.w #addResTrap,d0
_GetTrapAddress
move.l a0,AddResOldAddr-BlockBegin(a2)
move.w #chaResTrap,d0
_GetTrapAddress
move.l a0,ChaResOldAddr-BlockBegin(a2)
; Patch AddResource and ChangedResource.
lea AddResPatch-BlockBegin(a2),a0
move.w #addResTrap,d0
_SetTrapAddress
lea ChaResPatch-BlockBegin(a2),a0
move.w #chaResTrap,d0
_SetTrapAddress
; Return.
Exit:
rts
end