﻿#!/usr/bin/perl
#
# Parse un fichier log généré par SIW (version 1.63) et affiche un résumé.
#
# perl parseur-siw.pl <fichier.html>
#
# Script par BoboTiG - 12 septembre 2009
# Révision : 14 septembre 2009
#


use strict;
use warnings;


my $siw_version = 0;


# Sub to clear the console
sub clear_console {
	if ( $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'os2' ) {
		system('cls');
	} else {
		system('clear');
	}
}


# Determine if the file is a SVG file
sub is_log_file {
	open(my $svg, '<', "@_") || die("Impossible d'ouvrir le fichier.\n\n");
		while ( <$svg> ) {
			if ( $_ =~ '<TITLE>HTML Log</TITLE>' ) {
				$siw_version = '1.63';
				return 1;
			} elsif ( $_ =~ '<TITLE>HTML Report</TITLE>' )  {
				$siw_version = '2009.09.09';
				return 1;
			}
		}
	close($svg);
	
	return 0;
}


# Propriétés principales
# [<propriété>, <RegExp>]
my @strings = (
	['Constructeur', '<TR BGCOLOR="#F0F0F0"><TD>Manufacturer</TD><TD>(.+)</TD></TR>'],
	['Mother board', '<TR><TD>Model</TD><TD>(.+)</TD></TR>'],
	['CPU', '<TD>CPU Name</TD><TD>(.+)</TD>'],
	['Sok', '<TD>Cpu Socket</TD><TD>(.+)</TD>'],
	['GPU', '<TD>VideoProcessor</TD><TD>(.+)</TD>'],
	['RAM', '<TD>Physical Memory</TD><TD>(.+) Total'],
	['OS ', '<TD>Name</TD><TD>(.+)</TD></TR>'],
	['Cle', '<TD>Windows Key</TD><TD>(.+)</TD><TD></TD><TD></TD><TD></TD></TR>'],
	['Sta', '<TD>Activation Status</TD><TD>(.+)</TD>'],
	['Nom', '<TD>COMPUTERNAME</TD><TD>(.+)</TD>'],
);

# Propriétés des anti-virus
# [<nom>, <Match>]
my @antivirus = (
	['avast!', '<TD>avast! Antivirus</TD>'],
	['Avira AntiVir Personal', '<TD>Avira AntiVir Personal - Free Antivirus</TD>'],
	['BitDefender Free Edition', '<TD>BitDefender Free Edition'],
	['ClamWin Free Antivirus', '<TD>ClamWin Free Antivirus'],
	['Norton AntiVirus', '<TD>Norton AntiVirus Scanner Module</TD>'],
	['Moon Secure Antivirus', '<TD>Moon Secure Antivirus</TD>'],
);
# Propriétés des anti-spywares
# [<nom>, <Match>]
my @antispywares = (
	['a-squared', '<TD>a-squared'],
	['Immunet Protect', '<TD>Immunet Protect</TD>'],
	['Spybot - Search  Destroy', '<TD>Spybot - Search  Destroy</TD>'],
);


if (  @ARGV != 1  ) {
	die('perl $0 <fichier.html>'."\n");
} else {
	clear_console();
	print "\n".'*** Parseur de fichiers log SIW ***'."\n\n";
	
	my $split_char;
	if ( $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'os2' ) {
		$split_char = '\\\\';
	} else {
		$split_char = '/';
	}
	
	if ( $ARGV[0]=~ $split_char ) {
		my @file = split(/$split_char/, $ARGV[0]);
		print '[+] Fichier : '.$file[$#file]."\n";
	} else {
		print '[+] Fichier : '.$ARGV[0]."\n";
	}
	
	my @log_file;
	
	if ( is_log_file("$ARGV[0]") ) {
		open(my $log, '<', "$ARGV[0]");
			@log_file = <$log>;
		close($log);
		
		# Version de SIW
		print '[+] SIW ver : '.$siw_version."\n";
		
		if ( $siw_version eq '2009.09.09' ) {
			print "[!] Version non prise en compte.";
		} else {
			# Informations principales
			print "\t[+] Informations principales :\n";
			foreach my $string ( @strings ) {
				print "\t      $$string[0] : ";
				
				my $found = 0;
				foreach my $line ( @log_file ) {
					if ( $line =~ /($$string[1])/ ) {
						my $result = $+;
						if ( $result && !($$string[0] eq 'Mother board' && $result =~ '</TD><TD></TD>') ) {
							print $result."\n";
							$found = 1;
							last;
						}
					}
				}
				
				if ( !$found ) {
					print "inc.\n";
				}
			}
			
			# Informations anti-virus
			print "\n\t[+] Anti-virus :\n";
			my $found = 0;
			foreach my $antivirus ( @antivirus ) {
				foreach my $line ( @log_file ) {
					if ( $line =~ /($$antivirus[1])/ ) {
						print "\t      $$antivirus[0]\n";
						++$found;
						last;
					}
				}
			}
			
			if ( !$found ) {
				print "\t    ! Aucun !\n";
			} elsif ( $found > 1 ) {
				print "\t    ! Il y a $found anti-virus !\n";
			}
			
			# Informations anti-spyware
			print "\n\t[+] Anti-spyware :\n";
			$found = 0;
			foreach my $antispyware ( @antispywares ) {
				foreach my $line ( @log_file ) {
					if ( $line =~ /($$antispyware[1])/ ) {
						print "\t      $$antispyware[0]\n";
						++$found;
						last;
					}
				}
			}
			
			if ( !$found ) {
				print "\t    ! Aucun !\n";
			} elsif ( $found > 2 ) {
				print "\t    ! Il y a plus que 2 anti-spyware ($found) !\n";
			}
		}
	} else {
		print "[!] Il ne s'agit pas d'un fichier log.\n";
	}

	print "\n";
}

exit;

