Using partner scan function

Partner scan function allows your solution to scan and disinfect objects handled by monitors.

Partner scan function is supported only on Windows platform. The following monitors are supported: File Monitor, Web Monitor, and Mail Monitor. SDK library must be initialized in KAV_SHT_INPROC mode.

How partner scan function works

Partner scan function works from the callback function, which handles events in KAV SDK. This function is specified at KAV SDK initialization. Partner scan function uses a special event called EVENT_EXTERNAL_SCAN. KAV SDK sends this event when a monitor intercepts an object, and partner application can scan and disinfect the object when handling this event.

Following monitors support the partner scanning function:

KAV SDK uses the cleaning mode of the monitor when working with the partner scan function. For example, KAV SDK deletes objects that cannot be disinfected in KAV_CLEAN_DELETE mode and skips them in KAV_CLEAN_SKIP mode. The cleaning mode can restrict the partner scan fnction; in KAV_DELETE mode, for example, KAV SDK does not allow partner function to disinfect objects.

Note that the partner scan function works only with a matching license key type.

Events generated by file monitors

File monitors generate EVENT_EXTERNAL_SCAN event twice for a mailcious object. This is an intentional behavior caused by KAV SDK architecture.

In the first EVENT_EXTERNAL_SCAN event, pfnOnDetect function always returns SC_R_CANCEL, and object disinfection is not allowed. Partner scan function can handle the object in the second EVENT_EXTERNAL_SCAN event; this event is generated for the same object.

How KAV SDK handles objects depending on partner scan function results

When partner scan function processes an object, it reports the status of the scan and the result of object disinfection to KAV SDK. Depending on this information, KAV SDK performs additional actions on the object.

KAV SDK actions depend on the scan and disinfection status returned by the partner scan function:

Event parameters

Parameters of EVENT_EXTERNAL_SCAN event have data that is required for partner scanning function.

The following information is passed in EVENT_EXTERNAL_SCAN parameters:

Members of KAV_SCAN_OBJECT structure

KAV_SCAN_OBJECT structure holds pointers to functions required for partner scan function, and a member for the status of partner function scan.

Functions that perform actions with the object:

Functions that notify KAV SDK about partner function actions:

Other members:

Enabling the event for partner scan function

By default, monitors don't send the EVENT_EXTERNAL_SCAN event. You need to enable this event when you load a monitor.

To enable the EVENT_EXTERNAL_SCAN event:

The following example demonstrates setting partner function scanning mode for a file monitor. Note the KAV_O_M_EXTERNAL_SCAN flag that is specified.

Example:

KAV_FILE_MONITOR_SETTINGS2 fmset = {0};

fmset.s.enType = FILE_MONITOR;

fmset.s.dwSettingsStructSize = sizeof(KAV_FILE_MONITOR_SETTINGS);

fmset.dwScanningMode = KAV_O_M_EXTERNAL_SCAN | KAV_O_M_PACKED;

fmset.dwCleaningMode = KAV_CLEAN_DELETE;

//...

Casting dwParam1 and dwParam2

A pointer to KAV_SCAN_OBJECT structure is passed in dwParam1 (lower 32 bits) and dwParam2 (higher 32 bits). These parameters are of unsigned long type, and their combined value is a pointer to KAV_SCAN_OBJECT structure.

To get the pointer from dwParam1 and dwParam2, you need to cast these parameters as shown in the following example. Two parameters are cast to KAV_SCAN_CONTEXT type which is defined as a pointer to KAV_SCAN_OBJECT structure in KAV SDK header file.

Example:

KAV_SCAN_CONTEXT context = reinterpret_cast<KAV_SCAN_CONTEXT>(static_cast<unsigned long long>(dwParam1) | (static_cast<unsigned long long>(dwParam2) << 32));

Notifying KAV SDK about the process of scanning or disinfecting

Partner scan function must notify KAV SDK about the process of scanning or disinfecting.

While scanning or disinfecting, continuously call pfnOnProcessing function. This must be done at least 20-100 times per second.

Example:

result = context->pfnOnProcessing(context);

if (SC_R_OK != result)

{

printf("Processing error: 0x%x\n", result);

}

Scanning objects inside the event

When scanning an object inside EVENT_EXTERNAL_SCAN event, you generally do the following actions:

  1. Scan the object using functions passed in KAV_SCAN_OBJECT (pfnRead, and pfnSeek).
  2. Depending on the result of the scan, handle the object accordingly.

The following is an example of reading the object. The current position moves to the beginning of the object, and five bytes are read from that position into the buffer.

Example:

KAV_SC_RESULT result;

unsigned char buff[5];

unsigned long read;

 

result = context->pfnSeek(context, SC_O_BEGIN, 0, NULL);

result = context->pfnRead(context, buff, 5, &read);

Handling unknown objects

If the partner scan function cannot determine if an object is infected or clean:

  1. Set status member of KAV_SCAN_OBJECT structure to SC_S_UNKNOWN.
  2. Return CLBK_OK.
  3. KAV SDK will scan and handle the object.

Note that SC_S_UNKNOWN status is the default value in KAV_SCAN_OBJECT. You can use this to filter the objects even before you scan them. For example, filter by the object name, passed in pObjectName parameter, and return CLBK_OK for all objects that must be handled by KAV SDK.

An example of handling an unknown object:

Example:

context->status = SC_S_UNKNOWN;

return CLBK_OK;

Handling clean objects

If the partner scan function considers an object clean:

  1. Set status member of KAV_SCAN_OBJECT structure to SC_S_CLEAN.
  2. Return CLBK_OK.
  3. KAV SDK will consider the object clean.

An example of handling a clean object:

Example:

context->status = SC_S_CLEAN;

return CLBK_OK;

Handling infected objects without disinfection

If the partner scan function considers the object infected and does not attempt to disinfect it:

  1. Call pfnOnDetect and specify KVC_NON_CURABLE in the curability parameter.
  2. Set status member of KAV_SCAN_OBJECT structure to SC_S_INFECTED.
  3. Return CLBK_OK.
  4. KAV SDK will skip or delete the object, according to the monitor cleaning mode.

An example of handling an infected object without disinfection:

Example:

result = context->pfnOnDetect(context, "virus.virus.virus", KDD_HIGH, KDT_VIRWARE, KVC_NON_CURABLE);

context->status = SC_S_INFECTED;

return CLBK_OK;

Handling infected objects with disinfection

If the partner scan function considers the object malicious and attempts to disinfect it:

  1. Call pfnOnDetect and specify KVC_CURABLE in the curability parameter.
  2. The return value of pfnOnDetect determines if the disinfection is allowed by KAV SDK:
    • SC_R_CURE return code enables writing to the object. The object may be disinfected.
    • SC_R_CANCEL return code does not enable writing to the object. This may happen if the monitor cleaning mode doesn't allow disinfecting.

An example of notifying KAV SDK that an object is infected and partner scan function will attempt to disinfect it:

Example:

result = context->pfnOnDetect(context, "virus.cure.noncure", KDD_HIGH, KDT_VIRWARE, KVC_CURABLE);

If disinfection is not allowed:

  1. Set status member of KAV_SCAN_OBJECT structure to SC_S_INFECTED.
  2. Return CLBK_OK.
  3. KAV SDK will skip or delete the object, according to the monitor cleaning mode.

If disinfection is allowed:

  1. Disinfect the object using functions passed in KAV_SCAN_OBJECT (pfnWrite and pfnSetSize).
  2. Call pfnOnCured. In the successfully parameter specify the result of disinfection:
    • If the object was disinfected successfully, set successfully to TRUE. KAV SDK will consider the object disinfected.
    • If the object was not disinfected, set successfully to FALSE. KAV SDK will skip or delete the object, according to the monitor cleaning mode.
  3. Set status member of KAV_SCAN_OBJECT structure to SC_S_INFECTED.
  4. Return CLBK_OK.

An example of calling pfnOnCured if the object was disinfected successfully:

Example:

result = context->pfnOnCured(context, TRUE);

context->status = SC_S_INFECTED;

return CLBK_OK;

An example of calling pfnOnCured if the object was not disinfected:

Example:

result = context->pfnOnCured(context, FALSE);

context->status = SC_S_INFECTED;

return CLBK_OK;

Handling archives

Archives are handled differently from regular objects. To handle archive contents with partner scan function:

  1. Handle the archive as unknown object.
    1. Set status member of KAV_SCAN_OBJECT structure to SC_S_UNKNOWN.
    2. Return CLBK_OK.
  2. KAV SDK will generate EVENT_EXTERNAL_SCAN event for each object in the archive.
  3. Handle EVENT_EXTERNAL_SCAN event for each object from the archive.

Page top