コード例 #1
0
ファイル: engine.go プロジェクト: eaigner/clam
func (e *clEngine) Compile(cvdDir string) error {
	e.mtx.Lock()
	defer e.mtx.Unlock()

	if e.IsCompiled() {
		return ErrAlreadyCompiled
	}

	// Create new engine
	e.engine = C.cl_engine_new()
	if e.engine == nil {
		return errors.New("failed to create new clamav engine")
	}

	// Load signatures
	var ret C.int
	var sigs C.uint = 0
	ret = C.cl_load(C.CString(cvdDir), e.engine, &sigs, C.CL_DB_STDOPT)
	if ret != C.CL_SUCCESS {
		return fmt.Errorf("could not load vcds: %s", C.GoString(C.cl_strerror(ret)))
	}

	// Compile engine
	ret = C.cl_engine_compile(e.engine)
	if ret != C.CL_SUCCESS {
		return fmt.Errorf("could not compile engine: %s", C.GoString(C.cl_strerror(ret)))
	}

	atomic.StoreInt32(&e.compiled, 1)

	return nil
}
コード例 #2
0
ファイル: clamav.go プロジェクト: rayyang2000/clamav
// LoadDB loads a single database file or all databases depending on whether its first argument
// (path) points to a file or a directory. A number of loaded signatures will be added to signo
// (the virus counter should be initialized to zero initially)
func (e *Engine) Load(path string, dbopts uint) (uint, error) {
	var signo uint
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))
	err := ErrorCode(C.cl_load(cpath, (*C.struct_cl_engine)(e), (*C.uint)(unsafe.Pointer(&signo)), C.uint(dbopts)))
	if err != Success {
		return 0, fmt.Errorf("Load: %v", StrError(err))
	}
	return signo, nil
}