Skip to content

Commit a458b40

Browse files
committed
[FEATURE] Support new pe-sieve argument: pattern
1 parent 5f47a0a commit a458b40

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,6 @@ int main(int argc, char* argv[])
258258
}
259259
}
260260
save_remaing_files_report(session_timestamp, params, scanner);
261+
uParams.freeStruct(params);
261262
return ret_code;
262263
}

params.h

+55
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ using namespace paramkit;
1818
#define PARAM_DATA "data"
1919
#define PARAM_MINDUMP "minidmp"
2020
#define PARAM_SHELLCODE "shellc"
21+
#define PARAM_PATTERN "pattern"
2122
#define PARAM_HOOKS "hooks"
2223
#define PARAM_CACHE "cache"
2324
#define PARAM_IMP "imp"
@@ -165,6 +166,9 @@ class UnpackParams : public Params
165166
shellcParam->addEnumValue(pesieve::t_shellc_mode::SHELLC_PATTERNS_AND_STATS, "B", "detect shellcodes by patterns and stats (both match)");
166167
}
167168

169+
this->addParam(new StringParam(PARAM_PATTERN, false));
170+
this->setInfo(PARAM_PATTERN, "Set additional shellcode patterns (file in the SIG format).");
171+
168172
this->addParam(new BoolParam(PARAM_HOOKS, false));
169173
this->setInfo(PARAM_HOOKS, "Detect hooks and patches");
170174

@@ -217,6 +221,7 @@ class UnpackParams : public Params
217221
this->addParamToGroup(PARAM_DATA, str_group);
218222
this->addParamToGroup(PARAM_SHELLCODE, str_group);
219223
this->addParamToGroup(PARAM_HOOKS, str_group);
224+
this->addParamToGroup(PARAM_PATTERN, str_group);
220225

221226
str_group = "3. dump options";
222227
this->addGroup(new ParamGroup(str_group));
@@ -262,6 +267,11 @@ class UnpackParams : public Params
262267
fillPEsieveStruct(ps.hh_args.pesieve_args);
263268
}
264269

270+
void freeStruct(t_params_struct& ps)
271+
{
272+
free_strparam(ps.hh_args.pesieve_args.pattern_file);
273+
}
274+
265275
virtual void printVersionInfo()
266276
{
267277
if (versionStr.length()) {
@@ -300,6 +310,49 @@ class UnpackParams : public Params
300310
return "could not fetch the version";
301311
}
302312
}
313+
314+
// Fill PE-sieve params
315+
316+
bool alloc_strparam(pesieve::PARAM_STRING& strparam, size_t len)
317+
{
318+
if (strparam.buffer != nullptr) { // already allocated
319+
return false;
320+
}
321+
strparam.buffer = (char*)calloc(len + 1, sizeof(char));
322+
if (strparam.buffer) {
323+
strparam.length = len;
324+
return true;
325+
}
326+
return false;
327+
}
328+
329+
void free_strparam(pesieve::PARAM_STRING& strparam)
330+
{
331+
if (strparam.buffer) {
332+
free(strparam.buffer);
333+
}
334+
strparam.buffer = nullptr;
335+
strparam.length = 0;
336+
}
337+
338+
bool fillStringParam(const std::string& paramId, pesieve::PARAM_STRING& strparam)
339+
{
340+
StringParam* myStr = dynamic_cast<StringParam*>(this->getParam(paramId));
341+
if (!myStr || !myStr->isSet()) {
342+
return false;
343+
}
344+
std::string val = myStr->valToString();
345+
const size_t len = val.length();
346+
if (!len) {
347+
return false;
348+
}
349+
alloc_strparam(strparam, len);
350+
bool is_copied = false;
351+
if (strparam.buffer) {
352+
is_copied = copyCStr<StringParam>(paramId, strparam.buffer, strparam.length);
353+
}
354+
return is_copied;
355+
}
303356

304357
void fillPEsieveStruct(pesieve::t_params &ps)
305358
{
@@ -313,6 +366,8 @@ class UnpackParams : public Params
313366
copyVal<EnumParam>(PARAM_IMP, ps.imprec_mode);
314367
copyVal<EnumParam>(PARAM_DATA, ps.data);
315368
copyVal<BoolParam>(PARAM_CACHE, ps.use_cache);
369+
370+
fillStringParam(PARAM_PATTERN, ps.pattern_file);
316371
}
317372

318373
};

0 commit comments

Comments
 (0)