b151ef55 |
/* |
eedd6182 |
* Copyright (C) 1999 - 2005 Tomasz Kojm <tkojm@clamav.net> |
b151ef55 |
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 |
30738099 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. |
b151ef55 |
*/
|
f91f55e0 |
#ifndef __OTHERS_H_LC
#define __OTHERS_H_LC |
b151ef55 |
|
183ee7e7 |
#include <stdio.h> |
b151ef55 |
#include <stdlib.h> |
fbbf7cd2 |
#include "cltypes.h" |
b151ef55 |
|
b3e4f4f0 |
#include "clamav.h" |
4a30feab |
#include "dconf.h" |
b3e4f4f0 |
|
57f37aa6 |
/*
* CLI_ISCONTAINED(buf1, size1, buf2, size2) checks if buf2 is contained
* within buf1.
*
* buf1 and buf2 are pointers (or offsets) for the main buffer and the
* sub-buffer respectively, and size1/2 are their sizes
*
* The macro can be used to protect against wraps.
*/ |
67f852f2 |
#define CLI_ISCONTAINED(bb, bb_size, sb, sb_size) \
(bb_size > 0 && sb_size > 0 && sb_size <= bb_size \
&& sb >= bb && sb + sb_size <= bb + bb_size && sb + sb_size > bb)
|
edaad3c9 |
#define CLI_ISCONTAINED2(bb, bb_size, sb, sb_size) \
(bb_size > 0 && sb_size >= 0 && sb_size <= bb_size \ |
966c0551 |
&& sb >= bb && sb + sb_size <= bb + bb_size && sb + sb_size >= bb) |
edaad3c9 |
|
86112c06 |
#define CLI_MAX_ALLOCATION 184549376 |
61ec12c4 |
|
c4428bd1 |
/* Maximum filenames under various systems - njh */
#ifndef NAME_MAX /* e.g. Linux */
# ifdef MAXNAMELEN /* e.g. Solaris */
# define NAME_MAX MAXNAMELEN
# else
# ifdef FILENAME_MAX /* e.g. SCO */
# define NAME_MAX FILENAME_MAX
# endif
# endif
#endif
|
605b8cf0 |
/* internal clamav context */
typedef struct {
const char **virname;
unsigned long int *scanned;
const struct cli_matcher *root;
const struct cl_engine *engine;
const struct cl_limits *limits;
unsigned int options;
unsigned int arec;
unsigned int mrec; |
4a30feab |
struct cli_dconf *dconf; |
605b8cf0 |
} cli_ctx;
#define SCAN_ARCHIVE (ctx->options & CL_SCAN_ARCHIVE)
#define SCAN_MAIL (ctx->options & CL_SCAN_MAIL)
#define SCAN_OLE2 (ctx->options & CL_SCAN_OLE2)
#define SCAN_HTML (ctx->options & CL_SCAN_HTML)
#define SCAN_PE (ctx->options & CL_SCAN_PE) |
600fad76 |
#define SCAN_ELF (ctx->options & CL_SCAN_ELF) |
92f20fef |
#define SCAN_ALGO (ctx->options & CL_SCAN_ALGORITHMIC) |
605b8cf0 |
#define DETECT_ENCRYPTED (ctx->options & CL_SCAN_BLOCKENCRYPTED)
#define BLOCKMAX (ctx->options & CL_SCAN_BLOCKMAX)
#define DETECT_BROKEN (ctx->options & CL_SCAN_BLOCKBROKEN)
|
70ea6092 |
#if WORDS_BIGENDIAN == 0
/* new macros from A. Melnikoff */
#define le16_to_host(v) (v)
#define le32_to_host(v) (v)
#define le64_to_host(v) (v) |
b423f597 |
#define be16_to_host(v) ((v >> 8) | ((v & 0xFF) << 8)) |
70ea6092 |
#define be32_to_host(v) ((v >> 24) | ((v & 0x00FF0000) >> 8) | \
((v & 0x0000FF00) << 8) | (v << 24))
#define be64_to_host(v) ((v >> 56) | ((v & 0x00FF000000000000LL) >> 40) | \
((v & 0x0000FF0000000000LL) >> 24) | \
((v & 0x000000FF00000000LL) >> 8) | \
((v & 0x00000000FF000000LL) << 8) | \
((v & 0x0000000000FF0000LL) << 24) | \
((v & 0x000000000000FF00LL) << 40) | \
(v << 56))
#else |
b423f597 |
#define le16_to_host(v) ((v >> 8) | ((v & 0xFF) << 8)) |
70ea6092 |
#define le32_to_host(v) ((v >> 24) | ((v & 0x00FF0000) >> 8) | \
((v & 0x0000FF00) << 8) | (v << 24))
#define le64_to_host(v) ((v >> 56) | ((v & 0x00FF000000000000LL) >> 40) | \
((v & 0x0000FF0000000000LL) >> 24) | \
((v & 0x000000FF00000000LL) >> 8) | \
((v & 0x00000000FF000000LL) << 8) | \
((v & 0x0000000000FF0000LL) << 24) | \
((v & 0x000000000000FF00LL) << 40) | \
(v << 56))
#define be16_to_host(v) (v)
#define be32_to_host(v) (v)
#define be64_to_host(v) (v)
#endif
/* used by: spin, yc (C) aCaB */
#define ROL(a,b) a = ( a << (b % (sizeof(a)<<3) )) | (a >> ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) )
#define ROR(a,b) a = ( a >> (b % (sizeof(a)<<3) )) | (a << ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) )
|
59afa53d |
#ifndef FALSE |
70ea6092 |
#define FALSE (0) |
59afa53d |
#endif
#ifndef TRUE |
70ea6092 |
#define TRUE (1) |
59afa53d |
#endif |
70ea6092 |
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
|
4f437952 |
typedef struct bitset_tag
{
unsigned char *bitset;
unsigned long length;
} bitset_t;
|
658de21b |
#ifdef __GNUC__
void cli_warnmsg(const char *str, ...) __attribute__((format(printf, 1, 2)));
#else |
b151ef55 |
void cli_warnmsg(const char *str, ...); |
658de21b |
#endif
#ifdef __GNUC__
void cli_errmsg(const char *str, ...) __attribute__((format(printf, 1, 2)));
#else |
b151ef55 |
void cli_errmsg(const char *str, ...); |
658de21b |
#endif
#ifdef __GNUC__
void cli_dbgmsg(const char *str, ...) __attribute__((format(printf, 1, 2)));
#else |
b151ef55 |
void cli_dbgmsg(const char *str, ...); |
658de21b |
#endif
|
b151ef55 |
void *cli_malloc(size_t nmemb);
void *cli_calloc(size_t nmemb, size_t size); |
4cd4319e |
void *cli_realloc(void *ptr, size_t size); |
58b17dee |
char *cli_strdup(const char *s); |
b151ef55 |
int cli_rmdirs(const char *dirname); |
3f66a5af |
unsigned char *cli_md5digest(int desc); |
d2a12ffd |
char *cli_md5stream(FILE *fs, unsigned char *digcpy);
char *cli_md5file(const char *filename); |
66fcd9f8 |
int cli_readn(int fd, void *buff, unsigned int count); |
c3f09884 |
int cli_writen(int fd, const void *buff, unsigned int count); |
fbbf7cd2 |
int32_t cli_readint32(const char *buff); |
b3171bcd |
void cli_writeint32(char *offset, uint32_t value); |
f91f55e0 |
char *cli_gentemp(const char *dir); |
73c21438 |
char *cli_gentempdir(const char *dir);
char *cli_gentempdesc(const char *dir, int *fd);
char *cli_gentempstream(const char *dir, FILE **fs); |
f91f55e0 |
unsigned int cli_rndnum(unsigned int max); |
ed4b4196 |
int cli_filecopy(const char *src, const char *dest); |
b0674c6e |
bitset_t *cli_bitset_init(void); |
4f437952 |
void cli_bitset_free(bitset_t *bs);
int cli_bitset_set(bitset_t *bs, unsigned long bit_offset);
int cli_bitset_test(bitset_t *bs, unsigned long bit_offset); |
b151ef55 |
#endif |