5. Sample Codes

The following lists some examples using Vulnerability Module Source to get up-to-dateness of a product.

Check source definition

Query Vulnerability Module Source to get up-to-dateness of an antimalware product

#include <iostream>
#include "wa_offline_vmod_json_functions.h"
 
using namespace std;
using OfflineVMod::WaOVJson;
 
int main()
{
// initialize
wa_offline_vmod_setup();
 
// load offline database
const wchar_t *path = L"vmod.dat";
wchar_t *error = nullptr;
if (!wa_offline_vmod_read_database_from_path(path, &error)) {
wcout << L"Cannot read database" << endl << error << endl;
wa_offline_vmod_free(error);
return 1;
}
 
int signature = 25, // ESET Endpoint Security
productID = 25,
vendorID = 7, // ESET
osType = 1, // Windows
tolerance = 1,
antimalwareType = 1; // antivirus
 
wstring productName = L"ESET Endpoint Security",
vendorName = L"ESET",
productVersion = L"5.0.2211.0",
definitionDate = L"1479661200",
definitionVersion = L"14477 (20161121)",
engineVersion = L"";
 
WaOVJson inputDetails, jsonIn, jsonOut;
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_SIGNATURE, signature);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_PRODUCT_ID, productID);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_PRODUCT_NAME, productName);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_VENDOR_ID, vendorID);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_VENDOR_NAME, vendorName);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_VERSION_ELEM, productVersion);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_AM_TYPE, antimalwareType);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_INDICATOR_DEF_DATE, definitionDate);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_INDICATOR_DEF_VERSION, definitionVersion);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_INDICATOR_ENGINE_VERSION, engineVersion);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_OS_TYPE, osType);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_TOLERANCE, tolerance);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_METHOD_ID, WA_OFFLINE_VMOD_V4_CHECK_SOURCE_DEF);
jsonIn.putToObject(WA_OFFLINE_VMOD_KEY_INPUT, inputDetails);
 
if (wa_offline_vmod_invoke(jsonIn, jsonOut))
{
wcout << L"Query succeeded:" << endl;
wcout << jsonOut.toString() << endl;
 
bool isCurrent = false;
if (jsonOut.getValue(WA_OFFLINE_VMOD_KEY_IS_CURRENT, isCurrent))
{
if (isCurrent)
wcout << L"Product is up-to-date" << endl;
else
wcout << L"Product is out-of-date" << endl;
}
else
wcout << L"Cannot check if product is up-to-date" << endl;
}
else
{
wcout << L"Failed to query OfflineVMod:" << endl;
wcout << jsonOut.toString() << endl;
}
 
// teardown
wa_offline_vmod_teardown();
return 0;
}

Build/usage on older gcc without C++ 11 support

Here is the sample code on using VMod Source that is built with non-C++11 option and using char* interface

#include <iostream>
#define OFFLINE_VMOD_NO_C11
#define OFFLINE_VMOD_CHAR
#include "wa_offline_vmod_json_functions.h"
 
using namespace std;
using OfflineVMod::WaOVJson;
 
int main()
{
// initialize
wa_offline_vmod_setup();
 
// load offline database
const char *path = "vmod.dat";
char *error = nullptr;
if (!wa_offline_vmod_read_database_from_path(path, &error))
{
cout << "Cannot read database" << endl << error << endl;
wa_offline_vmod_free(error);
return 1;
}
 
int signature = 25, // ESET Endpoint Security
productID = 25,
vendorID = 7, // ESET
osType = 1, // Windows
tolerance = 1,
antimalwareType = 1; // antivirus
string productName = "ESET Endpoint Security",
vendorName = "ESET",
productVersion = "5.0.2211.0",
definitionDate = "1479661200",
definitionVersion = "14477 (20161121)",
engineVersion = "";
 
WaOVJson inputDetails, jsonIn, jsonOut;
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_SIGNATURE, signature);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_PRODUCT_ID, productID);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_PRODUCT_NAME, productName);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_VENDOR_ID, vendorID);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_VENDOR_NAME, vendorName);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_VERSION_ELEM, productVersion);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_AM_TYPE, antimalwareType);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_INDICATOR_DEF_DATE, definitionDate);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_INDICATOR_DEF_VERSION, definitionVersion);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_INDICATOR_ENGINE_VERSION, engineVersion);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_OS_TYPE, osType);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_TOLERANCE, tolerance);
inputDetails.putToObject(WA_OFFLINE_VMOD_KEY_METHOD_ID, WA_OFFLINE_VMOD_V4_CHECK_SOURCE_DEF);
jsonIn.putToObject(WA_OFFLINE_VMOD_KEY_INPUT, inputDetails);
 
if (wa_offline_vmod_invoke(jsonIn, jsonOut))
{
cout << "Query succeeded:" << endl;
cout << jsonOut.toString() << endl;
 
bool isCurrent = false;
if (jsonOut.getValue(WA_OFFLINE_VMOD_KEY_IS_CURRENT, isCurrent))
{
if (isCurrent)
cout << "Product is up-to-date" << endl;
else
cout << "Product is out-of-date" << endl;
}
else
cout << "Cannot check if product is up-to-date" << endl;
}
else
{
cout << "Failed to query OfflineVMod:" << endl;
cout << jsonOut.toString() << endl;
}
 
// teardown
wa_offline_vmod_teardown();
return 0;
}