home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
wb
/
assignwedge
/
source
/
assignwedge.c
next >
Wrap
C/C++ Source or Header
|
1994-12-23
|
24KB
|
1,067 lines
/*
** AssignWedge - AmigaDOS 2.04 utility
**
** Copyright © 1992-1994 by Olaf `Olsen' Barthel
** All Rights Reserved
**
** :ts=4
*/
#include <intuition/intuitionbase.h>
#include <workbench/startup.h>
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include <exec/execbase.h>
#include <exec/memory.h>
#include <libraries/locale.h>
#include <libraries/asl.h>
#include <clib/intuition_protos.h>
#include <clib/utility_protos.h>
#include <clib/locale_protos.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/asl_protos.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/utility_pragmas.h>
#include <pragmas/locale_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/asl_pragmas.h>
#include <string.h>
#include <stdarg.h>
/* Create the requester strings. */
#define CATCOMP_ARRAY
#include "AssignWedge.h"
/* The requester selection IDs. */
enum { REQ_CANCEL, REQ_RETRY, REQ_ASSIGN, REQ_MOUNT, REQ_DENY };
/* Some handy signal macros. */
#define SIG_KILL SIGBREAKF_CTRL_C
#define SIG_NOTIFY (1L << MainPort -> mp_SigBit)
/* The MC680x0 `jump to absolute address' opcode. */
#define JMP_ABS 0x4EF9
/* A simple wedge definition which is to consist of a jmp
* instruction and the destination of the jump.
*/
struct Wedge
{
UWORD Command;
ULONG Location;
};
/* Process and command names which are no longer allowed to
* access certain paths will be identified by information
* to be found in a list. The following structure definition
* holds the necessary data (name and process base address).
*/
struct DenyNode
{
struct MinNode Node;
struct Process *Process;
LONG DenyEmpty;
STRPTR Name,
ProgramName;
};
/* The library vector offset of the intuition.library routine to patch. */
extern ULONG __far LVOEasyRequestArgs;
/* The version ID tag. */
STATIC UBYTE Version[] = "\0$VER: AssignWedge 1.4 (4.12.94)\r\n";
/* Global and shared library identifiers. */
struct IntuitionBase *IntuitionBase;
struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
struct Library *UtilityBase,
*AslBase;
/* Locale support. */
struct LocaleBase *LocaleBase;
struct Catalog *Catalog;
/* Registration of programs which are not allowed to
* access certain devices.
*/
struct SignalSemaphore DenySemaphore;
struct MinList DenyList;
/* The following counter and the associated access semaphore help
* to keep track of the number of programs currently using the
* patched EasyRequestArgs() routine.
*/
struct SignalSemaphore RunSemaphore;
LONG RunCount;
/* Handshake data. */
struct Process *MainProcess;
struct MsgPort *MainPort;
BOOL Removed;
/* To compensate for possible incompatibilities introduced by internationalized
* requester texts, we will try to determine the text to turn up when an
* `please insert volume' requester is opened. The `SearchName' will receive
* the string to look for.
*/
UBYTE SearchName[256];
/* Function prototypes. */
LONG __saveds Main(VOID);
STRPTR __regargs GetString(LONG ID);
LONG __saveds __asm NewEasyRequestArgs(register __a0 struct Window *Window,register __a1 struct EasyStruct *EasyStruct,register __a2 ULONG *IDCMPPtr,register __a3 APTR *Args);
LONG (* __asm OldEasyRequestArgs)(register __a0 struct Window *,register __a1 struct EasyStruct *,register __a2 ULONG *,register __a3 APTR *,register __a6 struct IntuitionBase *);
LONG __stdargs StackCall(LONG *Success,LONG StackSize,LONG ArgCount,LONG (* __stdargs Function)(),...);
VOID __stdargs SPrintf(STRPTR buffer,STRPTR formatString,...);
VOID CheckIn(VOID);
VOID CheckOut(VOID);
LONG __saveds
Main()
{
struct WBStartup *WBenchMsg;
LONG ReturnCode = RETURN_FAIL;
/* Set up ExecBase */
SysBase = *(struct ExecBase **)4;
/* Determine current process identifier. */
MainProcess = (struct Process *)SysBase -> ThisTask;
/* Are we running from CLI? If not, wait for Workbench
* startup message.
*/
if(!MainProcess -> pr_CLI)
{
WaitPort(&MainProcess -> pr_MsgPort);
WBenchMsg = (struct WBStartup *)GetMsg(&MainProcess -> pr_MsgPort);
}
else
WBenchMsg = NULL;
/* Try to find the global handshake port and if present
* send a termination signal.
*/
Forbid();
if(MainPort = FindPort("AssignWedge Rendezvous"))
{
Signal(MainPort -> mp_SigTask,SIG_KILL);
ReturnCode = RETURN_OK;
Permit();
}
else
{
Permit();
/* Are we running under Kickstart version 37 or higher? */
if(SysBase -> LibNode . lib_Version > 36)
{
/* Create the global handshake port. */
if(MainPort = CreateMsgPort())
{
/* Give it a name and add it to the public list. */
MainPort -> mp_Node . ln_Name = "AssignWedge Rendezvous";
AddPort(MainPort);
/* Open the required libraries. */
if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37))
{
if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37))
{
if(UtilityBase = OpenLibrary("utility.library",37))
{
if(AslBase = OpenLibrary(AslName,37))
{
struct Wedge *Wedge;
/* Try to open locale.library, but don't panic
* if it's not available.
*/
if(LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",38))
{
if(!(Catalog = OpenCatalog(NULL,"assignwedge.catalog",
OC_BuiltInLanguage, "english",
OC_BuiltInCodeSet, 0,
TAG_DONE)))
{
CloseLibrary((struct Library *)LocaleBase);
LocaleBase = NULL;
}
}
/* Initialize the access semaphore. */
InitSemaphore(&RunSemaphore);
RunCount = 0;
/* Initialize the access semaphore and
* the list of programs to which access
* to certain devices has been denied.
*/
InitSemaphore(&DenySemaphore);
NewList((struct List *)&DenyList);
/* Allocate a system library function wedge. */
if(Wedge = AllocMem(sizeof(struct Wedge),MEMF_PUBLIC))
{
struct DenyNode *NextNode,
*DenyNode;
UBYTE LocalBuffer[80];
/* Initialize the wedge. */
Wedge -> Command = JMP_ABS;
Wedge -> Location = (ULONG)NewEasyRequestArgs;
Removed = FALSE;
/* Install the wedge. */
Forbid();
OldEasyRequestArgs = (LONG (* __asm)())SetFunction((struct Library *)IntuitionBase,(LONG)&LVOEasyRequestArgs,(ULONG (*)())Wedge);
/* Make sure the data gets written to memory. */
CacheClearU();
/* Put up an example requester. Note: this requester
* will be trapped by the wedge routine, giving us
* the string to look for in the future.
*/
SPrintf(LocalBuffer,"AssignWedge.%08lx:",MainProcess);
ErrorReport(ERROR_DEVICE_NOT_MOUNTED,REPORT_INSERT,(ULONG)LocalBuffer,NULL);
/* We're up and running now. Note that the
* Forbid() will be broken by the Wait() for
* a ^C signal.
*/
Wait(SIG_KILL);
/* We are no longer running,
* tell the wedge routine to
* skip the `access denied'
* part which requires the
* list to be initialized.
*/
Removed = TRUE;
/* Redirect the wedge pointer to
* the original routine.
*/
Wedge -> Location = (ULONG)OldEasyRequestArgs;
/* Make sure that the data
* gets written to memory.
*/
CacheClearU();
/* Clear pending signals. */
SetSignal(0,SIG_NOTIFY);
/* Turn the multitasking back on. */
Permit();
/* Wait until our wedge routine
* is no longer in use.
*/
while(RunCount)
Wait(SIG_NOTIFY);
/* Clear the `access denied' list. */
DenyNode = (struct DenyNode *)DenyList . mlh_Head;
while(NextNode = (struct DenyNode *)DenyNode -> Node . mln_Succ)