997a1efe |
/*
* Load, verify and execute ClamAV bytecode.
*
* Copyright (C) 2009 Sourcefire, Inc.
*
* Authors: Török Edvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef BYTECODE_H
#define BYTECODE_H |
250d92c5 |
#include <stdint.h> |
997a1efe |
#include "clambc.h" |
250d92c5 |
#include <stdio.h> |
cf0cd429 |
|
997a1efe |
struct cli_dbio;
struct cli_bc_ctx;
struct cli_bc_func; |
3555ee75 |
struct cli_bc_value; |
7a9022c9 |
struct cli_bc_inst; |
8cc286f5 |
struct cli_bc_type; |
d1487222 |
struct cli_bc_engine;
struct bitset_tag; |
ab636570 |
struct cl_engine; |
997a1efe |
|
6922903a |
enum bc_state { |
4789b8a5 |
bc_skip, |
6922903a |
bc_loaded,
bc_jit,
bc_interp
};
|
997a1efe |
struct cli_bc {
unsigned verifier;
char *sigmaker;
unsigned id; |
9fac78c7 |
unsigned kind; |
997a1efe |
struct bytecode_metadata metadata; |
8cc286f5 |
unsigned num_types; |
997a1efe |
unsigned num_func;
struct cli_bc_func *funcs; |
8cc286f5 |
struct cli_bc_type *types; |
ec077929 |
uint64_t **globals;
uint16_t *globaltys;
size_t num_globals; |
6922903a |
enum bc_state state; |
8cc286f5 |
uint16_t start_tid; |
d1487222 |
struct bitset_tag *uses_apis; |
dcee45cc |
char *lsig; |
ec41017b |
char *vnameprefix;
char **vnames;
unsigned vnames_cnt; |
d1487222 |
};
struct cli_all_bc {
struct cli_bc *all_bcs;
unsigned count;
struct cli_bcengine *engine; |
997a1efe |
};
|
ab636570 |
struct cli_pe_hook_data; |
7a9022c9 |
struct cli_bc_ctx *cli_bytecode_context_alloc(void); |
30188fcc |
int cli_bytecode_context_setfuncid(struct cli_bc_ctx *ctx, const struct cli_bc *bc, unsigned funcid); |
7a9022c9 |
int cli_bytecode_context_setparam_int(struct cli_bc_ctx *ctx, unsigned i, uint64_t c);
int cli_bytecode_context_setparam_ptr(struct cli_bc_ctx *ctx, unsigned i, void *data, unsigned datalen); |
a1781898 |
int cli_bytecode_context_setfile(struct cli_bc_ctx *ctx, int fd); |
ab636570 |
int cli_bytecode_context_setpe(struct cli_bc_ctx *ctx, const struct cli_pe_hook_data *data); |
7a9022c9 |
int cli_bytecode_context_clear(struct cli_bc_ctx *ctx); |
f3b2dc9e |
uint64_t cli_bytecode_context_getresult_int(struct cli_bc_ctx *ctx); |
7a9022c9 |
void cli_bytecode_context_destroy(struct cli_bc_ctx *ctx); |
997a1efe |
|
2487a4a3 |
extern int have_clamjit; |
d1487222 |
int cli_bytecode_init(struct cli_all_bc *allbc); |
997a1efe |
int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio); |
d1487222 |
int cli_bytecode_prepare(struct cli_all_bc *allbc); |
85a25497 |
int cli_bytecode_run(const struct cli_all_bc *bcs, const struct cli_bc *bc, struct cli_bc_ctx *ctx); |
997a1efe |
void cli_bytecode_destroy(struct cli_bc *bc); |
d1487222 |
int cli_bytecode_done(struct cli_all_bc *allbc); |
997a1efe |
|
d38d6dad |
/* Hooks */ |
ab636570 |
struct cli_exe_info; |
d38d6dad |
int cli_bytecode_runlsig(const struct cli_all_bc *bcs, const struct cli_bc* bc, const char **virname, const uint32_t* lsigcnt, int fd); |
ab636570 |
int cli_bytecode_runhook(const struct cl_engine *engine, struct cli_bc_ctx *ctx, unsigned id, int fd, const char **virname); |
d38d6dad |
|
29227461 |
#ifdef __cplusplus
extern "C" {
#endif
void cli_bytecode_debug(int argc, char **argv);
int bytecode_init(void);
#ifdef __cplusplus
}
#endif |
1a486dca |
|
997a1efe |
#endif |