git-svn: trunk@1782
remotes/push_mirror/metadata
Tomasz Kojm 20 years ago
parent 1b661cef15
commit 83fa53058e
  1. 8
      clamav-devel/clamscan/manager.c
  2. 5
      clamav-devel/clamscan/options.c
  3. 2
      clamav-devel/libclamav/clamav.h
  4. 4
      clamav-devel/libclamav/filetypes.c
  5. 15
      clamav-devel/libclamav/matcher-ac.c
  6. 1
      clamav-devel/libclamav/matcher-ac.h
  7. 19
      clamav-devel/libclamav/matcher.c
  8. 36
      clamav-devel/libclamav/readdb.c

@ -51,6 +51,7 @@
#include "output.h"
#include "misc.h"
#include "../libclamav/others.h"
#include "../libclamav/matcher-ac.h"
#ifdef C_LINUX
dev_t procdev;
@ -88,6 +89,13 @@ int scanmanager(const struct optstruct *opt)
if(optl(opt, "no-phishing"))
dboptions |= CL_DB_NOPHISHING;
if(optl(opt, "dev-ac-only")) {
dboptions |= CL_DB_ACONLY;
if(optl(opt, "dev-ac-depth"))
cli_ac_setdepth(atoi(getargl(opt, "dev-ac-depth")));
}
if(optc(opt, 'd')) {
if((ret = cl_load(getargc(opt, 'd'), &trie, &claminfo.signs, dboptions))) {
logg("^%s\n", cl_strerror(ret));

@ -118,6 +118,11 @@ int main(int argc, char **argv)
{"tar", 2, 0, 0},
{"tgz", 2, 0, 0},
{"deb", 2, 0, 0},
/* developers only */
{"dev-ac-only", 0, 0, 0},
{"dev-ac-depth", 1, 0, 0},
{0, 0, 0, 0}
};

@ -66,6 +66,7 @@ extern "C"
/* db options */
#define CL_DB_HWACCEL 1
#define CL_DB_NOPHISHING 2
#define CL_DB_ACONLY 4 /* for developers only */
/* scan options */
#define CL_SCAN_RAW 0
@ -134,6 +135,7 @@ struct cli_meta_node {
struct cli_matcher {
unsigned int maxpatlen; /* maximal length of pattern in db */
unsigned short ac_only;
/* Extended Boyer-Moore */
int *bm_shift;

@ -291,9 +291,7 @@ int cli_addtypesigs(struct cl_engine *engine)
if(engine->hwaccel) {
cli_dbgmsg("cli_addtypesigs: AC depth 10 (hwaccel mode)\n");
root->ac_depth = 10;
} else {
root->ac_depth = AC_DEFAULT_DEPTH;
cli_ac_setdepth(10);
}
root->ac_root = (struct cli_ac_node *) cli_calloc(1, sizeof(struct cli_ac_node));

@ -42,17 +42,19 @@ struct nodelist {
struct nodelist *next;
};
unsigned short ac_depth = AC_DEFAULT_DEPTH;
int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
{
struct cli_ac_node *pos, *next;
int i;
if(pattern->length < root->ac_depth)
if(pattern->length < ac_depth)
return CL_EPATSHORT;
pos = root->ac_root;
for(i = 0; i < root->ac_depth; i++) {
for(i = 0; i < ac_depth; i++) {
next = pos->trans[((unsigned char) pattern->pattern[i]) & 0xff];
if(!next) {
@ -280,11 +282,11 @@ int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virnam
current = current->trans[(unsigned char) buffer[i] & 0xff];
if(current->islast) {
position = i - root->ac_depth + 1;
position = i - ac_depth + 1;
pt = current->list;
while(pt) {
if(cli_findpos(buffer, root->ac_depth, position, length, pt)) {
if(cli_findpos(buffer, ac_depth, position, length, pt)) {
if((pt->offset || pt->target) && (!pt->sigid || pt->partno == 1)) {
if(ftype == CL_TYPE_UNKNOWN_TEXT)
t = type;
@ -360,3 +362,8 @@ int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virnam
return otfrec ? type : CL_CLEAN;
}
void cli_ac_setdepth(unsigned int depth)
{
ac_depth = depth;
}

@ -28,5 +28,6 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern);
int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cli_matcher *root, int *partcnt, short otfrec, unsigned long int offset, unsigned long int *partoff, unsigned short ftype, int fd, unsigned long int *ftoffset);
int cli_ac_buildtrie(struct cli_matcher *root);
void cli_ac_free(struct cli_matcher *root);
void cli_ac_setdepth(unsigned int depth);
#endif

@ -88,7 +88,7 @@ int cli_scanbuff(const char *buffer, unsigned int length, const char **virname,
return CL_EMEM;
}
if((ret = cli_bm_scanbuff(buffer, length, virname, troot, 0, ftype, -1)) != CL_VIRUS)
if(troot->ac_only || (ret = cli_bm_scanbuff(buffer, length, virname, troot, 0, ftype, -1)) != CL_VIRUS)
ret = cli_ac_scanbuff(buffer, length, virname, troot, partcnt, 0, 0, partoff, ftype, -1, NULL);
free(partcnt);
@ -109,7 +109,7 @@ int cli_scanbuff(const char *buffer, unsigned int length, const char **virname,
return CL_EMEM;
}
if((ret = cli_bm_scanbuff(buffer, length, virname, groot, 0, ftype, -1)) != CL_VIRUS)
if(groot->ac_only || (ret = cli_bm_scanbuff(buffer, length, virname, groot, 0, ftype, -1)) != CL_VIRUS)
ret = cli_ac_scanbuff(buffer, length, virname, groot, partcnt, 0, 0, partoff, ftype, -1, NULL);
free(partcnt);
@ -371,8 +371,10 @@ int cli_scandesc(int desc, const char **virname, long int *scanned, const struct
length -= SCANBUFF - bytes;
if(troot) {
if(cli_bm_scanbuff(pt, length, virname, troot, offset, ftype, desc) == CL_VIRUS ||
(ret = cli_ac_scanbuff(pt, length, virname, troot, tpartcnt, otfrec, offset, tpartoff, ftype, desc, ftoffset)) == CL_VIRUS) {
if(troot->ac_only || (ret = cli_bm_scanbuff(pt, length, virname, troot, offset, ftype, desc)) != CL_VIRUS)
ret = cli_ac_scanbuff(pt, length, virname, troot, tpartcnt, otfrec, offset, tpartoff, ftype, desc, ftoffset);
if(ret == CL_VIRUS) {
free(buffer);
free(gpartcnt);
free(gpartoff);
@ -387,8 +389,10 @@ int cli_scandesc(int desc, const char **virname, long int *scanned, const struct
}
}
if(cli_bm_scanbuff(pt, length, virname, groot, offset, ftype, desc) == CL_VIRUS ||
(ret = cli_ac_scanbuff(pt, length, virname, groot, gpartcnt, otfrec, offset, gpartoff, ftype, desc, ftoffset)) == CL_VIRUS) {
if(groot->ac_only || (ret = cli_bm_scanbuff(pt, length, virname, groot, offset, ftype, desc)) != CL_VIRUS)
ret = cli_ac_scanbuff(pt, length, virname, groot, gpartcnt, otfrec, offset, gpartoff, ftype, desc, ftoffset);
if(ret == CL_VIRUS) {
free(buffer);
free(gpartcnt);
free(gpartoff);
@ -534,7 +538,8 @@ void cl_free(struct cl_engine *engine)
for(i = 0; i < CL_TARGET_TABLE_SIZE; i++) {
if((root = engine->root[i])) {
cli_ac_free(root);
cli_bm_free(root);
if(!engine->root[i]->ac_only)
cli_bm_free(root);
}
}

@ -373,7 +373,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
free(pt);
}
} else if(strpbrk(hexsig, "?(") || type) {
} else if(root->ac_only || strpbrk(hexsig, "?(") || type) {
if((ret = cli_ac_addsig(root, virname, hexsig, 0, 0, 0, type, 0, 0, offset, target))) {
cli_errmsg("cli_parse_add(): Problem adding signature (3).\n");
return ret;
@ -428,7 +428,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
return 0;
}
static int cli_initengine(struct cl_engine **engine)
static int cli_initengine(struct cl_engine **engine, unsigned int options)
{
struct cli_matcher *root;
int i, ret;
@ -456,7 +456,7 @@ static int cli_initengine(struct cl_engine **engine)
return 0;
}
static int cli_initroots(struct cl_engine *engine)
static int cli_initroots(struct cl_engine *engine, unsigned int options)
{
int i, ret;
struct cli_matcher *root;
@ -471,8 +471,12 @@ static int cli_initroots(struct cl_engine *engine)
return CL_EMEM;
}
if(options & CL_DB_ACONLY) {
cli_dbgmsg("Only using AC pattern matcher.\n");
root->ac_only = 1;
}
cli_dbgmsg("Initialising AC pattern matcher of root[%d]\n", i);
root->ac_depth = AC_DEFAULT_DEPTH;
root->ac_root = (struct cli_ac_node *) cli_calloc(1, sizeof(struct cli_ac_node));
if(!root->ac_root) {
/* no need to free previously allocated memory here */
@ -480,10 +484,12 @@ static int cli_initroots(struct cl_engine *engine)
return CL_EMEM;
}
cli_dbgmsg("Initializing BM tables of root[%d]\n", i);
if((ret = cli_bm_init(root))) {
cli_errmsg("Can't initialise BM pattern matcher\n");
return ret;
if(!root->ac_only) {
cli_dbgmsg("Initializing BM tables of root[%d]\n", i);
if((ret = cli_bm_init(root))) {
cli_errmsg("Can't initialise BM pattern matcher\n");
return ret;
}
}
}
}
@ -498,12 +504,12 @@ static int cli_loaddb(FILE *fd, struct cl_engine **engine, unsigned int *signo,
struct cli_matcher *root;
if((ret = cli_initengine(engine))) {
if((ret = cli_initengine(engine, options))) {
cl_free(*engine);
return ret;
}
if((ret = cli_initroots(*engine))) {
if((ret = cli_initroots(*engine, options))) {
cl_free(*engine);
return ret;
}
@ -560,12 +566,12 @@ static int cli_loadndb(FILE *fd, struct cl_engine **engine, unsigned int *signo,
unsigned int nophish = options & CL_DB_NOPHISHING;
if((ret = cli_initengine(engine))) {
if((ret = cli_initengine(engine, options))) {
cl_free(*engine);
return ret;
}
if((ret = cli_initroots(*engine))) {
if((ret = cli_initroots(*engine, options))) {
cl_free(*engine);
return ret;
}
@ -681,7 +687,7 @@ static int cli_loadhdb(FILE *fd, struct cl_engine **engine, unsigned int *signo,
struct cli_md5_node *new;
if((ret = cli_initengine(engine))) {
if((ret = cli_initengine(engine, options))) {
cl_free(*engine);
return ret;
}
@ -769,7 +775,7 @@ static int cli_loadmd(FILE *fd, struct cl_engine **engine, unsigned int *signo,
struct cli_meta_node *new;
if((ret = cli_initengine(engine))) {
if((ret = cli_initengine(engine, options))) {
cl_free(*engine);
return ret;
}
@ -1069,7 +1075,7 @@ int cl_load(const char *path, struct cl_engine **engine, unsigned int *signo, un
return CL_EIO;
}
if((ret = cli_initengine(engine))) {
if((ret = cli_initengine(engine, options))) {
cl_free(*engine);
return ret;
}

Loading…
Cancel
Save