예제 #1
0
파일: avclient.go 프로젝트: wxdublin/clamav
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...")
}
예제 #2
0
파일: main.go 프로젝트: wxdublin/clamav
func initClamAV() *clamav.Engine {
	clamav.Init(clamav.InitDefault)
	engine := clamav.New()
	sigs, err := engine.Load(*db, clamav.DbStdopt)
	if err != nil {
		log.Fatalf("can not initialize ClamAV engine: %v", err)
	}
	if *debug {
		log.Printf("loaded %d signatures", sigs)
	}

	engine.SetPreCacheCallback(PreCacheCb)
	engine.SetPreScanCallback(PreScanCb)
	engine.SetPostScanCallback(PostScanCb)
	engine.SetHashCallback(HashCb)

	engine.Compile()

	return engine
}