; SystemUtils (parasite) removal code
; 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
; -------------------------------------------------------------------------


; created by rob; 17th September 1999

; -> R1 = filename


			funcName "sysutils_removal"

.kill_sysutils		mov		r0, #17		; we need it's length
			swi		XOS_File	; file length now in r4
			mov		r9, r4		; and keep a spare in r9

			mov		r0,#&C0
			;filename already in R1
			swi		XOS_Find
			bvs		exit_from_error	;failed to open file
			teq		r0,#0
			beq		exit_from_error	;failed to open file

			mov		r1,r0
			mov		r10,r0	;keep a copy of filehandle
			mov		r0,#3
			;filehandle already in r1
			adr		r2,scrap_block
			mov		r3,#4 * 4
			sub		r4, r9, #1656
			swi		XOS_GBPB ; read them...
			bvs		exit_from_error	;failed to read bytes

			; write out the original init offset

			mov		r0, #1
			mov		r1, r10
			adr		r2, scrap_block
			mov		r3, #4
			mov		r4, #4
			swi		XOS_GBPB
			bvs		exit_from_error	;failed to write bytes

			; write out original final offset

			mov		r0, #1
			mov		r1, r10
			adr		r2, scrap_block
			add		r2, r2, #4
			mov		r3, #4
			mov		r4, #8
			swi		XOS_GBPB
			bvs		exit_from_error	;failed to write bytes

			; and finally the service offset

			mov		r0, #1
			mov		r1, r10
			adr		r2, scrap_block
			add		r2, r2, #12
			mov		r3, #4
			mov		r4, #&C
			swi		XOS_GBPB
			bvs		exit_from_error	;failed to write bytes

			; and now shrink the file by 2780 bytes

			mov		r0, #3 ; write extent
			mov		r1, r10
			sub		r2, r9, #2780
			swi		XOS_Args

			; all done!

			mov		r0, #0
			mov		r1, r10
			swi		XOS_Find

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

