MDES SDK Guides Quick start guide
This guide will walk you through the basic steps needed to link against the MDES SDK and start calling functionality. If you are new to the MDES SDK, this is the first guide you should read before continuing.
Loading the library
Before you do anything, you must first load the MDES SDK into the process space. You can do this either implicitly or explicitly. Your integration must dynamically link against the libwaapi.dll. For the purpose of this example, we will assume implicit loading has been performed (e.g. linked against the libwaapi.lib file at compile time). If the libwaapi.lib file is in your working directory or in the path specified in the LIB environment variable, you can use the following to implicitly link the MDES SDK:
// implicitly link against the MDES SDK
#pragma comment( lib, "libwaapi" )
The alternative would be to link against the libwaapi.lib file in the project settings of your IDE.
You only need to include a single header file in your source code to obtain access to the entire MDES SDK. Include wa_api.h. Make sure this header is in your header search path. NOTE: You need all header files found in the "inc" directory to be deployed along side this header, however, you only need to include this header in your source.
// obtain access to the MDES SDK
#include "wa_api.h"
The MetaDefender Endpoint Security SDK does not make use of namespaces.
Initialize & configure
We must first intialize the MDES SDK before we can use it. We can also set any configuration options during this process. You only have to initialize the MDES SDK a single time, regardless of single or multithreaded deployment. Some setup options may be reconfigured after setup has occurred, but options such as license info, threading mode or file locations may not be changed without first calling teardown. If you attempt to initialize non-reconfigurable options in the MDES SDK when it is already initialized, you will get an already initialized error code. You must pass in a valid license key in order for the MDES SDK to successfully initialize itself. If you do not have a license key, contact sales@opswat.com.
// setup any configuration options, pass NULL to use all defaults, replace "passkey_string" with customer`s license one
const wa_wchar * json_config = L"{ \"config\" : { \"enable_pretty_print\": true , \"passkey_string\": \"passkey_string\"}}";
// declare variable to populate results, must be freed later
wa_wchar * json_out = NULL;
// initialize
wa_int return_code = wa_api_setup( json_config, &json_out );
if( WAAPI_SUCCESS( return_code ) )
{
// TODO: Successful initialization
}
else
{
// TODO: Failed to initialize
}
wa_api_free( json_out );
Call functionality
After a successful initialization, we can make invocation calls through the wa_api_invoke method. In this example, we are going to detect all public file sharing applications installed on the local machine.
We must setup our JSON input argument to detect installed applications of category public file sharing and pass
the proper component_method
to the function. The json_out
parameter will be allocated and populated with the results, either successful results
or the error results if the function call fails.
// setup our input
wstringstream ss;
ss << L"{ \"input\" : { \"method\" : 0, \"category\" : " << WAAPI_CATEGORY_PUBLIC_FILE_SHARING << L" }}";
std::wstring json_in(ss.str());
// declare variable to populate results, must be freed later
wa_wchar * json_out = NULL;
// invoke
return_code = wa_api_invoke( json_in.c_str(), &json_out );
if( WAAPI_SUCCESS( return_code ) )
{
// TODO: handle success results
}
else
{
// TODO: handle failure results
}
// handle clean, json_out must be freed
wa_api_free( json_out );
Deinitialize
Once you are finished with the MDES SDK, you can now deinitialize it. When you deinitialize the MDES SDK, we will release all internally held data structures and memory. Once this is complete, you can unload the MDES SDK from your process space.
// deinitialize the MDES SDK
return_code = wa_api_teardown();
if( WAAPI_SUCCESS( return_code ) )
{
// TODO: Successful deinitialization
}
else
{
// TODO: Failed to deinitialize
}