[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:23:31 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 6ad39a409987b9befa05ca4157b4181db098a815
Author: Török Edvin <edwin at clamav.net>
Date: Sun Mar 21 12:56:05 2010 +0200
zlib/buffer apis.
diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c
index 7b97efd..987c822 100644
--- a/libclamav/bytecode_api.c
+++ b/libclamav/bytecode_api.c
@@ -467,37 +467,266 @@ int32_t cli_bcapi_hashset_done(struct cli_bc_ctx *ctx , int32_t id)
{
}
-int32_t cli_bcapi_inflate_init(struct cli_bc_ctx *ctx)
+int32_t cli_bcapi_buffer_pipe_new(struct cli_bc_ctx *ctx, uint32_t size)
{
- z_stream *s;
- s = cli_realloc(ctx->z_streams, (ctx->z_nstreams+1)*sizeof(*ctx->z_streams));
- if (!s)
+ unsigned char *data;
+ struct bc_buffer *b;
+ unsigned n = ctx->nbuffers + 1;
+
+ data = cli_malloc(size);
+ if (!data)
+ return -1;
+ b = cli_realloc(ctx->buffers, sizeof(*ctx->buffers)*n);
+ if (!b) {
+ free(data);
+ return -1;
+ }
+ ctx->buffers = b;
+ ctx->nbuffers = n;
+ b = &b[n-1];
+
+ b->data = data;
+ b->size = size;
+ b->write_cursor = b->read_cursor = 0;
+ return n-1;
+}
+
+int32_t cli_bcapi_buffer_pipe_new_fromfile(struct cli_bc_ctx *ctx , uint32_t at)
+{
+ struct bc_buffer *b;
+ unsigned n = ctx->nbuffers + 1;
+
+ if (at >= ctx->file_size)
+ return -1;
+
+ b = cli_realloc(ctx->buffers, sizeof(*ctx->buffers)*n);
+ if (!b) {
+ return -1;
+ }
+ b = &b[n-1];
+ ctx->buffers = b;
+ ctx->nbuffers = n;
+
+ /* NULL data means read from file at pos read_cursor */
+ b->data = NULL;
+ b->size = 0;
+ b->read_cursor = at;
+ b->write_cursor = 0;
+}
+
+static struct bc_buffer *get_buffer(struct cli_bc_ctx *ctx, int32_t id)
+{
+ if (!ctx->buffers || id < 0 || id >= ctx->nbuffers)
+ return NULL;
+ return &ctx->buffers[id];
+}
+
+uint32_t cli_bcapi_buffer_pipe_read_avail(struct cli_bc_ctx *ctx , int32_t id)
+{
+ struct bc_buffer *b = get_buffer(ctx, id);
+ if (!b)
+ return 0;
+ if (b->data) {
+ if (b->write_cursor <= b->read_cursor)
+ return 0;
+ return b->write_cursor - b->read_cursor;
+ }
+ if (!ctx->fmap || ctx->off >= ctx->file_size)
+ return 0;
+ if (ctx->off + BUFSIZ <= ctx->file_size)
+ return BUFSIZ;
+ return ctx->file_size - ctx->off;
+}
+
+uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t id, uint32_t size)
+{
+ struct bc_buffer *b = get_buffer(ctx, id);
+ if (!b || size > cli_bcapi_buffer_pipe_read_avail(ctx, id) || !size)
+ return NULL;
+ if (b->data)
+ return b->data + b->read_cursor;
+ return fmap_need_off(ctx->fmap, b->read_cursor, size);
+}
+
+int32_t cli_bcapi_buffer_pipe_read_stopped(struct cli_bc_ctx *ctx , int32_t id, uint32_t amount)
+{
+ struct bc_buffer *b = get_buffer(ctx, id);
+ if (!b)
+ return -1;
+ if (b->data) {
+ if (b->write_cursor <= b->read_cursor)
+ return -1;
+ if (b->read_cursor + amount > b->write_cursor)
+ b->read_cursor = b->write_cursor;
+ else
+ b->read_cursor += amount;
+ if (b->read_cursor >= b->size &&
+ b->write_cursor >= b->size)
+ b->read_cursor = b->write_cursor = 0;
+ return 0;
+ }
+ b->read_cursor += amount;
+ return 0;
+}
+
+uint32_t cli_bcapi_buffer_pipe_write_avail(struct cli_bc_ctx *ctx, int32_t id)
+{
+ struct bc_buffer *b = get_buffer(ctx, id);
+ if (!b)
+ return 0;
+ if (!b->data)
+ return 0;
+ if (b->write_cursor >= b->size)
+ return 0;
+ return b->size - b->write_cursor;
+}
+
+uint8_t* cli_bcapi_buffer_pipe_write_get(struct cli_bc_ctx *ctx, int32_t id, uint32_t size)
+{
+ struct bc_buffer *b = get_buffer(ctx, id);
+ if (!b || size > cli_bcapi_buffer_pipe_write_avail(ctx, id) || !size)
+ return NULL;
+ if (!b->data)
+ return NULL;
+ return b->data + b->write_cursor;
+}
+
+int32_t cli_bcapi_buffer_pipe_write_stopped(struct cli_bc_ctx *ctx , int32_t id, uint32_t size)
+{
+ struct bc_buffer *b = get_buffer(ctx, id);
+ if (!b || !b->data)
+ return -1;
+ if (b->write_cursor + size >= b->size)
+ b->write_cursor = b->size;
+ else
+ b->write_cursor += size;
+ return 0;
+}
+
+int32_t cli_bcapi_buffer_pipe_done(struct cli_bc_ctx *ctx , int32_t id)
+{
+ /* TODO */
+}
+
+int32_t cli_bcapi_inflate_init(struct cli_bc_ctx *ctx, int32_t from, int32_t to, int32_t windowBits)
+{
+ int ret;
+ z_stream stream;
+ struct bc_inflate *b;
+ unsigned n = ctx->ninflates + 1;
+ if (!get_buffer(ctx, from) || !get_buffer(ctx, to))
+ return -1;
+ memset(&stream, 0, sizeof(stream));
+ ret = inflateInit2(&stream, windowBits);
+ switch (ret) {
+ case Z_MEM_ERROR:
+ cli_dbgmsg("bytecode api: inflateInit2: out of memory!\n");
+ return -1;
+ case Z_VERSION_ERROR:
+ cli_dbgmsg("bytecode api: inflateinit2: zlib version error!\n");
+ return -1;
+ case Z_STREAM_ERROR:
+ cli_dbgmsg("bytecode api: inflateinit2: zlib stream error!\n");
+ return -1;
+ case Z_OK:
+ break;
+ default:
+ cli_dbgmsg("bytecode api: inflateInit2: unknown error %d\n", ret);
+ return -1;
+ }
+
+ b = cli_realloc(ctx->inflates, sizeof(*ctx->inflates)*n);
+ if (!b) {
+ inflateEnd(&stream);
return -1;
- ctx->z_streams = s;
- ctx->z_nstreams++;
- s = &s[ctx->z_nstreams-1];
- memset(s, 0, sizeof(*s));
- return inflateInit2(s, MAX_WBITS+16);
+ }
+ ctx->inflates = b;
+ ctx->ninflates = n;
+ b = &b[n-1];
+
+ b->from = from;
+ b->to = to;
+ b->needSync = 0;
+ memcpy(&b->stream, &stream, sizeof(stream));
+ return n-1;
}
-int32_t cli_bcapi_inflate_process(struct cli_bc_ctx *ctx , int32_t id,
- uint8_t* in, uint32_t in_size,
- uint8_t* out, uint32_t out_size)
+static struct bc_inflate *get_inflate(struct cli_bc_ctx *ctx, int32_t id)
{
- if (id >= ctx->z_nstreams)
+ if (id < 0 || id >= ctx->ninflates || !ctx->inflates)
+ return NULL;
+ return &ctx->inflates[id];
+}
+
+int32_t cli_bcapi_inflate_process(struct cli_bc_ctx *ctx , int32_t id)
+{
+ int ret;
+ unsigned avail_in_orig, avail_out_orig;
+ struct bc_inflate *b = get_inflate(ctx, id);
+ if (!b)
+ return -1;
+
+ b->stream.avail_in = avail_in_orig =
+ cli_bcapi_buffer_pipe_read_avail(ctx, b->from);
+
+ b->stream.next_in = cli_bcapi_buffer_pipe_read_get(ctx, b->from,
+ b->stream.avail_in);
+
+ b->stream.avail_out = avail_out_orig =
+ cli_bcapi_buffer_pipe_write_avail(ctx, b->to);
+
+ b->stream.next_out = cli_bcapi_buffer_pipe_write_get(ctx, b->to,
+ b->stream.avail_out);
+
+ if (!b->stream.avail_in || !b->stream.avail_out)
return -1;
- z_stream *s = &ctx->z_streams[id];
- s->next_in = in;
- s->avail_in = in_size;
- s->next_out = out;
- s->avail_out = out_size;
- return inflate(s, 0);
+ /* try hard to extract data, skipping over corrupted data */
+ do {
+ if (!b->needSync) {
+ ret = inflate(&b->stream, Z_NO_FLUSH);
+ if (ret == Z_DATA_ERROR) {
+ cli_dbgmsg("bytecode api: inflate at %u: %s\n", b->stream.total_in,
+ b->stream.msg);
+ b->needSync = 1;
+ }
+ }
+ if (b->needSync) {
+ ret = inflateSync(&b->stream);
+ if (ret == Z_OK) {
+ b->needSync = 0;
+ continue;
+ }
+ }
+ break;
+ } while (1);
+ cli_bcapi_buffer_pipe_read_stopped(ctx, b->from, avail_in_orig - b->stream.avail_in);
+ cli_bcapi_buffer_pipe_write_stopped(ctx, b->to, avail_out_orig - b->stream.avail_out);
+
+ if (ret == Z_MEM_ERROR) {
+ cli_dbgmsg("bytecode api: out of memory!\n");
+ cli_bcapi_inflate_done(ctx, id);
+ return ret;
+ }
+ if (ret == Z_STREAM_END) {
+ cli_bcapi_inflate_done(ctx, id);
+ }
+ if (ret == Z_BUF_ERROR) {
+ cli_dbgmsg("bytecode api: buffer error!\n");
+ }
+
+ return ret;
}
int32_t cli_bcapi_inflate_done(struct cli_bc_ctx *ctx , int32_t id)
{
- if (id >= ctx->z_nstreams)
+ int ret;
+ struct bc_inflate *b = get_inflate(ctx, id);
+ if (!b || b->from == -1 || b->to == -1)
return -1;
- z_stream *s = &ctx->z_streams[id];
- return inflateEnd(s);
+ ret = inflateEnd(&b->stream);
+ if (ret == Z_STREAM_ERROR)
+ cli_dbgmsg("bytecode api: inflateEnd: %s\n", b->stream.msg);
+ b->from = b->to = -1;
+ return ret;
}
+
diff --git a/libclamav/bytecode_api.h b/libclamav/bytecode_api.h
index 7fafe1b..3c04ce6 100644
--- a/libclamav/bytecode_api.h
+++ b/libclamav/bytecode_api.h
@@ -230,9 +230,18 @@ int32_t hashset_remove(int32_t hs, uint32_t key);
int32_t hashset_contains(int32_t hs, uint32_t key);
int32_t hashset_done(int32_t id);
-int32_t inflate_init(void);
-int32_t inflate_process(int32_t id, uint8_t *input, uint32_t input_size,
- uint8_t *output, uint32_t output_size);
+int32_t buffer_pipe_new(uint32_t size);
+int32_t buffer_pipe_new_fromfile(uint32_t pos);
+uint32_t buffer_pipe_read_avail(int32_t id);
+uint8_t *buffer_pipe_read_get(int32_t id, uint32_t amount);
+int32_t buffer_pipe_read_stopped(int32_t id, uint32_t amount);
+uint32_t buffer_pipe_write_avail(int32_t id);
+uint8_t *buffer_pipe_write_get(int32_t id, uint32_t size);
+int32_t buffer_pipe_write_stopped(int32_t id, uint32_t amount);
+int32_t buffer_pipe_done(int32_t id);
+
+int32_t inflate_init(int32_t from_buffer, int32_t to_buffer, int32_t windowBits);
+int32_t inflate_process(int32_t id);
int32_t inflate_done(int32_t id);
#endif
diff --git a/libclamav/bytecode_api_decl.c b/libclamav/bytecode_api_decl.c
index 85447a8..a53bad9 100644
--- a/libclamav/bytecode_api_decl.c
+++ b/libclamav/bytecode_api_decl.c
@@ -61,8 +61,17 @@ int32_t cli_bcapi_hashset_add(struct cli_bc_ctx *ctx , int32_t, uint32_t);
int32_t cli_bcapi_hashset_remove(struct cli_bc_ctx *ctx , int32_t, uint32_t);
int32_t cli_bcapi_hashset_contains(struct cli_bc_ctx *ctx , int32_t, uint32_t);
int32_t cli_bcapi_hashset_done(struct cli_bc_ctx *ctx , int32_t);
-int32_t cli_bcapi_inflate_init(struct cli_bc_ctx *ctx );
-int32_t cli_bcapi_inflate_process(struct cli_bc_ctx *ctx , int32_t, uint8_t*, uint32_t, uint8_t*, uint32_t);
+int32_t cli_bcapi_buffer_pipe_new(struct cli_bc_ctx *ctx , uint32_t);
+int32_t cli_bcapi_buffer_pipe_new_fromfile(struct cli_bc_ctx *ctx , uint32_t);
+uint32_t cli_bcapi_buffer_pipe_read_avail(struct cli_bc_ctx *ctx , int32_t);
+uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+int32_t cli_bcapi_buffer_pipe_read_stopped(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+uint32_t cli_bcapi_buffer_pipe_write_avail(struct cli_bc_ctx *ctx , int32_t);
+uint8_t* cli_bcapi_buffer_pipe_write_get(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+int32_t cli_bcapi_buffer_pipe_write_stopped(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+int32_t cli_bcapi_buffer_pipe_done(struct cli_bc_ctx *ctx , int32_t);
+int32_t cli_bcapi_inflate_init(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t);
+int32_t cli_bcapi_inflate_process(struct cli_bc_ctx *ctx , int32_t);
int32_t cli_bcapi_inflate_done(struct cli_bc_ctx *ctx , int32_t);
const struct cli_apiglobal cli_globals[] = {
@@ -87,21 +96,22 @@ static uint16_t cli_tmp5[]={32, 16, 16, 32, 32, 32, 16, 16};
static uint16_t cli_tmp6[]={32};
static uint16_t cli_tmp7[]={32};
static uint16_t cli_tmp8[]={32, 32};
-static uint16_t cli_tmp9[]={32, 32, 65, 32, 65, 32};
-static uint16_t cli_tmp10[]={32};
-static uint16_t cli_tmp11[]={32, 32, 32};
-static uint16_t cli_tmp12[]={32, 65, 32, 32, 32, 32};
-static uint16_t cli_tmp13[]={32, 83, 32};
-static uint16_t cli_tmp14[]={84};
-static uint16_t cli_tmp15[]={32, 32, 32, 32, 32, 32, 32, 32, 32};
-static uint16_t cli_tmp16[]={65, 32};
-static uint16_t cli_tmp17[]={32, 65, 32};
-static uint16_t cli_tmp18[]={32, 88, 32};
-static uint16_t cli_tmp19[]={89};
-static uint16_t cli_tmp20[]={16, 8, 8, 8, 91, 90};
-static uint16_t cli_tmp21[]={8};
-static uint16_t cli_tmp22[]={92};
-static uint16_t cli_tmp23[]={8};
+static uint16_t cli_tmp9[]={32, 32, 32, 32};
+static uint16_t cli_tmp10[]={32, 32, 32};
+static uint16_t cli_tmp11[]={65, 32, 32};
+static uint16_t cli_tmp12[]={32};
+static uint16_t cli_tmp13[]={32, 65, 32, 32, 32, 32};
+static uint16_t cli_tmp14[]={32, 84, 32};
+static uint16_t cli_tmp15[]={85};
+static uint16_t cli_tmp16[]={32, 32, 32, 32, 32, 32, 32, 32, 32};
+static uint16_t cli_tmp17[]={65, 32};
+static uint16_t cli_tmp18[]={32, 65, 32};
+static uint16_t cli_tmp19[]={32, 89, 32};
+static uint16_t cli_tmp20[]={90};
+static uint16_t cli_tmp21[]={16, 8, 8, 8, 92, 91};
+static uint16_t cli_tmp22[]={8};
+static uint16_t cli_tmp23[]={93};
+static uint16_t cli_tmp24[]={8};
const struct cli_bc_type cli_apicall_types[]={
{DStructType, cli_tmp0, 11, 0, 0},
@@ -113,57 +123,67 @@ const struct cli_bc_type cli_apicall_types[]={
{DArrayType, cli_tmp6, 1, 0, 0},
{DArrayType, cli_tmp7, 64, 0, 0},
{DFunctionType, cli_tmp8, 2, 0, 0},
- {DFunctionType, cli_tmp9, 6, 0, 0},
- {DFunctionType, cli_tmp10, 1, 0, 0},
+ {DFunctionType, cli_tmp9, 4, 0, 0},
+ {DFunctionType, cli_tmp10, 3, 0, 0},
{DFunctionType, cli_tmp11, 3, 0, 0},
- {DFunctionType, cli_tmp12, 6, 0, 0},
- {DFunctionType, cli_tmp13, 3, 0, 0},
- {DPointerType, cli_tmp14, 1, 0, 0},
- {DStructType, cli_tmp15, 9, 0, 0},
- {DFunctionType, cli_tmp16, 2, 0, 0},
- {DFunctionType, cli_tmp17, 3, 0, 0},
+ {DFunctionType, cli_tmp12, 1, 0, 0},
+ {DFunctionType, cli_tmp13, 6, 0, 0},
+ {DFunctionType, cli_tmp14, 3, 0, 0},
+ {DPointerType, cli_tmp15, 1, 0, 0},
+ {DStructType, cli_tmp16, 9, 0, 0},
+ {DFunctionType, cli_tmp17, 2, 0, 0},
{DFunctionType, cli_tmp18, 3, 0, 0},
- {DPointerType, cli_tmp19, 1, 0, 0},
- {DStructType, cli_tmp20, 6, 0, 0},
- {DArrayType, cli_tmp21, 29, 0, 0},
- {DArrayType, cli_tmp22, 3, 0, 0},
- {DArrayType, cli_tmp23, 10, 0, 0}
+ {DFunctionType, cli_tmp19, 3, 0, 0},
+ {DPointerType, cli_tmp20, 1, 0, 0},
+ {DStructType, cli_tmp21, 6, 0, 0},
+ {DArrayType, cli_tmp22, 29, 0, 0},
+ {DArrayType, cli_tmp23, 3, 0, 0},
+ {DArrayType, cli_tmp24, 10, 0, 0}
};
const unsigned cli_apicall_maxtypes=sizeof(cli_apicall_types)/sizeof(cli_apicall_types[0]);
const struct cli_apicall cli_apicalls[]={
/* Bytecode APIcalls BEGIN */
- {"test1", 11, 0, 0},
- {"read", 17, 0, 1},
- {"write", 17, 1, 1},
- {"seek", 11, 1, 0},
- {"setvirusname", 17, 2, 1},
- {"debug_print_str", 17, 3, 1},
+ {"test1", 10, 0, 0},
+ {"read", 18, 0, 1},
+ {"write", 18, 1, 1},
+ {"seek", 10, 1, 0},
+ {"setvirusname", 18, 2, 1},
+ {"debug_print_str", 18, 3, 1},
{"debug_print_uint", 8, 0, 2},
- {"disasm_x86", 18, 4, 1},
- {"trace_directory", 17, 5, 1},
- {"trace_scope", 17, 6, 1},
- {"trace_source", 17, 7, 1},
- {"trace_op", 17, 8, 1},
- {"trace_value", 17, 9, 1},
- {"trace_ptr", 17, 10, 1},
+ {"disasm_x86", 19, 4, 1},
+ {"trace_directory", 18, 5, 1},
+ {"trace_scope", 18, 6, 1},
+ {"trace_source", 18, 7, 1},
+ {"trace_op", 18, 8, 1},
+ {"trace_value", 18, 9, 1},
+ {"trace_ptr", 18, 10, 1},
{"pe_rawaddr", 8, 1, 2},
- {"file_find", 17, 11, 1},
+ {"file_find", 18, 11, 1},
{"file_byteat", 8, 2, 2},
- {"malloc", 16, 0, 3},
+ {"malloc", 17, 0, 3},
{"test2", 8, 3, 2},
- {"get_pe_section", 13, 12, 1},
- {"fill_buffer", 12, 0, 4},
+ {"get_pe_section", 14, 12, 1},
+ {"fill_buffer", 13, 0, 4},
{"extract_new", 8, 4, 2},
{"read_number", 8, 5, 2},
- {"hashset_new", 10, 0, 5},
- {"hashset_add", 11, 2, 0},
- {"hashset_remove", 11, 3, 0},
- {"hashset_contains", 11, 4, 0},
+ {"hashset_new", 12, 0, 5},
+ {"hashset_add", 10, 2, 0},
+ {"hashset_remove", 10, 3, 0},
+ {"hashset_contains", 10, 4, 0},
{"hashset_done", 8, 6, 2},
- {"inflate_init", 10, 1, 5},
- {"inflate_process", 9, 0, 6},
- {"inflate_done", 8, 7, 2}
+ {"buffer_pipe_new", 8, 7, 2},
+ {"buffer_pipe_new_fromfile", 8, 8, 2},
+ {"buffer_pipe_read_avail", 8, 9, 2},
+ {"buffer_pipe_read_get", 11, 0, 6},
+ {"buffer_pipe_read_stopped", 10, 5, 0},
+ {"buffer_pipe_write_avail", 8, 10, 2},
+ {"buffer_pipe_write_get", 11, 1, 6},
+ {"buffer_pipe_write_stopped", 10, 6, 0},
+ {"buffer_pipe_done", 8, 11, 2},
+ {"inflate_init", 9, 0, 7},
+ {"inflate_process", 8, 12, 2},
+ {"inflate_done", 8, 13, 2}
/* Bytecode APIcalls END */
};
const cli_apicall_int2 cli_apicalls0[] = {
@@ -171,7 +191,9 @@ const cli_apicall_int2 cli_apicalls0[] = {
(cli_apicall_int2)cli_bcapi_seek,
(cli_apicall_int2)cli_bcapi_hashset_add,
(cli_apicall_int2)cli_bcapi_hashset_remove,
- (cli_apicall_int2)cli_bcapi_hashset_contains
+ (cli_apicall_int2)cli_bcapi_hashset_contains,
+ (cli_apicall_int2)cli_bcapi_buffer_pipe_read_stopped,
+ (cli_apicall_int2)cli_bcapi_buffer_pipe_write_stopped
};
const cli_apicall_pointer cli_apicalls1[] = {
(cli_apicall_pointer)cli_bcapi_read,
@@ -196,6 +218,12 @@ const cli_apicall_int1 cli_apicalls2[] = {
(cli_apicall_int1)cli_bcapi_extract_new,
(cli_apicall_int1)cli_bcapi_read_number,
(cli_apicall_int1)cli_bcapi_hashset_done,
+ (cli_apicall_int1)cli_bcapi_buffer_pipe_new,
+ (cli_apicall_int1)cli_bcapi_buffer_pipe_new_fromfile,
+ (cli_apicall_int1)cli_bcapi_buffer_pipe_read_avail,
+ (cli_apicall_int1)cli_bcapi_buffer_pipe_write_avail,
+ (cli_apicall_int1)cli_bcapi_buffer_pipe_done,
+ (cli_apicall_int1)cli_bcapi_inflate_process,
(cli_apicall_int1)cli_bcapi_inflate_done
};
const cli_apicall_malloclike cli_apicalls3[] = {
@@ -205,10 +233,13 @@ const cli_apicall_ptrbuffdata cli_apicalls4[] = {
(cli_apicall_ptrbuffdata)cli_bcapi_fill_buffer
};
const cli_apicall_allocobj cli_apicalls5[] = {
- (cli_apicall_allocobj)cli_bcapi_hashset_new,
- (cli_apicall_allocobj)cli_bcapi_inflate_init
+ (cli_apicall_allocobj)cli_bcapi_hashset_new
};
-const cli_apicall_bufops cli_apicalls6[] = {
- (cli_apicall_bufops)cli_bcapi_inflate_process
+const cli_apicall_bufget cli_apicalls6[] = {
+ (cli_apicall_bufget)cli_bcapi_buffer_pipe_read_get,
+ (cli_apicall_bufget)cli_bcapi_buffer_pipe_write_get
+};
+const cli_apicall_int3 cli_apicalls7[] = {
+ (cli_apicall_int3)cli_bcapi_inflate_init
};
const unsigned cli_apicall_maxapi = sizeof(cli_apicalls)/sizeof(cli_apicalls[0]);
diff --git a/libclamav/bytecode_api_impl.h b/libclamav/bytecode_api_impl.h
index 733f253..55ce68b 100644
--- a/libclamav/bytecode_api_impl.h
+++ b/libclamav/bytecode_api_impl.h
@@ -58,8 +58,17 @@ int32_t cli_bcapi_hashset_add(struct cli_bc_ctx *ctx , int32_t, uint32_t);
int32_t cli_bcapi_hashset_remove(struct cli_bc_ctx *ctx , int32_t, uint32_t);
int32_t cli_bcapi_hashset_contains(struct cli_bc_ctx *ctx , int32_t, uint32_t);
int32_t cli_bcapi_hashset_done(struct cli_bc_ctx *ctx , int32_t);
-int32_t cli_bcapi_inflate_init(struct cli_bc_ctx *ctx );
-int32_t cli_bcapi_inflate_process(struct cli_bc_ctx *ctx , int32_t, uint8_t*, uint32_t, uint8_t*, uint32_t);
+int32_t cli_bcapi_buffer_pipe_new(struct cli_bc_ctx *ctx , uint32_t);
+int32_t cli_bcapi_buffer_pipe_new_fromfile(struct cli_bc_ctx *ctx , uint32_t);
+uint32_t cli_bcapi_buffer_pipe_read_avail(struct cli_bc_ctx *ctx , int32_t);
+uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+int32_t cli_bcapi_buffer_pipe_read_stopped(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+uint32_t cli_bcapi_buffer_pipe_write_avail(struct cli_bc_ctx *ctx , int32_t);
+uint8_t* cli_bcapi_buffer_pipe_write_get(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+int32_t cli_bcapi_buffer_pipe_write_stopped(struct cli_bc_ctx *ctx , int32_t, uint32_t);
+int32_t cli_bcapi_buffer_pipe_done(struct cli_bc_ctx *ctx , int32_t);
+int32_t cli_bcapi_inflate_init(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t);
+int32_t cli_bcapi_inflate_process(struct cli_bc_ctx *ctx , int32_t);
int32_t cli_bcapi_inflate_done(struct cli_bc_ctx *ctx , int32_t);
#endif
diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h
index eda35f6..2d3ad26 100644
--- a/libclamav/bytecode_priv.h
+++ b/libclamav/bytecode_priv.h
@@ -116,6 +116,21 @@ enum trace_level {
trace_op,
trace_val
};
+
+struct bc_buffer {
+ unsigned char *data;
+ unsigned size;
+ unsigned write_cursor;
+ unsigned read_cursor;
+};
+
+struct bc_inflate {
+ z_stream stream;
+ int32_t from;
+ int32_t to;
+ int8_t needSync;
+};
+
struct cli_bc_ctx {
/* id and params of toplevel function called */
const struct cli_bc *bc;
@@ -152,8 +167,10 @@ struct cli_bc_ctx {
mpool_t *mpool;
uint32_t numGlobals;
uint8_t* globals;
- z_stream* z_streams;
- unsigned z_nstreams;
+ struct bc_inflate* inflates;
+ unsigned ninflates;
+ struct bc_buffer *buffers;
+ unsigned nbuffers;
};
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 03537bd..e9cbf86 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -1408,6 +1408,9 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
case 6:
dest = (void*)(intptr_t)cli_apicalls6[api->idx];
break;
+ case 7:
+ dest = (void*)(intptr_t)cli_apicalls7[api->idx];
+ break;
default:
llvm_unreachable("invalid api type");
}
diff --git a/libclamav/type_desc.h b/libclamav/type_desc.h
index 1addb68..0d4b6eb 100644
--- a/libclamav/type_desc.h
+++ b/libclamav/type_desc.h
@@ -47,7 +47,8 @@ typedef uint32_t (*cli_apicall_int1)(struct cli_bc_ctx *, uint32_t);
typedef void* (*cli_apicall_malloclike)(struct cli_bc_ctx *, uint32_t);
typedef void* (*cli_apicall_ptrbuffdata)(struct cli_bc_ctx *, void*, uint32_t, uint32_t, uint32_t, uint32_t);
typedef int32_t (*cli_apicall_allocobj)(struct cli_bc_ctx *);
-typedef int32_t (*cli_apicall_bufops)(struct cli_bc_ctx *, int32_t, void*, uint32_t, void*, uint32_t);
+typedef void* (*cli_apicall_bufget)(struct cli_bc_ctx *, int32_t, uint32_t);
+typedef int32_t (*cli_apicall_int3)(struct cli_bc_ctx *, int32_t, int32_t, int32_t);
struct cli_apicall {
const char *name;
@@ -78,7 +79,8 @@ extern const cli_apicall_int1 cli_apicalls2[];
extern const cli_apicall_malloclike cli_apicalls3[];
extern const cli_apicall_ptrbuffdata cli_apicalls4[];
extern const cli_apicall_allocobj cli_apicalls5[];
-extern const cli_apicall_bufops cli_apicalls6[];
+extern const cli_apicall_bufget cli_apicalls6[];
+extern const cli_apicall_int3 cli_apicalls7[];
extern const unsigned cli_apicall_maxapi;
extern const unsigned cli_apicall_maxglobal;
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list