0.96
Török Edvin 16 years ago
parent dfc8208705
commit f6471bc9d6
  1. 1
      libclamav/bytecode.c
  2. 30
      libclamav/bytecode_api.c
  3. 8
      libclamav/bytecode_api.h
  4. 7
      libclamav/bytecode_api_decl.c
  5. 1
      libclamav/bytecode_api_impl.h
  6. 2
      libclamav/pe.c

@ -768,6 +768,7 @@ static void readConstant(struct cli_bc *bc, unsigned i, unsigned comp,
}
if (*ok && j != comp) {
cli_errmsg("bytecode: constant has too few subcomponents: %u < %u\n", j, comp);
// *ok = 0;
}
(*offset)++;
}

@ -414,7 +414,7 @@ int32_t cli_bcapi_extract_new(struct cli_bc_ctx *ctx, int32_t id)
(ftruncate(ctx->outfd, 0) == -1)) {
close(ctx->outfd);
if (!(cctx && cctx->engine->keeptmp))
if (!(cctx && cctx->engine->keeptmp) && ctx->tempfile)
cli_unlink(ctx->tempfile);
free(ctx->tempfile);
ctx->tempfile = NULL;
@ -423,3 +423,31 @@ int32_t cli_bcapi_extract_new(struct cli_bc_ctx *ctx, int32_t id)
cli_dbgmsg("bytecode: extracting new file with id %u\n", id);
return res;
}
#define BUF 16
int32_t cli_bcapi_read_number(struct cli_bc_ctx *ctx, uint32_t radix)
{
unsigned char number[16];
unsigned i;
unsigned char *p;
int32_t result;
if (radix != 10 && radix != 16 || !ctx->fmap)
return -1;
while ((p = fmap_need_off_once(ctx->fmap, ctx->off, BUF))) {
for (i=0;i<BUF;i++) {
if (p[i] >= '0' && p[i] <= '9') {
unsigned char *endptr;
p = fmap_need_ptr_once(ctx->fmap, p+i, 16);
if (!p)
return -1;
result = strtoul(p, &endptr, radix);
ctx->off += i + (endptr - p);
return result;
}
}
ctx->off += BUF;
}
return -1;
}

@ -216,5 +216,13 @@ int32_t fill_buffer(uint8_t* buffer, uint32_t len, uint32_t filled, uint32_t cur
*/
int32_t extract_new(int32_t id);
/**
* Reads a number in the specified radix starting from the current position.
* Non-numeric characters are ignored.
* @param[in] radix 10 or 16
* @return the number read
*/
int32_t read_number(uint32_t radix);
#endif
#endif

@ -55,6 +55,7 @@ uint32_t cli_bcapi_test2(struct cli_bc_ctx *ctx, uint32_t);
int32_t cli_bcapi_get_pe_section(struct cli_bc_ctx *ctx, struct cli_exe_section*, uint32_t);
int32_t cli_bcapi_fill_buffer(struct cli_bc_ctx *ctx, uint8_t*, uint32_t, uint32_t, uint32_t, uint32_t);
int32_t cli_bcapi_extract_new(struct cli_bc_ctx *ctx, int32_t);
int32_t cli_bcapi_read_number(struct cli_bc_ctx *ctx, uint32_t);
const struct cli_apiglobal cli_globals[] = {
/* Bytecode globals BEGIN */
@ -141,7 +142,8 @@ const struct cli_apicall cli_apicalls[]={
{"test2", 8, 3, 2},
{"get_pe_section", 10, 12, 1},
{"fill_buffer", 9, 0, 4},
{"extract_new", 8, 4, 2}
{"extract_new", 8, 4, 2},
{"read_number", 8, 5, 2}
/* Bytecode APIcalls END */
};
const cli_apicall_int2 cli_apicalls0[] = {
@ -168,7 +170,8 @@ const cli_apicall_int1 cli_apicalls2[] = {
(cli_apicall_int1)cli_bcapi_pe_rawaddr,
(cli_apicall_int1)cli_bcapi_file_byteat,
(cli_apicall_int1)cli_bcapi_test2,
(cli_apicall_int1)cli_bcapi_extract_new
(cli_apicall_int1)cli_bcapi_extract_new,
(cli_apicall_int1)cli_bcapi_read_number
};
const cli_apicall_malloclike cli_apicalls3[] = {
(cli_apicall_malloclike)cli_bcapi_malloc

@ -52,5 +52,6 @@ uint32_t cli_bcapi_test2(struct cli_bc_ctx *ctx, uint32_t);
int32_t cli_bcapi_get_pe_section(struct cli_bc_ctx *ctx, struct cli_exe_section*, uint32_t);
int32_t cli_bcapi_fill_buffer(struct cli_bc_ctx *ctx, uint8_t*, uint32_t, uint32_t, uint32_t, uint32_t);
int32_t cli_bcapi_extract_new(struct cli_bc_ctx *ctx, int32_t);
int32_t cli_bcapi_read_number(struct cli_bc_ctx *ctx, uint32_t);
#endif

@ -2258,7 +2258,7 @@ int cli_scanpe(cli_ctx *ctx, icon_groupset *iconset)
case CL_SUCCESS:
ndesc = cli_bytecode_context_getresult_file(bc_ctx, &tempfile);
cli_bytecode_context_destroy(bc_ctx);
if (ndesc != -1) {
if (ndesc != -1 && tempfile) {
CLI_UNPRESULTS("bytecode PE hook", 1, 1, (0));
}
break;

Loading…
Cancel
Save