2
* Load, verify and execute ClamAV bytecode.
4
* Copyright (C) 2009-2010 Sourcefire, Inc.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 2 as
10
* published by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
#ifndef BYTECODE_PRIV_H
24
#define BYTECODE_PRIV_H
28
#include "type_desc.h"
30
#include "bytecode_hooks.h"
36
typedef uint32_t operand_t;
37
typedef uint16_t bbid_t;
38
typedef uint16_t funcid_t;
40
struct cli_bc_callop {
56
uint8_t size;/* 0: 1-bit, 1: 8b, 2: 16b, 3: 32b, 4: 64b */
59
typedef uint8_t interp_op_t;
61
enum bc_opcode opcode;
64
interp_op_t interp_op;/* opcode for interpreter */
67
struct cli_bc_cast cast;
70
struct cli_bc_callop ops;
78
struct cli_bc_inst *insts;
85
uint32_t numValues;/* without constants */
86
uint32_t numConstants;
87
uint32_t numBytes;/* stack size */
93
struct cli_bc_inst *allinsts;
98
struct cli_bc_dbgnode_element {
105
struct cli_bc_dbgnode {
106
unsigned numelements;
107
struct cli_bc_dbgnode_element* elements;
125
unsigned write_cursor;
126
unsigned read_cursor;
137
struct parser_state *state;
143
BCEV_EXEC_RETURNVALUE,
154
/* API failures (that are not serious), count must be 0 for testmode */
159
/* real errors (write failure) are reported via cli_event_error_str */
164
uint8_t timeout;/* must be first byte in struct! */
167
/* id and params of toplevel function called */
168
const struct cli_bc *bc;
169
const struct cli_bc_func *func;
170
uint32_t bytecode_timeout;
181
struct cli_bc_hooks hooks;
182
struct cli_exe_info exeinfo;
183
uint32_t lsigcnt[64];
184
uint32_t lsigoff[64];
186
struct pdf_obj *pdf_objs;
189
uint32_t pdf_startoff;
191
int32_t pdf_dumpedid;
192
const struct cli_exe_section *sections;
197
unsigned filewritten;
200
bc_dbg_callback_trace trace;
201
bc_dbg_callback_trace_op trace_op;
202
bc_dbg_callback_trace_val trace_val;
203
bc_dbg_callback_trace_ptr trace_ptr;
204
const char *directory;
207
unsigned trace_level;
212
struct bc_inflate* inflates;
213
struct bc_buffer *buffers;
217
unsigned jsnormwritten;
218
struct cli_hashset *hashsets;
219
struct bc_jsnorm* jsnorms;
221
struct cli_map *maps;
223
unsigned containertype;
224
unsigned extracted_file_input;
225
const struct cli_environment *env;
226
unsigned bytecode_disable_status;
227
cli_events_t *bc_events;
232
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);
238
int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx, const struct cli_bc_func *func);
239
int cli_bytecode_prepare_jit(struct cli_all_bc *bc);
240
int cli_bytecode_init_jit(struct cli_all_bc *bc, unsigned dconfmask);
241
int cli_bytecode_done_jit(struct cli_all_bc *bc, int partial);