

pmain	move.l	#$99999999,d7
	sf	-1(a0,d0.w)
	move.l	a0,-(sp)
	IFNE	ASMONE
	move.l	SysBase,a6
	ELSE
	move.l	SysBase.w,a6
	ENDC
	move.l	ThisTask(a6),a4
	tst.l	pr_CLI(a4)
	bne.s	pShellStart
	lea	pr_MsgPort(a4),a0
	CALL	WaitPort
	lea	pr_MsgPort(a4),a0
	CALL	GetMsg
	move.l	d0,a1
	addq.b	#1,IDNestCnt(a6)
	CALL	ReplyMsg
pError	addq.w	#4,sp
	moveq	#0,d0
	rts


pShellStart	moveq	#OS204,d0
	cmp.w	LIB_VERSION(a6),d0
	bgt.s	pError


pLoopLength	move.l	#$99999999,d2
	lsr.l	#2,d2
	move.l	d2,d5
	lea	pData(pc),a4
pPassword	move.l	#$99999999,d6
pDecryptLoop	move.l	(a4),d4
	add.l	d7,d4
	add.l	d6,d4
	ror.l	#4,d4
	addq.b	#3,d4
	bchg	#4,d4
	not.l	d4
	bchg	#1,d4
	sub.l	d6,d4
	move.l	d4,(a4)+
	sub.l	d6,d7
	subq.l	#1,d2
	bne.s	pDecryptLoop

pMakeChecksum	add.l	-(a4),d2
	subq.l	#1,d5
	bne.s	pMakeChecksum
pChecksum	cmp.l	#$99999999,d2
	bne.s	pError

	move.l	a4,a0
	cmp.l	#"CRU!",(a0)+
	bne.s	.1
	move.l	a0,a1
	add.l	4(a1),a0
	lea	3*4(a0),a0
	bsr	pUnpack
	move.l	a0,a4

.1	lea	pARexxPortName(pc),a1
	CALL	FindPort
	move.l	d0,d7
	beq.s	pError

	lea	pRexxSysName(pc),a1
	moveq	#36,d0
	CALL	OpenLibrary
	move.l	d0,d6
	beq	pError

	CALL	CreateMsgPort
	move.l	d0,d5
	beq.s	pMsgPortError

	move.l	d0,a0
	sub.l	a1,a1
	moveq	#0,d0
	move.l	d6,a6
	CALL	CreateRexxMsg
	move.l	d0,d4
	beq.s	pNoRexxMsg

	move.l	a4,rm_Args(a0)
	move.l	(sp),rm_Args+4(a0)
	moveq	#2,d0
	moveq	#0,d1
	CALL	FillRexxMsg
	tst.l	d0
	beq.s	pFillMsgError

	move.l	d4,a0
	move.l	#RXFUNC+RXFF_STRING+1,rm_Action(a0)
	IFNE	ASMONE
	move.l	SysBase,a6
	ELSE
	move.l	SysBase.w,a6
	ENDC
	move.l	d7,a0
	move.l	d4,a1
	CALL	PutMsg
	move.l	d5,a0
	CALL	WaitPort

pFillMsgError	move.l	d6,a6
	move.l	d4,a0
	moveq	#2,d0
	CALL	ClearRexxMsg
	move.l	d4,a0
	CALL	DeleteRexxMsg
pNoRexxMsg	move.l	d5,a0
	IFNE	ASMONE
	move.l	SysBase,a6
	ELSE
	move.l	SysBase.w,a6
	ENDC
	CALL	DeleteMsgPort
pMsgPortError	move.l	d6,a1
	CALL	CloseLibrary

pLoopLength2	move.l	#$99999999,d0
pClearScript	sf	(a4)+
	subq.l	#1,d0
	bne.s	pClearScript
	bra	pError

	INCLUDE	"RC:rcincludes/s404_passwo.asm"

	dc.w	0
pRexxSysName	dc.b	"rexxsyslib.library",0
pARexxPortName	ds.b	20+1
pData
phl	EQU	*-pmain
pHUNKLENGTH	EQU	(phl>>2+1)+7	;+null terminator
