... | ... |
@@ -33,6 +33,7 @@ |
33 | 33 |
#include "shared/optparser.h" |
34 | 34 |
#include "shared/misc.h" |
35 | 35 |
#include "libclamav/dconf.h" |
36 |
+#include "libclamav/others.h" |
|
36 | 37 |
|
37 | 38 |
#include <fcntl.h> |
38 | 39 |
#include <stdlib.h> |
... | ... |
@@ -123,7 +124,6 @@ static void tracehook_ptr(struct cli_bc_ctx *ctx, const void *ptr) |
123 | 123 |
fprintf(stderr, "[trace] %p\n", ptr); |
124 | 124 |
} |
125 | 125 |
|
126 |
-static uint8_t cli_debug_flag=0; |
|
127 | 126 |
static void print_src(const char *file) |
128 | 127 |
{ |
129 | 128 |
char buf[4096]; |
... | ... |
@@ -323,7 +323,11 @@ int main(int argc, char *argv[]) |
323 | 323 |
} else if (optget(opts, "printsrc")->enabled) { |
324 | 324 |
print_src(opts->filename[0]); |
325 | 325 |
} else { |
326 |
+ cli_ctx cctx; |
|
327 |
+ struct cl_engine engine; |
|
326 | 328 |
fmap_t *map = NULL; |
329 |
+ memset(&cctx, 0, sizeof(cctx)); |
|
330 |
+ memset(&engine, 0, sizeof(engine)); |
|
327 | 331 |
rc = cli_bytecode_prepare(&bcs, BYTECODE_ENGINE_MASK); |
328 | 332 |
if (rc != CL_SUCCESS) { |
329 | 333 |
fprintf(stderr,"Unable to prepare bytecode: %s\n", cl_strerror(rc)); |
... | ... |
@@ -338,6 +342,8 @@ int main(int argc, char *argv[]) |
338 | 338 |
fprintf(stderr,"Out of memory\n"); |
339 | 339 |
exit(3); |
340 | 340 |
} |
341 |
+ ctx->ctx = &cctx; |
|
342 |
+ cctx.engine = &engine; |
|
341 | 343 |
memset(&dbg_state, 0, sizeof(dbg_state)); |
342 | 344 |
dbg_state.file = "<libclamav>"; |
343 | 345 |
dbg_state.line = 0; |
... | ... |
@@ -116,8 +116,9 @@ uint32_t cli_bcapi_debug_print_str(struct cli_bc_ctx *ctx, const uint8_t *str, u |
116 | 116 |
|
117 | 117 |
uint32_t cli_bcapi_debug_print_uint(struct cli_bc_ctx *ctx, uint32_t a) |
118 | 118 |
{ |
119 |
- cli_dbgmsg("bytecode debug: %u\n", a); |
|
120 |
- return 0; |
|
119 |
+ if (!cli_debug_flag) |
|
120 |
+ return 0; |
|
121 |
+ return fprintf(stderr, "%d", a); |
|
121 | 122 |
} |
122 | 123 |
|
123 | 124 |
/*TODO: compiler should make sure that only constants are passed here, and not |
... | ... |
@@ -1026,6 +1027,8 @@ uint32_t cli_bcapi_debug_print_str_nonl(struct cli_bc_ctx *ctx , const uint8_t* |
1026 | 1026 |
{ |
1027 | 1027 |
if (!s || len <= 0) |
1028 | 1028 |
return -1; |
1029 |
+ if (!cli_debug_flag) |
|
1030 |
+ return 0; |
|
1029 | 1031 |
return fwrite(s, 1, len, stderr); |
1030 | 1032 |
} |
1031 | 1033 |
|