@@ -18,6 +18,7 @@ using namespace paramkit;
18
18
#define PARAM_DATA " data"
19
19
#define PARAM_MINDUMP " minidmp"
20
20
#define PARAM_SHELLCODE " shellc"
21
+ #define PARAM_PATTERN " pattern"
21
22
#define PARAM_HOOKS " hooks"
22
23
#define PARAM_CACHE " cache"
23
24
#define PARAM_IMP " imp"
@@ -165,6 +166,9 @@ class UnpackParams : public Params
165
166
shellcParam->addEnumValue (pesieve::t_shellc_mode::SHELLC_PATTERNS_AND_STATS, " B" , " detect shellcodes by patterns and stats (both match)" );
166
167
}
167
168
169
+ this ->addParam (new StringParam (PARAM_PATTERN, false ));
170
+ this ->setInfo (PARAM_PATTERN, " Set additional shellcode patterns (file in the SIG format)." );
171
+
168
172
this ->addParam (new BoolParam (PARAM_HOOKS, false ));
169
173
this ->setInfo (PARAM_HOOKS, " Detect hooks and patches" );
170
174
@@ -217,6 +221,7 @@ class UnpackParams : public Params
217
221
this ->addParamToGroup (PARAM_DATA, str_group);
218
222
this ->addParamToGroup (PARAM_SHELLCODE, str_group);
219
223
this ->addParamToGroup (PARAM_HOOKS, str_group);
224
+ this ->addParamToGroup (PARAM_PATTERN, str_group);
220
225
221
226
str_group = " 3. dump options" ;
222
227
this ->addGroup (new ParamGroup (str_group));
@@ -262,6 +267,11 @@ class UnpackParams : public Params
262
267
fillPEsieveStruct (ps.hh_args .pesieve_args );
263
268
}
264
269
270
+ void freeStruct (t_params_struct& ps)
271
+ {
272
+ free_strparam (ps.hh_args .pesieve_args .pattern_file );
273
+ }
274
+
265
275
virtual void printVersionInfo ()
266
276
{
267
277
if (versionStr.length ()) {
@@ -300,6 +310,49 @@ class UnpackParams : public Params
300
310
return " could not fetch the version" ;
301
311
}
302
312
}
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
+ }
303
356
304
357
void fillPEsieveStruct (pesieve::t_params &ps)
305
358
{
@@ -313,6 +366,8 @@ class UnpackParams : public Params
313
366
copyVal<EnumParam>(PARAM_IMP, ps.imprec_mode );
314
367
copyVal<EnumParam>(PARAM_DATA, ps.data );
315
368
copyVal<BoolParam>(PARAM_CACHE, ps.use_cache );
369
+
370
+ fillStringParam (PARAM_PATTERN, ps.pattern_file );
316
371
}
317
372
318
373
};
0 commit comments