Beispiel #1
0
func main() {
	var engine *clamav.Engine

	flag.Usage = usage
	flag.Parse()

	clamav.Init(clamav.InitDefault)

	if *clamavversion {
		fmt.Println(clamav.Retver())
		os.Exit(0)
	}

	args := flag.Args()
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "error: missing path\n")
		usage()
	}

	runtime.GOMAXPROCS(*cpus)

	if *scan {
		log.Println("initializing ClamAV database...")
		engine = initClamAV()
	}

	in := make(chan string, 1024)
	cnt := make(chan string, 1024)
	out := make(chan string, 1024)
	done := make(chan bool, *workers)

	log.Println("scan starting...")

	if *clamavdebug {
		clamav.Debug()
	}

	for i := 0; i < *workers; i++ {
		go worker(cnt, out, done, engine)
	}

	go counter(in, cnt)

	for _, v := range args {
		walker(v, in)
	}

	close(in)
	for i := 0; i < *workers; i++ {
		<-done
	}

	log.Println("scan completed...")
}
Beispiel #2
0
func main() {
	var engine *clamav.Engine

	flag.Usage = usage
	flag.Parse()

	if *clamavversion {
		fmt.Println(clamav.Retver())
		os.Exit(0)
	}

	args := flag.Args()
	if len(args) == 0 && !*testmap {
		fmt.Fprintln(os.Stderr, "error: missing path\n")
		usage()
	}

	runtime.GOMAXPROCS(*cpus)

	if *scan {
		log.Println("initializing ClamAV database...")
		engine = initClamAV()
	}

	if *testmap {
		fmap := clamav.OpenMemory(eicar)
		defer clamav.CloseMemory(fmap)

		virus, _, err := engine.ScanMapCb(fmap, clamav.ScanStdopt|clamav.ScanAllmatches, "eicar memorytest")
		if err != nil {
			log.Printf("error scanning in-memory: %v\n", err)
		}
		log.Printf("in-memory scan result: %s (eicar)\n", virus)
		return
	}

	in := make(chan string, 1024)
	cnt := make(chan string, 1024)
	out := make(chan string, 1024)
	done := make(chan bool, *workers)

	log.Println("scan starting...")

	if *clamavdebug {
		clamav.Debug()
	}

	for i := 0; i < *workers; i++ {
		go worker(cnt, out, done, engine)
	}

	go counter(in, cnt)

	for _, v := range args {
		walker(v, in)
	}

	close(in)
	for i := 0; i < *workers; i++ {
		<-done
	}

	log.Println("scan completed...")
}