kaveScanFile

Scans a file for malware. For usage example, see section "Regular file scanning".

KAV SDK provides the kaveScanFileEx function that allows you to make a more rigorous analysis of a file by supplying extra technical data about the file to KAV Engine.

When the Cloud Protection is enabled, this function performs additional checking of object reputation via Kaspersky Security Network.

Syntax

HRESULT kaveScanFile (

const char *pScanFileName,

unsigned long dwScanPriority,

unsigned long dwScanningMode,

unsigned long dwCleaningMode,

unsigned long dwScanTimeout,

void *pUserContext,

unsigned long *pdwObjectID,

KAV_RESULT *pResult);

Parameters

The kaveScanFile function has the following parameters.

kaveScanFile function parameters

Name

Type

Description

pScanFileName

in

A pointer to the string containing an UNC name of the file to scan. The file can reside in any data storage device.

dwScanPriority

in

A priority level for scanning the indicated file. The higher the value is, the higher the priority is.

Priority level is taken into consideration when selecting the objects from the scanning queue. The queue is sorted according to the objects’ priority. The files with higher priority are scanned first.

dwScanningMode

in

File scanning mode.

For more information, see section "Scanning modes".

In case the user is supposed to decide on the action with an infected object, such action is requested by calling the callback function with the appropriate parameters. For more details on callback functions, see section "Callback function".

dwCleaningMode

in

An action upon detection malware. For possible parameter values, see section "Cleaning modes".

Regardless of the cleaning mode settings, the KAV SDK reacts to the malware detection event by calling a callback function with the appropriate parameters. For more details on the callback function, see section "Callback function".

dwScanTimeout

in

The maximum time in milliseconds allotted for performing a scan task. After the specified timeout expires, the scanning is stopped and the function returns with the KAV_E_TIMEOUT error code.

To set no time limit for the scanning task, use the INFINITE value or set it to zero.

pUserContext

in

Any user data that can be used by a callback function. For more details on the callback function, see section "Callback function".

pdwObjectID

out

A pointer to the scan task identifier. It helps to distinguish scan tasks and their results in case of asynchronous scanning and monitoring—it is used for accessing the scanning result through a callback function. For more details on the callback function, see section "Callback function".

The scan task ID can also be used for canceling this particular scanning task. For more information, see kaveCancelScan.

When scanning files via File Monitor, unique identifiers assigned to scanned files by KAV SDK are returned directly to callback function in the dwObjectID parameter. For more details, see section "Callback function prototype".

pResult

out

A pointer to the variable describing the scan result.

If this variable does not have the NULL value, the function is called synchronously—the function does not return until the scan is completed. The scan result will be written to the pResult variable.

If this variable has the NULL value, the function is called asynchronously. In this case the scan result can be obtained only by calling a callback function with the appropriate parameters. For more details on the callback function, see section "Callback function".

Return value

If the kaveScanFile function succeeds, the return code is S_OK. If any malware is detected, the scan results are written to the corresponding parameter (in case of synchronous scanning), or a callback function is called.

When the function is invoked with invalid arguments that do not meet function specifications of the function, it returns the E_INVALIDARG return value.

In other cases one of the error return values is returned. For more information about return codes, see section "Return codes".

Handling encoded filenames

On Unix-like systems scanning files with names containing incorrect UTF-encoded byte sequences such as trailing UTF-8 byte may result in the E_INVALIDARG code. Invalid bytes are silently removed by operating system when invoking file I/O APIs. When this file name is handled by the operating system API, the file name passed to the function will not have the removed UTF-encoded characters. Effectively this results in a file path that does not have the UTF-encoded characters because they are removed by the operating system. The kaveScanFile function will throw the E_INVALIDARG error which has the value of 0x80070057.

For example, according to the Unicode standard recommendations, in a sequence of two octets the initial octet has its first two high-order bits set to 1 with the following bit set to 0. All the remaining bits are used to encode the character. The second octet in this sequence of two octets should start with the high-order bit set to 1. The following 7th bit should be set to zero (0) with the remaining six bits set to their values to specify the character that should be encoded. The correct byte stream should look like (two octets): 110XXXXX 10XXXXXX (character bits are marked with X). Consider the following file name is passed to the function (character codes as defined by their octal codes): \326\320\316\304. When converted from octal to hexadecimal codes this will result in this string: 00D6 00D0 00CE 00C4. In other words, the converted string will look like: ЦРОД. Converting to binary results in the four octets: 11010110 11010000 11001110 11000100. The resulting byte stream is invalid and does not comply with the UTF-8 transformation standard because the two second octets have ones set as the bits following the high-order bits of one.

For the sake of platform independence the SDK Engine handles strings in Unicode whereas the file I/O stores the file names byte stream in a local system encoding. The KAV SDK always converts the strings from Unicode to a current system locale before passing the strings to the file system APIs. The incorrect byte stream produced as a result of using unauthorized characters in the file names results in the E_INVALIDARG error. To avoid this error when scanning files with incorrect file names, please do one of the following:

For more information about UTF-8 encoding, please see RFC 3629.

Page top