; Slayer - a desktop anti-virus for RISC OS
; Copyright (C) 1996 - 2000 Kiwi Software (UK)
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
;
; info@kiwisoft.co.uk
; -------------------------------------------------------------------------

;

			funcName "module_removal"

; -> r1 = filename

.kill_module    	mov	r11,r1	;preserve filename
			mov	r12,r0	;preserve virus ID

			mov	r0,#5
			; r1 already contains filename
			swi	XOS_File
			bvs	exit_from_error
			;r4 is now the file-length
			mov	r7,r5
			mov	r5,r2
			mov	r6,r3
			mov	r8,r4

			mov	r0,#&C0
			; r1 already contains filename
			swi	XOS_Find
			bvs	exit_from_error

			mov	r10,r0  ;filehandle is now in r10

			;grab 4 byte section
			mov	r0,#3
			mov	r1,r10	;filehandle
			adr	r2,scrap_block
			mov	r3,#4
			mov	r4,#4

			swi	XOS_GBPB
			bvs	exit_from_error

			ldr	r9,scrap_block	;r9 contains i%

			;grab 20 byte section in scrap block
			mov	r0,#3
			mov	r1,r10
			adr	r2,scrap_block
			mov	r3,#20
			sub	r4,r8,#16	;length-16
			swi	XOS_GBPB
			bvs	exit_from_error

			;attempt to do the line fini%=!scrap% etc...
			ldr	r0,scrap_block
			mov	r2,r0
			cmp	r0,#0
			addne	r0,r9,#&F0
			subne	r0,r0,r2
			mov	r4,r0	;preserve to store later

			;attempt to do the line ini%=scrap%!4 etc..
			adr	r1,scrap_block
			ldr	r0,[r1,#4]
			mov	r2,r0
			cmp	r0,#0
			addne	r0,r9,#&C0
			subne	r0,r0,r2
			str	r0,[r1]		; store into block
			str	r4,[r1,#4]	; and this one

			;attempt to do line serv%=scrap%!8 etc..
			ldr	r0,[r1,#8]
			mov	r2,r0
			cmp	r0,#0
			addne	r0,r9,#&144
			subne	r0,r0,r2
			str	r0,[r1,#8]	; store into block

			mov	r0,#1
			mov	r1,r10
			adr	r2,scrap_block
			mov	r3,#12
			mov	r4,#4
			swi	XOS_GBPB	; store the block
			bvs	exit_from_error

			mov	r0,#3
			sub	r2,r9,#2

			; module is 2bytes longer when cleaned than millenium
			teq	r12,#module
			addeq	r2,r2,#2

			swi	XOS_Args
			bvs	exit_from_error

			mov	r0,#0
			swi	XOS_Find
			bvs	exit_from_error

			mov	r0,#1
			mov	r1,r11
			mov	r2,r5
			mov	r3,r6
			mov	r5,r7
			swi	XOS_File
			bvs	exit_from_error

			mov	r0,#0
			ldmfd	r13!,{pc}	;unstack and return to caller

