Go to the documentation of this file.
66 SCLogError(
"no libmagic support built in, needed for filemagic keyword");
84 typedef struct DetectFilemagicThreadData {
86 } DetectFilemagicThreadData;
89 static int g_file_match_list_id = 0;
92 static int g_file_magic_buffer_id = 0;
98 void *alstate,
void *txv, uint64_t tx_id);
129 SCLogDebug(
"registering filemagic rule option");
132 #define FILEMAGIC_MIN_SIZE 512
142 int FilemagicThreadLookup(magic_t *
ctx,
File *file)
148 const uint8_t *data = NULL;
149 uint32_t data_len = 0;
153 &data, &data_len, &
offset);
156 file->magic = MagicThreadLookup(
ctx, data, data_len);
158 file->magic = MagicThreadLookup(
ctx, data, data_len);
164 static void *DetectFilemagicThreadInit(
void *data )
166 DetectFilemagicThreadData *t =
SCCalloc(1,
sizeof(DetectFilemagicThreadData));
172 t->ctx = MagicInitContext();
185 static void DetectFilemagicThreadFree(
void *
ctx)
188 DetectFilemagicThreadData *t = (DetectFilemagicThreadData *)
ctx;
209 SCLogError(
"previous transforms not consumed before 'filemagic'");
232 de_ctx,
"filemagic", DetectFilemagicThreadInit, NULL, DetectFilemagicThreadFree, 1);
257 de_ctx,
"filemagic", DetectFilemagicThreadInit, NULL, DetectFilemagicThreadFree, 1);
266 int list_id,
int local_file_id)
276 if (cur_file->magic == NULL) {
277 DetectFilemagicThreadData *tfilemagic =
280 if (tfilemagic == NULL) {
285 FilemagicThreadLookup(&tfilemagic->ctx, cur_file);
287 if (cur_file->magic == NULL) {
291 const uint8_t *data = (
const uint8_t *)cur_file->magic;
292 uint32_t data_len = (uint32_t)strlen(cur_file->magic);
301 void *alstate,
void *txv, uint64_t tx_id)
315 int local_file_id = 0;
316 for (
File *file = ffc->
head; file != NULL; file = file->
next) {
318 det_ctx, transforms, f,
flags, file, engine->
sm_list, local_file_id);
335 typedef struct PrefilterMpmFilemagic {
339 } PrefilterMpmFilemagic;
354 if (!AppLayerParserHasFilesInDir(txd,
flags))
357 const PrefilterMpmFilemagic *
ctx = (
const PrefilterMpmFilemagic *)pectx;
359 const int list_id =
ctx->list_id;
364 int local_file_id = 0;
365 for (
File *file = ffc->
head; file != NULL; file = file->
next) {
367 det_ctx,
ctx->transforms, f,
flags, file, list_id, local_file_id);
381 static void PrefilterMpmFilemagicFree(
void *ptr)
389 PrefilterMpmFilemagic *pectx =
SCCalloc(1,
sizeof(*pectx));
392 pectx->list_id = list_id;
393 pectx->mpm_ctx = mpm_ctx;
397 mpm_reg->
app_v2.alproto, mpm_reg->
app_v2.tx_min_progress,
398 pectx, PrefilterMpmFilemagicFree, mpm_reg->
pname);
#define SIGMATCH_INFO_STICKY_BUFFER
SigTableElmt * sigmatch_table
Container for matching data for a signature group.
void * DetectThreadCtxGetKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
int DetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
struct DetectBufferMpmRegistry_::@84::@86 app_v2
main detection engine ctx
void DetectBufferTypeSupportsMultiInstance(const char *name)
struct DetectEngineAppInspectionEngine_::@79 v2
int DetectContentConvertToNocase(DetectEngineCtx *de_ctx, DetectContentData *cd)
int StreamingBufferGetData(const StreamingBuffer *sb, const uint8_t **data, uint32_t *data_len, uint64_t *stream_offset)
one time registration of keywords at start up
DetectFileHandlerTableElmt filehandler_table[DETECT_TBLSIZE_STATIC]
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
DetectEngineTransforms transforms
void DetectFilemagicRegister(void)
Registration function for keyword: filemagic.
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
int DetectBufferTypeGetByName(const char *name)
#define SIGMATCH_QUOTES_MANDATORY
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
setup the buffer empty
int DetectContentSetup(DetectEngineCtx *de_ctx, Signature *s, const char *contentstr)
Function to setup a content pattern.
#define FILE_SIG_NEED_MAGIC
#define DETECT_ENGINE_INSPECT_SIG_MATCH
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
#define SIGMATCH_HANDLE_NEGATION
SignatureInitData * init_data
#define SCReturnPtr(x, type)
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
uint64_t FileDataSize(const File *file)
get the size of the file data
#define DETECT_SM_LIST_NOTSET
struct AppLayerTxData AppLayerTxData
#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
#define DETECT_CI_FLAGS_SINGLE
int DetectBufferTypeRegister(const char *name)
int DetectRegisterThreadCtxFuncs(DetectEngineCtx *de_ctx, const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *), int mode)
Register Thread keyword context Funcs.
PrefilterRegisterFunc PrefilterFn
void InspectionBufferSetupMulti(InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
int PrefilterAppendTxEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterTxFn PrefilterTxFunc, AppProto alproto, int tx_min_progress, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
int filemagic_thread_ctx_id
#define SCLogError(...)
Macro used to log ERROR messages.
a single match condition for a signature
const DetectEngineTransforms * transforms
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
InspectEngineFuncPtr Callback
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
#define FILE_SIG_NEED_FILE
SigMatch * DetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
DetectEngineTransforms transforms
bool DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const uint8_t *buffer, const uint32_t buffer_len, const uint32_t stream_start_offset, const uint8_t flags, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only