[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:12 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 4789b8a5a63f810913b37e06cac4d3ec548d3836
Author: Török Edvin <edwin at clamav.net>
Date: Fri Sep 4 17:29:13 2009 +0300
Add draft file API, doesn't work yet.
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 77a8e63..e986661 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -39,6 +39,8 @@ struct cli_bc_ctx *cli_bytecode_context_alloc(void)
ctx->values = NULL;
ctx->operands = NULL;
ctx->opsizes = NULL;
+ ctx->fd = -1;
+ ctx->off = 0;
return ctx;
}
@@ -940,8 +942,10 @@ int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio)
switch (state) {
case PARSE_BC_HEADER:
rc = parseHeader(bc, (unsigned char*)buffer);
- if (rc == CL_BREAK) /* skip */
+ if (rc == CL_BREAK) /* skip */ {
+ bc->state = bc_skip;
return CL_SUCCESS;
+ }
if (rc != CL_SUCCESS) {
cli_errmsg("Error at bytecode line %u\n", row);
return rc;
@@ -958,8 +962,10 @@ int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio)
break;
case PARSE_BC_APIS:
rc = parseApis(bc, (unsigned char*)buffer);
- if (rc == CL_BREAK) /* skip */
+ if (rc == CL_BREAK) /* skip */ {
+ bc->state = bc_skip;
return CL_SUCCESS;
+ }
if (rc != CL_SUCCESS) {
cli_errmsg("Error at bytecode line %u\n", row);
return rc;
diff --git a/libclamav/bytecode.h b/libclamav/bytecode.h
index 7e9f94d..c8cddb1 100644
--- a/libclamav/bytecode.h
+++ b/libclamav/bytecode.h
@@ -34,6 +34,7 @@ struct cli_bc_engine;
struct bitset_tag;
enum bc_state {
+ bc_skip,
bc_loaded,
bc_jit,
bc_interp
diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c
index e625e7b..4c63864 100644
--- a/libclamav/bytecode_api.c
+++ b/libclamav/bytecode_api.c
@@ -20,7 +20,10 @@
* MA 02110-1301, USA.
*/
+#include <stdlib.h>
#include "cltypes.h"
+#include "clambc.h"
+#include "bytecode_priv.h"
#include "type_desc.h"
#include "bytecode_api.h"
#include "bytecode_api_impl.h"
@@ -34,3 +37,30 @@ uint32_t cli_bcapi_test1(struct cli_bc_ctx *ctx, uint32_t a, uint32_t b)
{
return (a==0xf00dbeef && b==0xbeeff00d) ? 0x12345678 : 0x55;
}
+
+int32_t cli_bcapi_read(struct cli_bc_ctx* ctx, uint8_t *data, int32_t size)
+{
+ if (ctx->fd == -1)
+ return -1;
+ return pread(ctx->fd, data, size, ctx->off);
+}
+
+int32_t cli_bcapi_seek(struct cli_bc_ctx* ctx, int32_t pos, uint32_t whence)
+{
+ off_t off;
+ switch (whence) {
+ case 0:
+ off = pos;
+ break;
+ case 1:
+ off = ctx->off + pos;
+ break;
+ case 2:
+ off = ctx->file_size + pos;
+ break;
+ }
+ if (off < 0 || off > ctx->file_size)
+ return -1;
+ ctx->off = off;
+ return off;
+}
diff --git a/libclamav/bytecode_api.h b/libclamav/bytecode_api.h
index 86261d0..002b47f 100644
--- a/libclamav/bytecode_api.h
+++ b/libclamav/bytecode_api.h
@@ -30,5 +30,22 @@ struct foo {
struct foo *nxt;
};
+#ifdef __CLAMBC__
+
uint32_t test0(struct foo*, uint32_t);
uint32_t test1(uint32_t, uint32_t);
+
+/* reads @size bytes from current file (if any) to @data, returns amount read */
+int32_t read(uint8_t *data, int32_t size);
+
+enum {
+ SEEK_SET=0,
+ SEEK_CUR,
+ SEEK_END
+};
+
+/* seeks current position to @pos, from @whence, returns current position from
+ * start of file */
+int32_t seek(int32_t pos, uint32_t whence);
+
+#endif
diff --git a/libclamav/bytecode_api_decl.c b/libclamav/bytecode_api_decl.c
index 711b24c..9c1265c 100644
--- a/libclamav/bytecode_api_decl.c
+++ b/libclamav/bytecode_api_decl.c
@@ -26,30 +26,38 @@
uint32_t cli_bcapi_test0(struct cli_bc_ctx *ctx, struct foo*, uint32_t);
uint32_t cli_bcapi_test1(struct cli_bc_ctx *ctx, uint32_t, uint32_t);
+int32_t cli_bcapi_read(struct cli_bc_ctx *ctx, uint8_t*, int32_t);
+int32_t cli_bcapi_seek(struct cli_bc_ctx *ctx, int32_t, uint32_t);
static uint16_t cli_tmp0[]={32, 70, 32};
static uint16_t cli_tmp1[]={71};
static uint16_t cli_tmp2[]={70};
static uint16_t cli_tmp3[]={32, 32, 32};
+static uint16_t cli_tmp4[]={32, 65, 32};
const struct cli_bc_type cli_apicall_types[]={
{DFunctionType, cli_tmp0, 3},
{DPointerType, cli_tmp1, 1},
{DStructType, cli_tmp2, 1},
- {DFunctionType, cli_tmp3, 3}
+ {DFunctionType, cli_tmp3, 3},
+ {DFunctionType, cli_tmp4, 3}
};
const unsigned cli_apicall_maxtypes=sizeof(cli_apicall_types)/sizeof(cli_apicall_types[0]);
const struct cli_apicall cli_apicalls[]={
/* Bytecode APIcalls BEGIN */
{"test0", 0, 0, 1},
- {"test1", 3, 0, 0}
+ {"test1", 3, 0, 0},
+ {"read", 4, 1, 1},
+ {"seek", 3, 1, 0}
/* Bytecode APIcalls END */
};
const cli_apicall_int2 cli_apicalls0[] = {
- cli_bcapi_test1
+ cli_bcapi_test1,
+ cli_bcapi_seek
};
const cli_apicall_pointer cli_apicalls1[] = {
- (cli_apicall_pointer)cli_bcapi_test0
+ (cli_apicall_pointer)cli_bcapi_test0,
+ cli_bcapi_read
};
const unsigned cli_apicall_maxapi = sizeof(cli_apicalls)/sizeof(cli_apicalls[0]);
diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h
index 2bbc74a..71f282c 100644
--- a/libclamav/bytecode_priv.h
+++ b/libclamav/bytecode_priv.h
@@ -95,6 +95,9 @@ struct cli_bc_ctx {
operand_t *operands;
uint16_t funcid;
unsigned numParams;
+ size_t file_size;
+ off_t off;
+ int fd;
};
struct cli_all_bc;
int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst);
diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index 096f5bf..8641ddb 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -755,6 +755,8 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
for (unsigned i=0;i<bcs->count;i++) {
const struct cli_bc *bc = &bcs->all_bcs[i];
+ if (bc->state == bc_skip)
+ continue;
LLVMCodegen Codegen(bc, M, bcs->engine->compiledFunctions, EE,
OurFPM, apiFuncs);
if (!Codegen.generate()) {
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list