|
| 1 | +diff --git a/clambc/bcrun.c b/clambc/bcrun.c |
| 2 | +index 669df0a93..718fbc31d 100644 |
| 3 | +--- a/clambc/bcrun.c |
| 4 | ++++ b/clambc/bcrun.c |
| 5 | +@@ -402,6 +402,26 @@ int main(int argc, char *argv[]) |
| 6 | + fprintf(stderr, "Out of memory\n"); |
| 7 | + exit(3); |
| 8 | + } |
| 9 | ++ |
| 10 | ++ if ((opt = optget(opts, "input"))->enabled) { |
| 11 | ++ fd = open(opt->strarg, O_RDONLY | O_BINARY); |
| 12 | ++ if (fd == -1) { |
| 13 | ++ fprintf(stderr, "Unable to open input file %s: %s\n", opt->strarg, strerror(errno)); |
| 14 | ++ optfree(opts); |
| 15 | ++ exit(5); |
| 16 | ++ } |
| 17 | ++ map = fmap(fd, 0, 0, opt->strarg); |
| 18 | ++ if (!map) { |
| 19 | ++ fprintf(stderr, "Unable to map input file %s\n", opt->strarg); |
| 20 | ++ exit(5); |
| 21 | ++ } |
| 22 | ++ rc = cli_bytecode_context_setfile(ctx, map); |
| 23 | ++ if (rc != CL_SUCCESS) { |
| 24 | ++ fprintf(stderr, "Unable to set file %s: %s\n", opt->strarg, cl_strerror(rc)); |
| 25 | ++ optfree(opts); |
| 26 | ++ exit(5); |
| 27 | ++ } |
| 28 | ++ } |
| 29 | + |
| 30 | + // ctx was memset, so recursion_level starts at 0. |
| 31 | + cctx.recursion_stack[cctx.recursion_level].fmap = map; |
| 32 | +@@ -416,6 +436,7 @@ int main(int argc, char *argv[]) |
| 33 | + dbg_state.col = 0; |
| 34 | + dbg_state.showline = !optget(opts, "no-trace-showsource")->enabled; |
| 35 | + tracelevel = optget(opts, "trace")->numarg; |
| 36 | ++ printf("tracelevel %d\n", tracelevel); |
| 37 | + cli_bytecode_context_set_trace(ctx, tracelevel, |
| 38 | + tracehook, |
| 39 | + tracehook_op, |
| 40 | +@@ -440,25 +461,6 @@ int main(int argc, char *argv[]) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | +- if ((opt = optget(opts, "input"))->enabled) { |
| 45 | +- fd = open(opt->strarg, O_RDONLY | O_BINARY); |
| 46 | +- if (fd == -1) { |
| 47 | +- fprintf(stderr, "Unable to open input file %s: %s\n", opt->strarg, strerror(errno)); |
| 48 | +- optfree(opts); |
| 49 | +- exit(5); |
| 50 | +- } |
| 51 | +- map = fmap(fd, 0, 0, opt->strarg); |
| 52 | +- if (!map) { |
| 53 | +- fprintf(stderr, "Unable to map input file %s\n", opt->strarg); |
| 54 | +- exit(5); |
| 55 | +- } |
| 56 | +- rc = cli_bytecode_context_setfile(ctx, map); |
| 57 | +- if (rc != CL_SUCCESS) { |
| 58 | +- fprintf(stderr, "Unable to set file %s: %s\n", opt->strarg, cl_strerror(rc)); |
| 59 | +- optfree(opts); |
| 60 | +- exit(5); |
| 61 | +- } |
| 62 | +- } |
| 63 | + /* for testing */ |
| 64 | + ctx->hooks.match_counts = deadbeefcounts; |
| 65 | + ctx->hooks.match_offsets = deadbeefcounts; |
| 66 | +diff --git a/libclamav/bytecode_vm.c b/libclamav/bytecode_vm.c |
| 67 | +index 74953c852..925cf0bb4 100644 |
| 68 | +--- a/libclamav/bytecode_vm.c |
| 69 | ++++ b/libclamav/bytecode_vm.c |
| 70 | +@@ -79,7 +79,7 @@ static inline int bcfail(const char *msg, long a, long b, |
| 71 | + #define CHECK_EQ(a, b) |
| 72 | + #define CHECK_GT(a, b) |
| 73 | + #endif |
| 74 | +-#if 0 /* too verbose, use #ifdef CL_DEBUG if needed */ |
| 75 | ++#if 1 /* too verbose, use #ifdef CL_DEBUG if needed */ |
| 76 | + #define CHECK_UNREACHABLE \ |
| 77 | + do { \ |
| 78 | + cli_dbgmsg("bytecode: unreachable executed!\n"); \ |
| 79 | +@@ -737,29 +737,29 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
| 80 | + TRACE_INST(inst); |
| 81 | + |
| 82 | + switch (inst->interp_op) { |
| 83 | +- DEFINE_BINOP(OP_BC_ADD, res = op0 + op1); |
| 84 | +- DEFINE_BINOP(OP_BC_SUB, res = op0 - op1); |
| 85 | +- DEFINE_BINOP(OP_BC_MUL, res = op0 * op1); |
| 86 | ++ DEFINE_BINOP(OP_BC_ADD, printf("%d + %d\n", op0, op1); res = op0 + op1); |
| 87 | ++ DEFINE_BINOP(OP_BC_SUB, printf("%d - %d\n", op0, op1); res = op0 - op1); |
| 88 | ++ DEFINE_BINOP(OP_BC_MUL, printf("%d * %d\n", op0, op1); res = op0 * op1); |
| 89 | + |
| 90 | + DEFINE_BINOP(OP_BC_UDIV, CHECK_OP(op1 == 0, "bytecode attempted to execute udiv#0\n"); |
| 91 | +- res = op0 / op1); |
| 92 | ++ printf("%d / %d\n", op0, op1); res = op0 / op1); |
| 93 | + DEFINE_BINOP(OP_BC_SDIV, CHECK_OP(check_sdivops(sop0, sop1), "bytecode attempted to execute sdiv#0\n"); |
| 94 | +- res = sop0 / sop1); |
| 95 | ++ printf("%d /s %d\n", op0, op1); res = sop0 / sop1); |
| 96 | + DEFINE_BINOP(OP_BC_UREM, CHECK_OP(op1 == 0, "bytecode attempted to execute urem#0\n"); |
| 97 | +- res = op0 % op1); |
| 98 | ++ printf("%d %% %d\n", op0, op1); res = op0 % op1); |
| 99 | + DEFINE_BINOP(OP_BC_SREM, CHECK_OP(check_sdivops(sop0, sop1), "bytecode attempted to execute urem#0\n"); |
| 100 | +- res = sop0 % sop1); |
| 101 | ++ printf("%d %%s %d\n", op0, op1); res = sop0 % sop1); |
| 102 | + |
| 103 | + DEFINE_BINOP(OP_BC_SHL, CHECK_OP(op1 > inst->type, "bytecode attempted to execute shl greater than bitwidth\n"); |
| 104 | +- res = op0 << op1); |
| 105 | ++ printf("%d << %d\n", op0, op1); res = op0 << op1); |
| 106 | + DEFINE_BINOP(OP_BC_LSHR, CHECK_OP(op1 > inst->type, "bytecode attempted to execute lshr greater than bitwidth\n"); |
| 107 | +- res = op0 >> op1); |
| 108 | ++ printf("%d >> %d\n", op0, op1); res = op0 >> op1); |
| 109 | + DEFINE_BINOP(OP_BC_ASHR, CHECK_OP(op1 > inst->type, "bytecode attempted to execute ashr greater than bitwidth\n"); |
| 110 | +- res = CLI_SRS(sop0, op1)); |
| 111 | ++ printf("%d >>a %d\n", op0, op1); res = CLI_SRS(sop0, op1)); |
| 112 | + |
| 113 | +- DEFINE_BINOP(OP_BC_AND, res = op0 & op1); |
| 114 | +- DEFINE_BINOP(OP_BC_OR, res = op0 | op1); |
| 115 | +- DEFINE_BINOP(OP_BC_XOR, res = op0 ^ op1); |
| 116 | ++ DEFINE_BINOP(OP_BC_AND, printf("%d & %d\n", op0, op1); res = op0 & op1); |
| 117 | ++ DEFINE_BINOP(OP_BC_OR, printf("%d | %d\n", op0, op1); res = op0 | op1); |
| 118 | ++ DEFINE_BINOP(OP_BC_XOR, printf("%d ^ %d\n", op0, op1); res = op0 ^ op1); |
| 119 | + |
| 120 | + // clang-format off |
| 121 | + DEFINE_SCASTOP(OP_BC_SEXT, |
| 122 | +@@ -803,16 +803,16 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
| 123 | + DEFINE_OP_BC_RET_N(OP_BC_RET_VOID * 5 + 3, uint8_t, (void), (void)); |
| 124 | + DEFINE_OP_BC_RET_N(OP_BC_RET_VOID * 5 + 4, uint8_t, (void), (void)); |
| 125 | + |
| 126 | +- DEFINE_ICMPOP(OP_BC_ICMP_EQ, res = (op0 == op1)); |
| 127 | +- DEFINE_ICMPOP(OP_BC_ICMP_NE, res = (op0 != op1)); |
| 128 | +- DEFINE_ICMPOP(OP_BC_ICMP_UGT, res = (op0 > op1)); |
| 129 | +- DEFINE_ICMPOP(OP_BC_ICMP_UGE, res = (op0 >= op1)); |
| 130 | +- DEFINE_ICMPOP(OP_BC_ICMP_ULT, res = (op0 < op1)); |
| 131 | +- DEFINE_ICMPOP(OP_BC_ICMP_ULE, res = (op0 <= op1)); |
| 132 | +- DEFINE_ICMPOP(OP_BC_ICMP_SGT, res = (sop0 > sop1)); |
| 133 | +- DEFINE_ICMPOP(OP_BC_ICMP_SGE, res = (sop0 >= sop1)); |
| 134 | +- DEFINE_ICMPOP(OP_BC_ICMP_SLE, res = (sop0 <= sop1)); |
| 135 | +- DEFINE_ICMPOP(OP_BC_ICMP_SLT, res = (sop0 < sop1)); |
| 136 | ++ DEFINE_ICMPOP(OP_BC_ICMP_EQ, printf("%d == %d (%08x == %08x)\n", op0, op1, op0, op1); res = (op0 == op1)); |
| 137 | ++ DEFINE_ICMPOP(OP_BC_ICMP_NE, printf("%d != %d\n", op0, op1); res = (op0 != op1)); |
| 138 | ++ DEFINE_ICMPOP(OP_BC_ICMP_UGT, printf("%d > %d\n", op0, op1); res = (op0 > op1)); |
| 139 | ++ DEFINE_ICMPOP(OP_BC_ICMP_UGE, printf("%d >= %d\n", op0, op1); res = (op0 >= op1)); |
| 140 | ++ DEFINE_ICMPOP(OP_BC_ICMP_ULT, printf("%d < %d\n", op0, op1); res = (op0 < op1)); |
| 141 | ++ DEFINE_ICMPOP(OP_BC_ICMP_ULE, printf("%d <= %d\n", op0, op1); res = (op0 <= op1)); |
| 142 | ++ DEFINE_ICMPOP(OP_BC_ICMP_SGT, printf("%d >s %d\n", op0, op1); res = (sop0 > sop1)); |
| 143 | ++ DEFINE_ICMPOP(OP_BC_ICMP_SGE, printf("%d >=s %d\n", op0, op1); res = (sop0 >= sop1)); |
| 144 | ++ DEFINE_ICMPOP(OP_BC_ICMP_SLE, printf("%d <=s %d\n", op0, op1); res = (sop0 <= sop1)); |
| 145 | ++ DEFINE_ICMPOP(OP_BC_ICMP_SLT, printf("%d <s %d\n", op0, op1); res = (sop0 < sop1)); |
| 146 | + |
| 147 | + case OP_BC_SELECT * 5: { |
| 148 | + uint8_t t0, t1, t2; |
0 commit comments