mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Refactor common MIME magic matching code.
Put some methods in file_analysis::Manager that can perform the matching process and return MIME type results. Also helps to centralize the management/re-use of a signature matcher object.
This commit is contained in:
parent
9ac8110416
commit
0865b152bb
5 changed files with 71 additions and 17 deletions
|
@ -280,16 +280,12 @@ bool File::BufferBOF(const u_char* data, uint64 len)
|
|||
|
||||
bool File::DetectMIME(const u_char* data, uint64 len)
|
||||
{
|
||||
static RuleFileMagicState* fms = rule_matcher->InitFileMagic();
|
||||
rule_matcher->ClearFileMagicState(fms);
|
||||
RuleMatcher::MIME_Matches matches;
|
||||
rule_matcher->Match(fms, data, len, &matches);
|
||||
string strongest_match = file_mgr->DetectMIME(data, len);
|
||||
|
||||
if ( matches.empty() )
|
||||
if ( strongest_match.empty() )
|
||||
return false;
|
||||
|
||||
val->Assign(mime_type_idx, new StringVal(*matches.begin()->second.begin()));
|
||||
|
||||
val->Assign(mime_type_idx, new StringVal(strongest_match));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue