Browse code

cw4: track number of loaded sigs, provide retieval api

aCaB authored on 2011/06/29 23:39:56
Showing 2 changed files
... ...
@@ -261,10 +261,20 @@ int CLAMAPI Scan_ScanObjectByHandle(CClamAVScanner *pScanner, HANDLE object, int
261 261
 /*
262 262
  * Returns the outer file type as an _int64[2] for the give HANDLE
263 263
  * Scan is not performed and no callback is invoked
264
+ * INPUT @param hFile : file handle whose type is to be determined
265
+ * OUTPUT @param filetype : result array (_int64[2])
264 266
  */
265 267
  int CLAMAPI Scan_GetFileType(HANDLE hFile, _int64 *filetype);
266 268
 
267 269
 /*
270
+ * Checks if any meaningful signature is loaded
271
+ * Returns 0 (false), 1 (true) or -1 (error)
272
+ * OUTPUT @param official : set to the number of official signatures loaded, unless NULL
273
+ * OUTPUT @param custom : set to the number of custom signatures loaded, unless NULL
274
+ */
275
+ int CLAMAPI Scan_HaveSigs(unsigned int *official, unsigned int *custom);
276
+
277
+/*
268 278
  * MANDATORY SUPPORT
269 279
  * Destroy memory allocated when malicious objects are found during scan
270 280
  * INPUT @param pScanner : opaque object
... ...
@@ -115,6 +115,7 @@ struct {
115 115
 } *instances = NULL;
116 116
 unsigned int ninsts_total = 0;
117 117
 unsigned int ninsts_avail = 0;
118
+unsigned int official_sigs, custom_sigs;
118 119
 HANDLE instance_mutex;
119 120
 
120 121
 BOOL minimal_definitions = FALSE;
... ...
@@ -306,6 +307,10 @@ BOOL interface_setup(void) {
306 306
 static int sigload_callback(const char *type, const char *name, unsigned int custom, void *context) {
307 307
     if(minimal_definitions && (custom || strcmp(type, "fp")))
308 308
 	return 1;
309
+    if(custom)
310
+	custom_sigs++;
311
+    else if(strcmp(type, "fp"))
312
+	official_sigs++;
309 313
     return 0;
310 314
 }
311 315
 
... ...
@@ -361,6 +366,7 @@ static int load_db(void) {
361 361
     INFN();
362 362
 
363 363
     cl_engine_set_clcb_sigload(engine, sigload_callback, NULL);
364
+    official_sigs = custom_sigs = 0;
364 365
     if((ret = cl_load(dbdir, engine, &signo, CL_DB_STDOPT & ~CL_DB_PHISHING & ~CL_DB_PHISHING_URLS)) != CL_SUCCESS) {
365 366
 	cl_engine_free(engine);
366 367
 	engine = NULL;
... ...
@@ -382,6 +388,21 @@ static int load_db(void) {
382 382
     WIN();
383 383
 }
384 384
 
385
+int CLAMAPI Scan_HaveSigs(unsigned int *official, unsigned int *custom) {
386
+    int ret;
387
+    if(lock_engine())
388
+	FAIL(-1, "failed to lock engine");
389
+    if(!engine) {
390
+	unlock_engine();
391
+	FAIL(-1, "No engine available");
392
+    }
393
+    ret = ((official_sigs + custom_sigs) > 0);
394
+    if(official) *official = official_sigs;
395
+    if(custom) *custom = custom_sigs;
396
+    unlock_engine();
397
+    return ret;
398
+}
399
+
385 400
 static void free_engine_and_unlock(void) {
386 401
     cl_engine_free(engine);
387 402
     engine = NULL;