@ -721,42 +721,30 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
const char * virname = NULL ;
uint32_t viroffset = 0 ;
uint32_t viruses_found = 0 ;
EVP_MD_CTX * md5ctx , * sha1ctx , * sha256ctx ;
void * md5ctx , * sha1ctx , * sha256ctx ;
if ( ! ctx - > engine ) {
cli_errmsg ( " cli_scandesc: engine == NULL \n " ) ;
return CL_ENULLARG ;
}
md5ctx = EVP_MD_CTX_create ( ) ;
md5ctx = cl_hash_init ( " md5 " ) ;
if ( ! ( md5ctx ) )
return CL_EMEM ;
sha1ctx = EVP_MD_CTX_create ( ) ;
sha1ctx = cl_hash_init ( " sha1 " ) ;
if ( ! ( sha1ctx ) ) {
EVP_MD_CTX _destroy( md5ctx ) ;
cl_hash _destroy( md5ctx ) ;
return CL_EMEM ;
}
sha256ctx = EVP_MD_CTX_create ( ) ;
sha256ctx = cl_hash_init ( " sha256 " ) ;
if ( ! ( sha256ctx ) ) {
EVP_MD_CTX _destroy( md5ctx ) ;
EVP_MD_CTX _destroy( sha1ctx ) ;
cl_hash _destroy( md5ctx ) ;
cl_hash _destroy( sha1ctx ) ;
return CL_EMEM ;
}
if ( ! EVP_DigestInit_ex ( md5ctx , EVP_md5 ( ) , NULL ) ) {
return CL_CLEAN ;
}
if ( ! EVP_DigestInit_ex ( sha1ctx , EVP_sha1 ( ) , NULL ) ) {
return CL_CLEAN ;
}
if ( ! EVP_DigestInit_ex ( sha256ctx , EVP_sha256 ( ) , NULL ) ) {
return CL_CLEAN ;
}
if ( ! ftonly )
groot = ctx - > engine - > root [ 0 ] ; /* generic signatures */
@ -774,9 +762,9 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
if ( ftonly ) {
if ( ! troot ) {
EVP_MD_CTX _destroy( md5ctx ) ;
EVP_MD_CTX _destroy( sha1ctx ) ;
EVP_MD_CTX _destroy( sha256ctx ) ;
cl_hash _destroy( md5ctx ) ;
cl_hash _destroy( sha1ctx ) ;
cl_hash _destroy( sha256ctx ) ;
return CL_CLEAN ;
}
@ -796,9 +784,9 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
free ( info . exeinfo . section ) ;
cli_hashset_destroy ( & info . exeinfo . vinfo ) ;
EVP_MD_CTX _destroy( md5ctx ) ;
EVP_MD_CTX _destroy( sha1ctx ) ;
EVP_MD_CTX _destroy( sha256ctx ) ;
cl_hash _destroy( md5ctx ) ;
cl_hash _destroy( sha1ctx ) ;
cl_hash _destroy( sha256ctx ) ;
return ret ;
}
}
@ -811,9 +799,9 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
free ( info . exeinfo . section ) ;
cli_hashset_destroy ( & info . exeinfo . vinfo ) ;
EVP_MD_CTX _destroy( md5ctx ) ;
EVP_MD_CTX _destroy( sha1ctx ) ;
EVP_MD_CTX _destroy( sha256ctx ) ;
cl_hash _destroy( md5ctx ) ;
cl_hash _destroy( sha1ctx ) ;
cl_hash _destroy( sha256ctx ) ;
return ret ;
}
if ( troot - > bm_offmode ) {
@ -827,9 +815,9 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
free ( info . exeinfo . section ) ;
cli_hashset_destroy ( & info . exeinfo . vinfo ) ;
EVP_MD_CTX _destroy( md5ctx ) ;
EVP_MD_CTX _destroy( sha1ctx ) ;
EVP_MD_CTX _destroy( sha256ctx ) ;
cl_hash _destroy( md5ctx ) ;
cl_hash _destroy( sha1ctx ) ;
cl_hash _destroy( sha256ctx ) ;
return ret ;
}
@ -896,9 +884,9 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
free ( info . exeinfo . section ) ;
cli_hashset_destroy ( & info . exeinfo . vinfo ) ;
EVP_MD_CTX _destroy( md5ctx ) ;
EVP_MD_CTX _destroy( sha1ctx ) ;
EVP_MD_CTX _destroy( sha256ctx ) ;
cl_hash _destroy( md5ctx ) ;
cl_hash _destroy( sha1ctx ) ;
cl_hash _destroy( sha256ctx ) ;
return ret ;
}
}
@ -935,11 +923,11 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
uint32_t data_len = bytes - maxpatlen * ( offset ! = 0 ) ;
if ( compute_hash [ CLI_HASH_MD5 ] )
EVP_DigestUpdate ( md5ctx , data , data_len ) ;
cl_update_hash ( md5ctx , data , data_len ) ;
if ( compute_hash [ CLI_HASH_SHA1 ] )
EVP_DigestUpdate ( sha1ctx , data , data_len ) ;
cl_update_hash ( sha1ctx , data , data_len ) ;
if ( compute_hash [ CLI_HASH_SHA256 ] )
EVP_DigestUpdate ( sha256ctx , data , data_len ) ;
cl_update_hash ( sha256ctx , data , data_len ) ;
}
}
@ -958,15 +946,18 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
enum CLI_HASH_TYPE hashtype , hashtype2 ;
if ( compute_hash [ CLI_HASH_MD5 ] ) {
EVP_DigestFinal_ex ( md5ctx , digest [ CLI_HASH_MD5 ] , NULL ) ;
cl_finish_hash ( md5ctx , digest [ CLI_HASH_MD5 ] ) ;
md5ctx = NULL ;
}
if ( refhash )
compute_hash [ CLI_HASH_MD5 ] = 1 ;
if ( compute_hash [ CLI_HASH_SHA1 ] ) {
EVP_DigestFinal_ex ( sha1ctx , digest [ CLI_HASH_SHA1 ] , NULL ) ;
cl_finish_hash ( sha1ctx , digest [ CLI_HASH_SHA1 ] ) ;
sha1ctx = NULL ;
}
if ( compute_hash [ CLI_HASH_SHA256 ] ) {
EVP_DigestFinal_ex ( sha256ctx , digest [ CLI_HASH_SHA256 ] , NULL ) ;
cl_finish_hash ( sha256ctx , digest [ CLI_HASH_SHA256 ] ) ;
sha256ctx = NULL ;
}
virname = NULL ;
@ -1024,9 +1015,9 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
}
}
EVP_MD_CTX _destroy( md5ctx ) ;
EVP_MD_CTX _destroy( sha1ctx ) ;
EVP_MD_CTX _destroy( sha256ctx ) ;
cl_hash _destroy( md5ctx ) ;
cl_hash _destroy( sha1ctx ) ;
cl_hash _destroy( sha256ctx ) ;
if ( troot ) {
if ( ret ! = CL_VIRUS | | SCAN_ALL )