Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
// New allocates a new ClamAV engine.
func New() *Engine {
	eng := (*Engine)(C.cl_engine_new())
	return eng
}