Download Virtual Disk API Programming Guide
Transcript
5Vi
Practical Programming Tasks
5
This chapter presents some practical programming challenges not covered in the sample program, including:
“Scan VMDK for Virus Signatures” on page 31
“Creating Virtual Disks” on page 32
“Working with Virtual Disk Data” on page 33
“Managing Child Disks” on page 34
“Interfacing With the VIX API” on page 35
“Interfacing With VMware vSphere” on page 36
Scan VMDK for Virus Signatures
One of the tasks listed in “Solutions Enabled by the Virtual Disk API” on page 11 is to scan a VMDK for virus signatures. Using the framework of our sample program, a function can implement the -virus command‐line option. The function in Example 5‐1 relies on a pre‐existing library routine called SecureVirusScan(), which typically is supplied by a vendor of antivirus software. As it does for email messages, the library routine scans a buffer of any size against the vendor’s latest pattern library, and returns TRUE if it identifies a virus. Example 5-1. Function to Scan VMDK for Viruses
extern int SecureVirusScan(const uint8 *buf, size_t n);
/*
*
DoVirusScan -*
Scan the content of a virtual disk for virus signatures.
*/
static void DoVirusScan(void)
{
VixDisk disk(appGlobals.connection, appGlobals.diskPath, appGlobals.openFlags);
VixDiskLibDiskInfo info;
uint8 buf[VIXDISKLIB_SECTOR_SIZE];
VixDiskLibSectorType sector;
VixError vixError = VixDiskLib_GetInfo(disk.Handle(), &info);
CHECK_AND_THROW(vixError);
cout << "capacity = " << info.capacity << " sectors" << endl;
// read all sectors even if not yet populated
for (sector = 0; sector < info.capacity; sector++) {
vixError = VixDiskLib_Read(disk.Handle(), sector, 1, buf);
CHECK_AND_THROW(vixError);
if (SecureVirusScan(buf, sizeof buf)) {
printf("Virus detected in sector %d\n", sector);
}
}
cout << info.capacity << " sectors scanned" << endl;
}
VMware, Inc.
31