home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Security / Security.zip / fprot312.zip / f-prot.cmd < prev    next >
OS/2 REXX Batch file  |  2002-04-09  |  8KB  |  148 lines

  1. /* OS/2 REXX, requires DOSCALL.EXE and F-PROT.EXE 3.11b or later: */
  2. /* Start F-PROT.EXE on a given file or directory tree in an OS/2  */
  3. /* text mode window (VIO) using DOSCALL.EXE to get rc and output. */
  4.  
  5.    PROT = 'f:\etc\f-prot\f-prot.exe'
  6.    PLOG = 'f:\etc\f-prot\f-prot.log'
  7.  
  8. /* Usage: F-PROT [drive, file or directory] [options]             */
  9. /*                                                                */
  10. /*     /AI         Enable neural-network virus detection.         */
  11. /*     /APPEND     Append to existing report file.                */
  12. /*     /ARCHIVE    Scan inside .ZIP and .ARJ files.               */
  13. /*     /AUTO       Automatic virus removal.                       */
  14. /*     /BEEP       Beep when a virus is found.                    */
  15. /*     /CDROM      Scan any attached CD-ROM drives.               */
  16. /*     /COLLECT    Scan a virus collection.                       */
  17. /*     /DELETE     Delete infected files.                         */
  18. /*     /DISINF     Disinfect whenever possible.                   */
  19. /*     /DUMB       Do a "dumb" scan of all files.                 */
  20. /*     /EXT        Scan only files with default extensions.       */
  21. /*     /FREEZE     "Freeze" the program if a virus is found.      */
  22. /*     /HARD       Scan the hard disk(s).                         */
  23. /*     /HELP       Display this list.                             */
  24. /*     /LIST       List all files checked.                        */
  25. /*     /LOADDEF    Load DEF files from a floppy.                  */
  26. /*     /NET        Scan network directories mapped to a drive.    */
  27. /*     /NOBOOT     Do not scan boot sectors.                      */
  28. /*     /NOBREAK    Do not abort scan if ESC is pressed.           */
  29. /*     /NOFILE     Do not scan files.                             */
  30. /*     /NOFLOPPY   For use on system without floppy drives.       */
  31. /*     /NOHEUR     Disable heuristics.                            */
  32. /*     /NOLFN      Disable long file name support.                */
  33. /*     /NOMEM      Do not scan memory for viruses.                */
  34. /*     /NOSUB      Do not scan subdirectories.                    */
  35. /*     /OLD        Do not complain when using outdated DEF files. */
  36. /*     /ONLYHEUR   Only use heuristics, not "normal" scanning.    */
  37. /*     /PACKED     Unpack compressed executables.                 */
  38. /*     /RENAME     Rename infected COM/EXE files to VOM/VXE.      */
  39. /*     /TYPE       Select files by type. (default)                */
  40. /*     /VIRLIST    List the known viruses.                        */
  41. /*     /VIRNO      Count the known viruses.                       */
  42. /*     /WRAP       Wrap text so the report fits in 78 columns.    */
  43. /*     /SILENT     Do not generate any screen output.             */
  44. /*     /NOMACRO    Do not scan for macro viruses.                 */
  45. /*     /ONLYMACRO  Only scan for macro viruses.                   */
  46. /*     /REMOVEALL  Remove all macros from all documents.          */
  47. /*     /REMOVENEW  Remove new variants of macro viruses by        */
  48. /*                 removing all macros from infected documents.   */
  49. /*     /SAFEREMOVE Remove all macros from documents, if a known   */
  50. /*                 virus is found.                                */
  51. /*                                                                */
  52. /* Without options F-PROT.CMD uses /AI /ARCHIVE /PACKED /WRAP ... */
  53.  
  54.    signal on novalue  name TRAP  ;  signal on syntax name TRAP
  55.    signal on failure  name TRAP  ;  signal on halt   name TRAP
  56.    call UTIL 'SysGetKey'         ;  call UTIL 'SysTextScreenSize'
  57.  
  58.    parse arg  FILE '/' OPTS
  59.    if FILE = ''   then exit HELP( 1 )
  60.    if OPTS <> ''  then OPTS = '/' || translate( strip( OPTS ))
  61.                   else OPTS = '/AI /ARCHIVE /PACKED /WRAP'
  62.  
  63.    if pos( 'INTER', OPTS ) > 0 then exit HELP( 0 )
  64.    if pos( 'PAGE' , OPTS ) > 0 then exit HELP( 0 )
  65.    address CMD 'DOSCALL' PROT FILE OPTS '/REPORT=' || PLOG
  66.    exit rc
  67.  
  68. HELP: procedure
  69.    parse value SysTextScreenSize() with ROWS .  ;  HERE = 0
  70.  
  71.    if arg( 1 ) then do N = 1
  72.       parse value sourceline( N ) with STOP '/*' LINE '*/'
  73.       if HERE = 0 then
  74.          if abbrev( strip( LINE ), 'Usage:' ) = 0 then iterate N
  75.       if STOP <> '' then leave N
  76.       HERE = HERE + 1   ;  say LINE
  77.       if HERE // ( ROWS - 2 ) = 0 then call SysGetKey 'NoEcho'
  78.    end N
  79.    else say "sorry, options /INTER or /PAGE won't work in a pipe..."
  80.    return 1
  81.  
  82. UTIL: procedure                  /* load necessary RexxUtil entry */
  83.    if RxFuncQuery(  arg( 1 )) then
  84.       if RxFuncAdd( arg( 1 ), 'RexxUtil', arg( 1 )) then
  85.          exit TRAP( "can't add RexxUtil"  arg( 1 ))
  86.    return 0
  87.  
  88. TRAP:                            /* select REXX exception handler */
  89.    call trace 'O' ;  trace N           /* don't trace interactive */
  90.    parse source TRAP                   /* source on separate line */
  91.    TRAP = x2c( 0D ) || right( '+++', 10 ) TRAP || x2c( 0D0A )
  92.    TRAP = TRAP || right( '+++', 10 )   /* = standard trace prefix */
  93.    TRAP = TRAP condition( 'c' ) 'trap:' condition( 'd' )
  94.    select
  95.       when wordpos( condition( 'c' ), 'ERROR FAILURE' ) > 0 then do
  96.          if condition( 'd' ) > ''      /* need an additional line */
  97.             then TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 )
  98.          TRAP = TRAP '(RC' rc || ')'   /* any system error codes  */
  99.          if condition( 'c' ) = 'FAILURE' then rc = -3
  100.       end
  101.       when wordpos( condition( 'c' ), 'HALT SYNTAX'   ) > 0 then do
  102.          if condition( 'c' ) = 'HALT' then rc = 4
  103.          if condition( 'd' ) > '' & condition( 'd' ) <> rc then do
  104.             if condition( 'd' ) <> errortext( rc ) then do
  105.                TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 )
  106.                TRAP = TRAP errortext( rc )
  107.             end                        /* future condition( 'd' ) */
  108.          end                           /* may use errortext( rc ) */
  109.          else  TRAP = TRAP errortext( rc )
  110.          rc = -rc                      /* rc < 0: REXX error code */
  111.       end
  112.       when condition( 'c' ) = 'NOVALUE'  then rc = -2 /* dubious  */
  113.       when condition( 'c' ) = 'NOTREADY' then rc = -1 /* dubious  */
  114.       otherwise                        /* force non-zero whole rc */
  115.          if datatype( value( 'RC' ), 'W' ) = 0 then rc = 1
  116.          if condition() = '' then TRAP = TRAP arg( 1 )
  117.    end                                 /* direct: TRAP( message ) */
  118.  
  119.    TRAP = TRAP || x2c( 0D0A ) || format( sigl, 6 )
  120.    signal on syntax name TRAP.SIGL     /* throw syntax error 3... */
  121.    if 0 < sigl & sigl <= sourceline()  /* if no handle for source */
  122.       then TRAP = TRAP '*-*' strip( sourceline( sigl ))
  123.       else TRAP = TRAP '+++ (source line unavailable)'
  124. TRAP.SIGL:                             /* ...catch syntax error 3 */
  125.    if abbrev( right( TRAP, 2 + 6 ), x2c( 0D0A )) then do
  126.       TRAP = TRAP '+++ (source line unreadable)'   ;  rc = -rc
  127.    end
  128.    select
  129.       when 0 then do                   /* in pipes STDERR: output */
  130.          parse version TRAP.REXX . .   /* REXX/Personal: \dev\con */
  131.          signal on syntax name TRAP.FAIL
  132.          if TRAP.REXX = 'REXXSAA'      /* fails if no more handle */
  133.             then call lineout 'STDERR'  , TRAP
  134.             else call lineout '\dev\con', TRAP
  135.       end
  136.       when 0 then do                   /* OS/2 PM: RxMessageBox() */
  137.          signal on syntax name TRAP.FAIL
  138.          call RxMessageBox ,           /* fails if not in PMREXX  */
  139.             translate( TRAP, ' ', x2c( 0D )), , 'CANCEL', 'WARNING'
  140.       end                              /* replace any CR by blank */
  141.       otherwise   say TRAP ; trace ?L  /* interactive Label trace */
  142.    end
  143.  
  144.    if condition() = 'SIGNAL' then signal TRAP.EXIT
  145. TRAP.CALL:  return rc                  /* continue after CALL ON  */
  146. TRAP.FAIL:  say TRAP ;  rc = 0 - rc    /* force TRAP error output */
  147. TRAP.EXIT:  exit   rc                  /* exit for any SIGNAL ON  */
  148.