#
# ESET Software NOD32
# preliminary support
# tested with NOD32/Linux 1.011
#
if ($nod32) {
    do_log(2,"Using $nod32");
    # as of version 1.011, NOD32 spits out control characters and
    # other screen-oriented garbage even if stdout is *not*
    # connected to a terminal. The log file, however, is clean.
    chop($output = `$nod32 -all -subdir+ $TEMPDIR/parts`);
    $errval = retcode($?);
    # I hope E-SET will correct bugs, so don't mess up with
    # temporary files for logging etc., and hack to filter
    # nonprinting characters in the output.
    $output =~ tr{\r}{\n};
    $output =~ s'[^[:print:]\n]+'';
    do_log(2,$output);
    if ($errval == 0) {			# no errors, no viruses found
	$scanner_errors = 0;
    } elsif ($errval == 1) {		# no errors, viruses discovered
	$scanner_errors = 0;
	# I also hope they will turn to something a bit more
	# descriptive than just "filename - virusname" ...
	@virusname = ($output =~ m{^$TEMPDIR/parts/.+ - (.+(?:backdoor|joke|trojan|virus|worm))}mg);
	return 1;  # 'true' indicates virus found and stops further checking
    } else {
    	# FIXME: Do these error conditions (from `strings nod32`)
	# fall in this category?
	#
        # - password protected file
        # - file compressed using unknown method
        # - wrong file checksum (CRC), may be damaged
        # - broken archive
        # - archive damaged and file can not be extracted
        # - can not find next archive volume
        # - not an archive file
        # - problem encountered while loading an archive
        # - decompression not performed, check available memory and disk space
	#
	do_log(0,"Virus scanner failure: $nod32 (error code: $errval)");
    }
}

# List of Return Codes
#define NOD32_EXIT_CODE_OK               0
#define NOD32_EXIT_CODE_VIRUS            1
#define NOD32_EXIT_CODE_CLEANED          2
#define NOD32_EXIT_INTERNAL_ERROR        10

