/* Hashes a file onto the provided buffer and looks it up the cache. Returns CL_VIRUS if found, CL_CLEAN if not FIXME or a recoverable error, and returns CL_EREAD if unrecoverable */ int cache_check(unsigned char *hash, cli_ctx *ctx) { fmap_t *map; size_t todo, at = 0; cli_md5_ctx md5; int ret; if(!ctx || !ctx->engine || !ctx->engine->cache) return CL_VIRUS; map = *ctx->fmap; todo = map->len; cli_md5_init(&md5); while(todo) { const void *buf; size_t readme = todo < FILEBUFF ? todo : FILEBUFF; if(!(buf = fmap_need_off_once(map, at, readme))) return CL_EREAD; todo -= readme; at += readme; if (cli_md5_update(&md5, buf, readme)) { cli_errmsg("cache_check: error reading while generating hash!\n"); return CL_EREAD; } } cli_md5_final(hash, &md5); ret = cache_lookup_hash(hash, map->len, ctx->engine->cache, ctx->recursion); cli_dbgmsg("cache_check: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x is %s\n", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15], (ret == CL_VIRUS) ? "negative" : "positive"); return ret; }
/* Hashes a file onto the provided buffer and looks it up the cache. Returns CL_VIRUS if found, CL_CLEAN if not FIXME or a recoverable error, and returns CL_EREAD if unrecoverable */ int cache_check(unsigned char *hash, cli_ctx *ctx) { fmap_t *map; size_t todo, at = 0; void *hashctx; int ret; if(!ctx || !ctx->engine || !ctx->engine->cache) return CL_VIRUS; if (ctx->engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { cli_dbgmsg("cache_check: Caching disabled. Returning CL_VIRUS.\n"); return CL_VIRUS; } map = *ctx->fmap; todo = map->len; hashctx = cl_hash_init("md5"); if (!(hashctx)) return CL_VIRUS; while(todo) { const void *buf; size_t readme = todo < FILEBUFF ? todo : FILEBUFF; if(!(buf = fmap_need_off_once(map, at, readme))) { cl_hash_destroy(hashctx); return CL_EREAD; } todo -= readme; at += readme; if (cl_update_hash(hashctx, (void *)buf, readme)) { cl_hash_destroy(hashctx); cli_errmsg("cache_check: error reading while generating hash!\n"); return CL_EREAD; } } cl_finish_hash(hashctx, hash); ret = cache_lookup_hash(hash, map->len, ctx->engine->cache, ctx->recursion); cli_dbgmsg("cache_check: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x is %s\n", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15], (ret == CL_VIRUS) ? "negative" : "positive"); return ret; }
/* Hashes a file onto the provided buffer and looks it up the cache. Returns CL_VIRUS if found, CL_CLEAN if not FIXME or a recoverable error, and returns CL_EREAD if unrecoverable */ int cache_check(unsigned char *hash, cli_ctx *ctx) { fmap_t *map; int ret; if(!ctx || !ctx->engine || !ctx->engine->cache) return CL_VIRUS; if (ctx->engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { cli_dbgmsg("cache_check: Caching disabled. Returning CL_VIRUS.\n"); return CL_VIRUS; } ret = cache_get_MD5(hash, ctx); if (ret != CL_CLEAN) return ret; map = *ctx->fmap; ret = cache_lookup_hash(hash, map->len, ctx->engine->cache, ctx->recursion); cli_dbgmsg("cache_check: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x is %s\n", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15], (ret == CL_VIRUS) ? "negative" : "positive"); return ret; }