[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
Török Edvin
edwin at clamav.net
Sun Apr 4 01:04:41 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit a1781898ecf725f86e4d4979edbc3c688fde92e8
Author: Török Edvin <edwin at clamav.net>
Date: Tue Sep 8 22:25:33 2009 +0300
inputfile support
diff --git a/clambc/bcrun.c b/clambc/bcrun.c
index d382b6f..404e23d 100644
--- a/clambc/bcrun.c
+++ b/clambc/bcrun.c
@@ -28,7 +28,9 @@
#include "shared/optparser.h"
#include "shared/misc.h"
+#include <fcntl.h>
#include <stdlib.h>
+#include <errno.h>
static void help(void)
{
@@ -52,8 +54,10 @@ int main(int argc, char *argv[])
struct cli_bc_ctx *ctx;
int rc, dbgargc;
struct optstruct *opts;
+ const struct optstruct *opt;
unsigned funcid=0, i;
struct cli_all_bc bcs;
+ unsigned int fd = -1;
opts = optparse(NULL, argc, argv, 1, OPT_CLAMBC, 0, NULL);
if (!opts) {
@@ -151,6 +155,22 @@ int main(int argc, char *argv[])
}
}
+ if ((opt = optget(opts,"input"))->enabled) {
+ fd = open(opt->strarg, O_RDONLY);
+ if (fd == -1) {
+ fprintf(stderr, "Unable to open input file %s: %s\n", opt->strarg, strerror(errno));
+ optfree(opts);
+ exit(5);
+ }
+ rc = cli_bytecode_context_setfile(ctx, fd);
+ if (rc != CL_SUCCESS) {
+ fprintf(stderr, "Unable to set file %s: %s\n", opt->strarg, cl_strerror(rc));
+ optfree(opts);
+ exit(5);
+ }
+ }
+
+
rc = cli_bytecode_run(&bcs, bc, ctx);
if (rc != CL_SUCCESS) {
fprintf(stderr,"Unable to run bytecode: %s\n", cl_strerror(rc));
@@ -165,6 +185,8 @@ int main(int argc, char *argv[])
cli_bytecode_done(&bcs);
free(bc);
optfree(opts);
+ if (fd != -1)
+ close(fd);
printf("Exiting\n");
return 0;
}
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index a8c059a..a8e28f5 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -1249,3 +1249,13 @@ int cli_bytecode_done(struct cli_all_bc *allbc)
return cli_bytecode_done_jit(allbc);
}
+int cli_bytecode_context_setfile(struct cli_bc_ctx *ctx, int fd)
+{
+ struct stat buf;
+ ctx->fd = fd;
+ if (fstat(fd, &buf) == -1)
+ return CL_ESTAT;
+ ctx->file_size = buf.st_size;
+ return 0;
+}
+
diff --git a/libclamav/bytecode.h b/libclamav/bytecode.h
index 90b8630..2026318 100644
--- a/libclamav/bytecode.h
+++ b/libclamav/bytecode.h
@@ -64,6 +64,7 @@ struct cli_bc_ctx *cli_bytecode_context_alloc(void);
int cli_bytecode_context_setfuncid(struct cli_bc_ctx *ctx, const struct cli_bc *bc, unsigned funcid);
int cli_bytecode_context_setparam_int(struct cli_bc_ctx *ctx, unsigned i, uint64_t c);
int cli_bytecode_context_setparam_ptr(struct cli_bc_ctx *ctx, unsigned i, void *data, unsigned datalen);
+int cli_bytecode_context_setfile(struct cli_bc_ctx *ctx, int fd);
int cli_bytecode_context_clear(struct cli_bc_ctx *ctx);
uint64_t cli_bytecode_context_getresult_int(struct cli_bc_ctx *ctx);
void cli_bytecode_context_destroy(struct cli_bc_ctx *ctx);
diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c
index 1bb22c2..2286fe5 100644
--- a/libclamav/bytecode_api.c
+++ b/libclamav/bytecode_api.c
@@ -50,6 +50,8 @@ int32_t cli_bcapi_read(struct cli_bc_ctx* ctx, uint8_t *data, int32_t size)
int32_t cli_bcapi_seek(struct cli_bc_ctx* ctx, int32_t pos, uint32_t whence)
{
off_t off;
+ if (ctx->fd == -1)
+ return -1;
switch (whence) {
case 0:
off = pos;
diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index 8641ddb..e26a11e 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -379,6 +379,7 @@ public:
case OP_GEP2:
case OP_GEPN:
case OP_STORE:
+ case OP_COPY:
// these instructions represents operands differently
break;
default:
@@ -529,8 +530,13 @@ public:
Store(inst->dest, Builder.CreateSelect(Op0, Op1, Op2));
break;
case OP_COPY:
- Builder.CreateStore(Op0, Op1);
+ {
+ Value *Dest = Values[inst->u.binop[1]];
+ const PointerType *PTy = cast<PointerType>(Dest->getType());
+ Op0 = convertOperand(func, PTy->getElementType(), inst->u.binop[0]);
+ Builder.CreateStore(Op0, Dest);
break;
+ }
case OP_CALL_DIRECT:
{
Function *DestF = Functions[inst->u.ops.funcid];
@@ -594,6 +600,7 @@ public:
break;
}
case OP_LOAD:
+ Op0 = Builder.CreateLoad(Op0);
Store(inst->dest, Op0);
break;
default:
diff --git a/libclamav/libclamav.map b/libclamav/libclamav.map
index ecf15ab..e925b97 100644
--- a/libclamav/libclamav.map
+++ b/libclamav/libclamav.map
@@ -154,6 +154,7 @@ CLAMAV_PRIVATE {
cli_bytecode_context_setfuncid;
cli_bytecode_context_setparam_int;
cli_bytecode_context_setparam_ptr;
+ cli_bytecode_context_setfile;
cli_bytecode_context_getresult_int;
cli_bytecode_context_clear;
cli_bytecode_init;
diff --git a/shared/optparser.c b/shared/optparser.c
index 8b03f15..388df25 100644
--- a/shared/optparser.c
+++ b/shared/optparser.c
@@ -118,7 +118,8 @@ const struct clam_option clam_options[] = {
{ NULL, "non-default", 'n', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMCONF, "", "" },
{ NULL, "generate-config", 'g', TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMCONF, "", "" },
- { NULL, "force-interpreter", 'f', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMBC, "", "" },
+ { NULL, "force-interpreter", 'f', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMBC, "Force using the interpreter instead of the JIT", "" },
+ { NULL, "input", 'i', TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMBC, "Input file to run the bytecode n", ""},
/* cmdline only - deprecated */
{ NULL, "http-proxy", 0, TYPE_STRING, NULL, 0, NULL, 0, OPT_FRESHCLAM | OPT_DEPRECATED, "", "" },
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list