;JackWeg tool to remove Traveling Jack Virus from files
;all this here is public domain made by Carnivore/BeerMacht 11.10.90

CloseLibrary		= -414
OldOpenLibrary		= -408

Close			= -36
Examine			= -102
ExNext			= -108
Lock			= -84
Open			= -30
Output			= -60
Read			= -42
Seek			= -66
UnLock			= -90
Write			= -48

run:	move.l 4.w,a6
	lea dosname(pc),a1
	jsr OldOpenLibrary(a6)
	move.l d0,dosbase
	beq.L nodos

	move.l dosbase(pc),a6
	jsr Output(a6)
	move.l d0,outhd
	
	move.l d0,d1
	lea titte(pc),a2
	move.l a2,d2
	move.l #titlen,d3
	jsr Write(a6)

	lea path(pc),a1
	move.l a1,d1
	moveq #-2,d2
	jsr Lock(a6)
	move.l d0,dirlock
	beq.L nolock

	move.l dirlock(pc),d1
	lea fileinfo(pc),a2
	move.l a2,d2	
	jsr Examine(a6)
	tst.l d0
	beq.L noexamine

scanit:	move.l dirlock(pc),d1
	lea fileinfo(pc),a2
	move.l a2,d2	
	jsr ExNext(a6)
	tst.l d0
	beq.L enddir

	move.l outhd(pc),d1
	lea fileinfo+8(pc),a2
	move.l a2,d2		;filename
	moveq #-1,d3
cntlen:	addq.l #1,d3
	tst.b (a2)+
	bne.s cntlen
	jsr Write(a6)	

	lea isdir(pc),a2
	moveq #dirlen,d3

	tst.l fileinfo+4
	bpl.L yoho
	lea small(pc),a2
	moveq #smallen,d3
	
	cmp.l #$99c,fileinfo+124
	bls.L yoho

	lea fileinfo+8(pc),a1
	move.l a1,d1
	move.l #1005,d2	
	jsr Open(a6)	
	move.l d0,srchd
	beq.L nosrc		;file empty
	
	move.l srchd(pc),d1
	lea minibuf(pc),a2
	move.l a2,d2
	move.l #$18,d3
	jsr Read(a6)
	tst.l d0

	lea small(pc),a2
	moveq #smallen,d3

	lea minibuf(pc),a0
	cmp.l #$3f3,(a0)
	bne.L clean
	move.l #$998,d6		;jack v1
	cmp.l #$25e,$14(a0)
	beq.s dojack1
	move.l #$99c,d6		;jack mutant
	cmp.l #$25f,$14(a0)
	bne.L clean
dojack1:

	lea destnam(pc),a1
	move.l #"RAM:",(a1)+
	lea fileinfo+8(pc),a0
copyname:move.b (a0)+,(a1)
	tst.b (a1)+
	bne.s copyname

	lea destnam(pc),a1
	move.l a1,d1
	move.l #1006,d2
	jsr Open(a6)
	move.l d0,desthd
	beq.s nodest

	lea minibuf(pc),a5
	subq.l #1,8(a5)			;n hunks
	subq.l #1,$10(a5)		;last hunk
	move.l $8(a5),d7		;howmanytocopy
	asl.l #2,d7
	move.l desthd(pc),d1
	move.l a5,d2
	moveq #$14,d3			;cut of his balls
	jsr Write(a6)

	move.l srchd(pc),d1
	lea bigbuf,a5
	move.l a5,d2
	move.l d7,d3
	jsr Read(a6)
	move.l desthd(pc),d1
	move.l a5,d2
	move.l d7,d3
	jsr Write(a6)

	move.l srchd(pc),d1
	move.l d6,d2		;see above!!
	clr.l d3
	jsr Seek(a6)

conti:	move.l srchd(pc),d1
	lea bigbuf,a5
	move.l a5,d2
	move.l #$10000,d3
	move.l d3,d7
	jsr Read(a6)
	sub.l d0,d7
	move.l desthd(pc),d1
	move.l a5,d2
	move.l d0,d3
	jsr Write(a6)
	tst.l d7
	beq.s conti	
	

	move.l desthd(pc),d1
	jsr Close(a6)
nodest:
	lea infect(pc),a2
	moveq #inflen,d3

clean:	move.l srchd(pc),d1
	jsr Close(a6)
nosrc:

yoho:	move.l outhd(pc),d1
	move.l a2,d2
	jsr Write(a6)

	bra.L scanit
enddir:
noexamine:
	move.l dirlock(pc),d1
	jsr UnLock(a6)
nolock:	move.l 4.w,a6
	move.l dosbase(pc),a1
	jsr CloseLibrary(a6)
nodos:

	clr.l d0
	rts

dosbase:dc.l 0
dosname:dc.b "dos.library",0
path:	dc.b 0
even
destnam:blk.b 128,0		;108bytes filename
isdir:	dc.b " (dir) ",10,13
dirlen=*-isdir
small:	dc.b " ",$1b,"[33;42m<not infected>",$1b,"[0m",10,13
smallen=*-small
infect:	dc.b 7," ",$1b,"[31;42mIS INFECTED and has been "
	dc.b "stripped from it in RAM: !!!",$1b,"[0m",10,13
inflen=*-infect
titte:	dc.b 12,$1b,"[31;42m JACKWEG V0.4 - 11-oct-90         "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m Carnivore of BeerMacht presents  "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m a fast hack to remove the JACK - "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m Virus from any file in your      "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m current directory!               "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m (now handles the JACK-mutant)    "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m The salvaged file is stored in   "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m RAM: so you have to move it...   "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m Gritinx to Flynn and the other   "
	dc.b $1b,"[0m",10,13
	dc.b $1b,"[31;42m friends in RAULS mighty empire.  "
	dc.b $1b,"[0m",10,10,13
	dc.b $1b,"[31;42m Now let's spill the blood...     "
	dc.b $1b,"[0m",10,10,13

	dc.b 0
titlen=*-titte
even
outhd:	dc.l 0
desthd:	dc.l 0
srchd:	dc.l 0
dirlock:dc.l 0
minibuf:blk.b $18,0
align 4
fileinfo:blk.b 260,0
data
bigbuf:	blk.b $10000,0
