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);
130 SCLogDebug(
"registering filemagic rule option");
133 #define FILEMAGIC_MIN_SIZE 512
143 int FilemagicThreadLookup(magic_t *
ctx,
File *file)
149 const uint8_t *data = NULL;
150 uint32_t data_len = 0;
154 &data, &data_len, &
offset);
157 file->magic = MagicThreadLookup(
ctx, data, data_len);
159 file->magic = MagicThreadLookup(
ctx, data, data_len);
165 static void *DetectFilemagicThreadInit(
void *data )
167 DetectFilemagicThreadData *t =
SCCalloc(1,
sizeof(DetectFilemagicThreadData));
173 t->ctx = MagicInitContext();
186 static void DetectFilemagicThreadFree(
void *
ctx)
189 DetectFilemagicThreadData *t = (DetectFilemagicThreadData *)
ctx;
210 SCLogError(
"previous transforms not consumed before 'filemagic'");
233 de_ctx,
"filemagic", DetectFilemagicThreadInit, NULL, DetectFilemagicThreadFree, 1);
258 de_ctx,
"filemagic", DetectFilemagicThreadInit, NULL, DetectFilemagicThreadFree, 1);
267 int list_id,
int local_file_id)
277 if (cur_file->magic == NULL) {
278 DetectFilemagicThreadData *tfilemagic =
281 if (tfilemagic == NULL) {
286 FilemagicThreadLookup(&tfilemagic->ctx, cur_file);
288 if (cur_file->magic == NULL) {
292 const uint8_t *data = (
const uint8_t *)cur_file->magic;
293 uint32_t data_len = (uint32_t)strlen(cur_file->magic);
302 void *alstate,
void *txv, uint64_t tx_id)
311 if (ffc == NULL || ffc->
head == NULL) {
324 int local_file_id = 0;
325 for (
File *file = ffc->
head; file != NULL; file = file->
next) {
327 det_ctx, transforms,
f,
flags, file, engine->
sm_list, local_file_id);
328 if (buffer == NULL) {
346 typedef struct PrefilterMpmFilemagic {
350 } PrefilterMpmFilemagic;
368 const PrefilterMpmFilemagic *
ctx = (
const PrefilterMpmFilemagic *)pectx;
370 const int list_id =
ctx->list_id;
375 int local_file_id = 0;
376 for (
File *file = ffc->
head; file != NULL; file = file->
next) {
378 det_ctx,
ctx->transforms,
f,
flags, file, list_id, local_file_id);
392 static void PrefilterMpmFilemagicFree(
void *ptr)
400 PrefilterMpmFilemagic *pectx =
SCCalloc(1,
sizeof(*pectx));
403 pectx->list_id = list_id;
404 pectx->mpm_ctx = mpm_ctx;
409 pectx, PrefilterMpmFilemagicFree, mpm_reg->
pname);
#define AppLayerParserHasFilesInDir(txd, direction)
check if tx (possibly) has files in this tx for the direction
int PrefilterAppendTxEngineSubState(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterTxFn PrefilterTxFunc, AppProto alproto, uint8_t sub_state, const int8_t tx_min_progress, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
struct DetectEngineAppInspectionEngine_::@82 v2
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.
struct DetectBufferMpmRegistry_::@90::@92 app_v2
SigMatch * SCDetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
main detection engine ctx
void DetectBufferTypeSupportsMultiInstance(const char *name)
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
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
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 DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
#define SIGMATCH_SUPPORT_DIR
#define SIGMATCH_INFO_MULTI_BUFFER
char pname[DETECT_PROFILE_NAME_LEN]
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
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 uint64_t stream_start_offset, const uint8_t flags, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *tx, uint8_t flags)
get the progress value for a tx/protocol
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
SignatureInitData * init_data
#define SCReturnPtr(x, type)
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
#define SIGMATCH_QUOTES_MANDATORY
uint64_t FileDataSize(const File *file)
get the size of the file data
#define DETECT_SM_LIST_NOTSET
#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.
#define SIGMATCH_OPTIONAL_OPT
PrefilterRegisterFunc PrefilterFn
#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
#define SIGMATCH_INFO_STICKY_BUFFER
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
InspectEngineFuncPtr Callback
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
setup the buffer empty
#define FILE_SIG_NEED_FILE
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
DetectEngineTransforms transforms
AppProto alproto
application level protocol
#define SIGMATCH_HANDLE_NEGATION
DetectFileHandlerTableElmt filehandler_table[DETECT_TBLSIZE_STATIC]
void InspectionBufferSetupMulti(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer