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:
Note that KAV SDK does not scan such objects.
Note that KAV SDK does not scan or disinfect such objects.
Note that KAV SDK does not scan or disinfect such objects.
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:
dwParam1 contains lower 32 bits of a pointer to KAV_SCAN_OBJECT structure.dwParam2 contains higher 32 bits of a pointer to KAV_SCAN_OBJECT structure (in 64-bit systems).pObjectName contains the name of the object.dwMonitorID is the identifier of the monitor that detected the object.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:
pfnSetSize function changes the size of the object. This function is used for disinfection.pfnRead function reads the object into a buffer, starting from the current position.pfnWrite function writes buffer contents to the object, starting from the current position. This function is used for disinfection.pfnSeek function moves the current position.Functions that notify KAV SDK about partner function actions:
pfnOnProcessing notifies KAV SDK that partner function keeps processing the event. This is a heartbeat function.pfnOnDetect notifies KAV SDK that partner function detected a threat.pfnOnCured notifies KAV SDK about the result of disinfection performed by partner function.Other members:
status member contains the status of the partner function scan. KAV SDK uses this parameter to determine the status of the scan with partner function.
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:
KAV_O_M_EXTERNAL_SCAN flag when you initialize the monitor.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:
KAV_SCAN_OBJECT (pfnRead, and pfnSeek).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:
status member of KAV_SCAN_OBJECT structure to SC_S_UNKNOWN.CLBK_OK.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:
status member of KAV_SCAN_OBJECT structure to SC_S_CLEAN.CLBK_OK. 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:
pfnOnDetect and specify KVC_NON_CURABLE in the curability parameter.status member of KAV_SCAN_OBJECT structure to SC_S_INFECTED.CLBK_OK.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:
pfnOnDetect and specify KVC_CURABLE in the curability parameter.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:
status member of KAV_SCAN_OBJECT structure to SC_S_INFECTED.CLBK_OK.If disinfection is allowed:
KAV_SCAN_OBJECT (pfnWrite and pfnSetSize).pfnOnCured. In the successfully parameter specify the result of disinfection:successfully to TRUE. KAV SDK will consider the object disinfected.successfully to FALSE. KAV SDK will skip or delete the object, according to the monitor cleaning mode.status member of KAV_SCAN_OBJECT structure to SC_S_INFECTED.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:
status member of KAV_SCAN_OBJECT structure to SC_S_UNKNOWN.CLBK_OK.EVENT_EXTERNAL_SCAN event for each object in the archive.EVENT_EXTERNAL_SCAN event for each object from the archive.