; BBCEconet 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 Luke (21/10/98)

			funcName "bbceconet_removal"

.kill_bbceconet
;filename = r1
;Infected File's length = r8
;magic number=r7
;Original file length=r6
;File's handle = r10

			; Get the file's length
			mov	r0,#17
			; r1 already contains filename
			swi	XOS_File
			bvs	exit_from_error
			mov	r8,r4

			;Calculate the original length from infected length
			mov	r0,#5284
			sub	r6,r8,r0

			;Now open the file...
			mov	r0,#&C0
			; r1 already contains filename
			swi	XOS_Find
			bvs	exit_from_error
			cmp	r0,#0
			beq	exit_from_error
			mov	r10,r0

			;Grab the first &9B bytes into scrap_block...
			mov	r0,#3
			mov	r1,r10
			adr	r2,scrap_block
			mov	r3,#&9B
			mov	r4,#0
			swi	XOS_GBPB
			bvs	exit_from_error

			;Grab the information for the header
			adr	r2,scrap2_block
			;mov	r2,r9
			mov	r3,#20
			mov	r0,#5032
			sub	r4,r8,r0
			mov	r0,#3
			swi	XOS_GBPB
			bvs	exit_from_error

			;Find the magic number?  What's the magic number?
			cmp	r8,#&9B
			movlt	r7,r8
			movge	r7,#&9B

			;Do the main eor decryption.
			adr	r1,scrap_block
			mov	r2,#&18		;loop offset
			mov	r4,#&80000000

.eor_loop		ldr	r3,[r1,r2]
			eor	r3,r3,r4
			str	r3,[r1,r2]
			add	r2,r2,#4
			cmp	r2,r7
			ble	eor_loop

			cmp	r6,#&9b
			ldrge	r3,[r1,#&98]
			eorge	r3,r3,r4
			strge	r3,[r1,#&98]

			; Aquire and fix header
			adr	r0,scrap_block		;where to put it
			adr	r1,scrap2_block		;where to get it
			mov	r2,#0			;loop offset
			mov	r4,#&80000000

.eor_loop2		ldr	r3,[r1,r2]
			eor	r3,r3,r4
			str	r3,[r0,r2]
			add	r2,r2,#4
			cmp	r2,#16
			ble	eor_loop2

			;Write the changes to disc...
			mov	r0,#1
			mov	r1,r10
			adr	r2,scrap_block
			mov	r3,#&9b
			mov	r4,#0
			swi	XOS_GBPB
			bvs	exit_from_error

			mov	r0,#3
			mov	r1,r10
			mov	r2,r6
			swi	XOS_Args
			bvs	exit_from_error

			mov	r0,#0
			mov	r1,r10
			swi	XOS_Find
			bvs	exit_from_error

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

