; VDEngine for Slayer
; 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
; -------------------------------------------------------------------------



; designed for extASM or similar
; assumes 1K descending stack in R13 on entry (ie use from BASIC)

#speed 		10000			;lines per poll - make it fast(er)
#smile		;sad but true

TEMP 		r12

#include 	"VDEng:main.h.Aliases"
#include 	"VDEng:main.h.MiscDefine"
#include 	"SlayEng:h.VirusIDs"
#include	"SlayEng:h.macros"
#include	"VDEng:main.h.macros"


; main entry point
; =>	r1 Pointer to name of file to be scanned
;	r2 0 for file +ve = size of memory block
;	r3 load address
;	r4 filelength
;	r5 filetype

; <= 	r0 Result of check
;	/no/ other registers preserved

; free regs are: r9, r10, r11, r12(temp)
; usable regs are: r0-r6
; /must/ preserve r7, r8

 		stmfd	r13!,{r14}

		teq	r2,#0
		bne	memory_block_scan
 ; grab file info, then open the file

 		;mov	r0,#5			;read catalogue info
 		;swi	XOS_File
 		;mvnvs	r0,#0
 		;ldmvsfd	r13!,{pc}		;error - leave
 		mov	filelength,r4		;length

; calculate the filetype
		mov	filetype,r5
		;mov	r0,#&FFF00
		;and	filetype,r3,r0
		;mov	filetype,filetype, lsr #8

 ; now look to see if this is a file we are interested in

		mov	r9,r3,lsr #20	;check load address for brb virus
		teq	r9,#&FFF	;if top 12 bits set then it is a filetype - we want a load address
		teqne	r0,r0		;bogde to set eq flag

		teqne	filetype,#&FF8		;absolute
		teqne	filetype,#&FFA		;module

;icon 2218, satani, vandamme and honeymonster are covered by the following
 		cmpne	filelength,#1208+1024	;<1215+1024 could be thunder
 		cmple	filelength,#MINIMUM_SIZE_CHECKED
  		teqge	r0,r0			;bodge to set eq flag
		beq	grabIt

 ; check filesizes
 		teqne	filelength,#5036	;5036 Nitemare
 		teqne	filelength,#2616	;2616 icon
 		teqne	filelength,#2618	;2618 icon
 		teqne	filelength,#3639	;3639 icon
 		teqne	filelength,#5587	;5587 icon
 		teqne	filelength,#5592	;5592 icon
 		teqne	filelength,#5859	;5859 icon
 		teqne	filelength,#7463	;7463 icon
 		teqne	filelength,#7933	;7933 icon
 		teqne	filelength,#5574	;5574 icon
 		teqne	filelength,#5580	;5580 bigfoot
 		teqne	filelength,#5535	;5535 bigfoot

 ; now filetypes

		teqne	filetype,#&FAF		;HTML
		teqne	filetype,#&ae4		;Java class
 		;teqne	filetype,#&FFB		;BASIC
 		;teqne	filetype,#&FF9		;sprite
 		;teqne	filetype,#&FFD		;data
 		;teqne	filetype,#&FFF		;text

; if not wanted then exit

 		movne	r0,#no_virus
 		ldmnefd	r13!,{pc}		;unstack and return to caller

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Pre checks complete. This is a file worthy of our attention - grab it

.grabIt

; open the file
 		mov	r0,#&40			;open for read
 		swi	XOS_Find
 		ldmvsfd	r13!,{pc}		;error - leave
 		mov	r1,r0

; read first and last xxx bytes

 		mov	r0,#3			;read bytes
 		;r1 already contains file handle
 		adr	r2,bufferTopOfFile
 		mov	r3,#FILE_TOP_BUFFER_SIZE
 		mov	r4,#0
 		swi	XOS_GBPB
 		ldmvsfd	r13!,{pc}		;error - leave

 		;r1 already contains file handle
 		adr	r2,bufferBottomOfFile
 		mov	r3,#FILE_BOTTOM_BUFFER_SIZE
		sub	r4,filelength,r3

 		;file might not be big enough...
 		cmp	filelength,r3
 		sublt	r3,r3,filelength	;filelength-buffer size
 		addlt	r2,r2,r3	;add that to buffer pointer
		movlt	r4,#0		;read from start
		movlt	r3,filelength	;read /all/ bytes from file

 		mov	r0,#3			;read bytes
 		swi	XOS_GBPB
 		ldmvsfd	r13!,{pc}		;error - leave

; close the file (no longer needed)

 		teq	r1,#0			;is the file still open
 		movne	r0,#0
 		swine	XOS_Find		;close it
 		ldmvsfd	r13!,{pc}		;error - leave

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; We have the memory, now do the actual checks

#include 	"VDEng:main.s.VCheck"

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; no virus found - leave

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

#include 	"VDEng:VCheck.h.Includes"
 		align
#include	"VDEng:main.s.MemBlockS"
#include 	"VDEng:VCheck.s.Buffers"
 		align


