home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d919 / bbbf.lha / BBBF / FileVirLib / TestAFile.S < prev    next >
Text File  |  1993-10-04  |  5KB  |  288 lines

  1. ;------------------------------------------------------------
  2. ;    An assembler example of showing the use
  3. ;    of the 'removelink.library'.
  4. ;    Will assemble correctly with most assemblers,
  5. ;    supporting local labels.
  6. ;
  7. ;    This will examine a file, and check if the file is
  8. ;    executable, data or infected.
  9. ;    Will just check for virusnames. Not remove the
  10. ;    viruses.
  11. ;
  12. ;    This pice of code is copyright (C) Johan Ohman 1993
  13. ;
  14. ;------------------------------------------------------------
  15.  
  16.     incdir    'df0:include/'
  17.  
  18.     include    'exec/exec_lib.i'
  19.     include    'exec/memory.i'
  20.     include    'exec/tasks.i'
  21.     include    'libraries/dos_lib.i'
  22.     include    'libraries/dos.i'
  23.  
  24.     include    'RLL/removelink_lib.i'
  25.     include    'RLL/removelink.i'
  26.  
  27. call:    macro
  28.     jsr    _LVO\1(a6)
  29.     endm
  30.  
  31. MaxFileSize=    $10000    ;( <= 65535 bytes.)
  32. HUNK_HEADER=    $3F3
  33.  
  34.  
  35. S:    movem.l    d0-a6,-(sp)
  36.  
  37.     move.l    (4).W,a6    ;This is if we were called from WB
  38.     suba.l    a1,a1
  39.     call    FindTask
  40.     move.l    d0,a4
  41.     tst.l    140(a4)
  42.     bne.b    .FromCLI
  43.  
  44.     lea.l    92(a4),a0
  45.     call    WaitPort
  46.  
  47.     lea.l    92(a4),a0
  48.     call    GetMsg
  49. .FromCLI:
  50.     movem.l    (sp)+,d0-a6
  51.  
  52.     clr.b    -1(a0,d0.w)
  53.     move.l    d0,Argc
  54.     move.l    a0,Argv
  55.  
  56.     subq.w    #1,d0
  57.     beq.w    NoArgs
  58.  
  59.     move.l    (4).W,a6
  60.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  61.     move.l    #MaxFileSize,d0
  62.     call    AllocMem
  63.     tst.l    d0
  64.     beq.w    NoMem
  65.     move.l    d0,FileMemPtr
  66.  
  67.     move.l    (4).W,a6
  68.     moveq.l    #32,d0
  69.     lea.l    RLLib(pc),a1
  70.     call    OpenLibrary
  71.     tst.l    d0
  72.     beq.w    NoRLLib
  73.     move.l    d0,RLBase
  74.  
  75.     moveq.l    #33,d0        ;Kick 1.2 +
  76.     lea.l    DosLib(pc),a1
  77.     call    OpenLibrary
  78.     tst.l    d0
  79.     beq.w    NoDosLib
  80.     move.l    d0,DosBase
  81.  
  82.     move.l    RLBase(pc),a6
  83.     call    AllocRLMem
  84.     tst.l    d0
  85.     beq.w    Quit
  86.     move.l    d0,RLTab
  87.  
  88.     move.l    DosBase(pc),a6
  89.     move.l    Argv(pc),d1
  90.     move.l    #MODE_OLDFILE,d2
  91.     call    Open
  92.     tst.l    d0
  93.     beq.w    Quit
  94.     move.l    d0,FHandler
  95.  
  96.     move.l    FHandler(pc),d1
  97.     move.l    FileMemPtr(pc),d2
  98.     move.l    #MaxFileSize,d3
  99.     call    read
  100.     move.l    d0,FileSize    ;Number of bytes read.
  101.  
  102.     move.l    FHandler(pc),d1
  103.     call    close
  104.  
  105.     move.l    FileMemPtr(pc),a0
  106.     cmp.l    #HUNK_HEADER,(a0)
  107.     bne.w    NotExec
  108.  
  109.     move.l    FileSize(pc),d0
  110.     cmp.l    #MaxFileSize,d0
  111.     beq.w    TooBig
  112.  
  113.     move.l    RLTab(pc),a0
  114.     move.l    FileMemPtr(pc),RL_BufferPtr(a0)
  115.     move.l    FileSize,RL_BufferLen(a0)
  116.     move.l    RLBase(pc),a6
  117.     call    GetFileVName
  118.  
  119.     tst.l    RL_FileInfection(a0)
  120.     beq.b    NoInfection
  121.  
  122.     move.l    RL_FileInfection(a0),a0
  123.     lea.l    ThisFINode(pc),a1
  124.     move.l    a0,(a1)
  125.     bsr.b    Infection
  126.  
  127.     tst.l    FI_NextNode(a0)
  128.     beq.b    NoNextFINode
  129.  
  130. NextFINode:
  131.     move.l    FI_NextNode(a0),(a1)
  132.     bsr.b    Infection
  133.     tst.l    (a1)
  134.     bne.b    NextFINode
  135.  
  136. NoNextFINode:
  137.     bra.b    Quit
  138.  
  139. NoRLLib:
  140.     pea.l    RLLib(pc)
  141.     pea.l    _NoLib(pc)
  142.     bsr.w    printF
  143.     addq.w    #8,Sp
  144.     bra.b    Quit
  145.  
  146. NoDosLib:
  147.     pea.l    DosLib(pc)
  148.     pea.l    _NoLib(pc)
  149.     bsr.w    printF
  150.     addq.w    #8,Sp
  151.     bra.b    Quit
  152.  
  153. NoMem:
  154.     move.l    #MaxFileSize,-(sp)
  155.     move.l    #MaxFileSize,-(sp)
  156.     pea.l    _NotEnoughMem
  157.     bsr.w    printF
  158.     lea.l    12(sp),sp
  159.     bra.b    Quit
  160.  
  161. NoArgs:    pea.l    _NoArgs(pc)
  162.     bsr.w    printF
  163.     addq.w    #4,Sp
  164.     rts
  165.  
  166. NotExec:
  167.     pea.l    _NotExecutable(pc)
  168.     bsr.b    printF
  169.     addq.w    #4,Sp
  170.     bra.b    Quit
  171.  
  172. NoInfection:
  173.     move.l    Argv(pc),-(sp)
  174.     pea.l    _NotInfected(pc)
  175.     bsr.b    printF
  176.     addq.w    #8,Sp
  177.     bra.b    Quit
  178.  
  179. Infection:
  180.     move.l    ThisFINode(pc),a6
  181.     move.l    FI_VirusName(a6),-(sp)
  182.  
  183.     pea.l    _Infected(pc)
  184.     bsr.b    printF
  185.     addq.w    #8,Sp
  186.     rts
  187.  
  188. TooBig:
  189.     pea.l    _FileTooBig(pc)
  190.     bsr.b    printF
  191.     addq.w    #4,Sp
  192.     bra.w    Quit
  193.  
  194. Quit:    move.l    FileMemPtr(pc),d0
  195.     beq.b    .NoMemAllocated
  196.     move.l    d0,a1
  197.     move.l    #MaxFileSize,d0
  198.     move.l    (4).W,a6
  199.     call    FreeMem
  200.  
  201. .NoMemAllocated:
  202.     move.l    RLBase(pc),d0
  203.     tst.l    d0
  204.     beq.b    .NoRLTab    ;Don't use the library if there is no... 
  205.     move.l    d0,a6        ;ie. don't provoke a Guru ...
  206.  
  207.     move.l    RLTab(pc),d0
  208.     beq.b    .NoRLTab
  209.     move.l    d0,a0
  210.     call    FreeRLMem
  211.  
  212. .NoRLTab:
  213.     move.l    (4).W,a6
  214.  
  215.     move.l    DosBase(pc),d0
  216.     beq.b    .NotDos
  217.     move.l    d0,a1
  218.     call    CloseLibrary
  219.  
  220. .NotDos:
  221.     move.l    RLBase(pc),d0
  222.     beq.b    .NotRL
  223.     move.l    d0,a1
  224.     call    CloseLibrary
  225. .NotRL:    rts
  226.  
  227. printF:
  228.     movem.l    d0-a6,-(Sp)
  229.     move.l    (4).W,a6
  230.     move.l    15*4+4*1(Sp),a0
  231.     lea.l    15*4+4*2(Sp),a1
  232.     lea.l    .SubPrintF(pc),a2
  233.     link    a5,#-512
  234.     move.l    a5,a3
  235.     lea.l    -512(a3),a3
  236.     call    RawDoFmt
  237.  
  238.     movem.l    d0-a6,-(sp)
  239.     lea.l    -512(a5),a5
  240.     move.l    (4).W,a6
  241.     lea.l    DosLib(pc),a1
  242.     call    OldOpenLibrary
  243.     move.l    d0,a6
  244.     jsr    -60(a6)
  245.     move.l    d0,d1
  246.     move.l    a5,d2
  247. .1:    tst.b    (a5)+
  248.     bne.b    .1
  249.     move.l    a5,d3
  250.     sub.l    d2,d3
  251.     jsr    -48(a6)
  252.     move.l    a6,a1
  253.     move.l    (4).W,a6
  254.     jsr    -414(a6)
  255.     movem.l    (Sp)+,d0-a6
  256.     unlk    a5
  257.     movem.l    (Sp)+,d0-a6
  258.     rts
  259.  
  260. .SubPrintF:
  261.     move.b    d0,(a3)+
  262.     rts
  263.  
  264. DosBase:    dc.l    0
  265. RLBase:        dc.l    0
  266. RLTab:        dc.l    0
  267. Argc:        dc.l    0
  268. Argv:        dc.l    0
  269. ThisFINode:    dc.l    0
  270. FileMemPtr:    dc.l    0
  271. FileSize:    dc.l    0
  272. FHandler:    dc.l    0
  273.  
  274. _NoArgs:    dc.b    'No args ...',10,0
  275. _NoLib:        dc.b    'No %s ',10,0
  276. _NotEnoughMem:    dc.b    'Sorry ! Not enough memory available '
  277.         dc.b    '(bytes needed %ld/$%lx )',10,0
  278. _NotInfected:    dc.b    'The file ''%s'' is not infected ... ',10,0
  279. _Infected:    dc.b    'The file is infected by the ',$9b,'1;31;42m'
  280.         dc.b    '%s',$9b,'0;31;40m - virus',10,0
  281. _NotExecutable:    dc.b    'This file is not a programme [executable] file.',10,0
  282. _FileTooBig:    dc.b    'The file is too big to fit into the allocated memory '
  283.         dc.b    'block...',10,0
  284.  
  285. RLLib:        dc.b    'removelink.library',0
  286. DosLib:        dc.b    'dos.library',0
  287.         even
  288.