45 using namespace dca_malware;
47 const std::string S_ToolName =
"malwareenumsample";
48 const std::string S_ToolVersion =
"1.2";
55 "<redist-folder> <ticket> <product> [<locale>]\n"
56 " redist-folder - the folder where the DCA is installed\n"
57 " ticket - a valid ticket\n"
58 " product - the product associated with your ticket\n"
59 " locale - optional locale for the Malware category info names and descriptions, default = en_US\n\n"
67 # define DCA_BINDIR "bin/Win32"
69 # define DCA_BINDIR "bin/linux"
76 #define DCA_INITDIR "init"
82 #define DCA_LOGDIR "./logs"
94 static void SetupInitData(
const std::string& strRedistFolder,
111 const std::string& strProduct,
114 aLicenseData.
ticket = strTicket;
115 aLicenseData.
product = strProduct;
127 struct tm *expirationTime = localtime( &expirationDate );
129 std::cout <<
"License Info:" << std::endl;
130 std::cout <<
" DCA is " << ( aLicense.
isLicensed() ?
"licensed." :
131 "not licensed." ) << std::endl;
132 std::cout <<
" MaxUsers:" << aLicense.
getMaxUsers() <<
136 std::cout <<
" Ticket:" << aLicense.
getTicket() <<
138 std::cout <<
" Session:" << aLicense.
getSession() <<
142 std::cout <<
" Expiration Date:" << asctime( expirationTime ) <<
152 std::cout <<
"IBM DCA Sample: " << S_ToolName <<
" (" << S_ToolVersion <<
")" << std::endl;
161 static void PrintUsage(
const char *pSampleName )
163 std::cout << pSampleName <<
" usage:" << std::endl;
175 const std::string& strIndent =
"" )
177 std::cout << strIndent <<
"\tMalwareLocale '" << aMalwareLocale.
languageId() <<
178 "' (displayName=" << aMalwareLocale.
displayName() <<
")" << std::endl;
190 if( numOfLocales > 0 ) {
191 std::cout << std::endl <<
"MalwareLocales (size=" << numOfLocales <<
")" << std::endl;
194 PrintLocale( myMalwareLocale,
"\t" );
197 else std::cout << std::endl;
209 const std::string& strLocale,
210 const std::string& strIndent =
"" )
212 std::cout << strIndent <<
"MalwareEnum: '" << aMalwareEnum.
name( strLocale )
213 <<
"' (id=" << aMalwareEnum.
id() <<
")" << std::endl;
226 const std::string& strLocale )
231 if( numOfEnums > 0 ) {
233 std::cout <<
" (enumsSize=" << numOfEnums <<
")" << std::endl;
237 if( i > maxEnumsToDisplay && numOfEnums > maxEnumsToDisplay ) {
239 std::cout <<
"\t\t ...(" << (numOfEnums - maxEnumsToDisplay - 2) <<
240 " more)..." << std::endl;
243 const MalwareEnum myLastMalwareEnum = myMalwareEnums.
byId( myLastEnumId );
244 PrintEnum( myLastMalwareEnum, strLocale,
"\t\t" );
249 PrintEnum( myMalwareEnum, strLocale,
"\t\t" );
252 else std::cout << std::endl;
264 const std::string& strLocale,
265 const std::string& strIndent =
"" )
267 std::cout << strIndent <<
"MalwareCategory: '" << aMalwareCategory.
name( strLocale ) <<
268 "' (id=" << aMalwareCategory.
id() <<
")";
281 const std::string& strLocale )
285 if( numOfCategories > 0 ) {
286 std::cout << std::endl <<
"MalwareCategories (size=" << numOfCategories <<
291 PrintCategory( myMalwareCategory, strLocale,
"\t" );
292 EnumCategoryEnums( aMalwareCategoriesInfo, myMalwareCategory, strLocale );
295 else std::cout << std::endl;
306 const std::string& strLocale )
311 std::cout << std::endl <<
"MalwareEnums (size=" << numOfEnums <<
314 if( numOfEnums > 0 ) {
318 if( i > maxEnumsToDisplay && numOfEnums > maxEnumsToDisplay ) {
320 std::cout <<
"\t ...(" << (numOfEnums - maxEnumsToDisplay - 2) <<
321 " more)..." << std::endl;
324 const MalwareEnum myLastMalwareEnum = aMalwareEnums[ numOfEnums - 1 ];
325 PrintEnum( myLastMalwareEnum, strLocale,
"\t" );
328 const MalwareEnum myMalwareEnum = aMalwareEnums[i];
329 PrintEnum( myMalwareEnum, strLocale,
"\t" );
332 else std::cout << std::endl;
343 const std::string& strLocale )
345 std::cout <<
"Enumeration of all available MalwareLocale, MalwareCategory and MalwareEnum objects:"
349 EnumLocales( myMalwareLocales );
352 EnumCategories( aMalwareCategoriesInfo, myMalwareCategories, strLocale );
355 EnumEnums( myMalwareEnums, strLocale );
365 int main(
int argc,
char *argv[] )
377 std::string strRedistFolder = argv[ 1 ];
378 const std::string strTicket = argv[ 2 ];
379 const std::string strProduct = argv[ 3 ];
380 std::string strLocale =
"en_US";
386 if( strRedistFolder.empty() ||
395 const char c = strRedistFolder[ strRedistFolder.length() - 1 ];
396 if( c !=
'/' && c !=
'\\' )
397 strRedistFolder +=
"/";
399 std::cout << std::endl;
420 if( myLicense.
isLicensed( MalwareClassification::ID ) ) {
422 const MalwareClassification myMalwareClassification = MalwareClassification::create( myDca, myLicense );
428 EnumMalwareCategoriesInfo( myCategoriesInfo, strLocale );
433 catch(
const ExDca& ex ) {
434 std::cerr <<
"DCA Exception occured. Details: " << ex.
getDescription() <<
438 catch(
const std::exception& s ) {
439 std::cerr <<
"std::exception occured. Details: " << s.what() <<
"." << std::endl;
443 std::cerr <<
"Unknown exception caught." << std::endl;
Is used to create a License object. A license first must be created with DcaInstance::createLicense t...
Main class for the Malware classification.
Exception class used in the DCA.
void InitCUrl()
Initializes libcurl. Do not use any DCA function before initializing libcurl.
std::string initDir
the directory in which the DCA init files are stored
This header includes all header files of the Malware Classification Package.
int getMaxSessions() const
Returns the maximum allowed sessions associated with your ticket/license.
time_t getExpirationDate() const
Returns the expiration date of the license in UTC.
std::string getDescription() const
Returns a description of the error.
The MalwareCategory class contains information for a single category.
DCA_ENUM_ID_TYPE id() const
Returns the internal id of the enumerable item.
DCA_CATEGORY_ID_TYPE id() const
Returns the internal id of a MalwareCategory class.
static void SetupInitData(const std::string &redist_folder, InitData &initData)
Sets up the given initData by substituting the given redist_folder with DCA subdirectories.
std::string languageId() const
Returns the language id of the locale.
Container class for all Malware enumeration objects.
std::string binDir
the directory in which the DCA binary (*.dca) files are stored
This header includes initialization/deinitialization support functions for the 3rd party libraries us...
DCA_ENUM_ID_TYPE enumId(DCA_INDEX_TYPE index) const
Returns the id of an enum item associated with the current MalwareCategory.
std::string name(const std::string &localeString=std::string()) const
Returns the localized (display) name of the category.
void SetOpenSslCallbacks()
Initializes the required callbacks for OpenSSL when using HTTPS or SSL connections in a multi-threade...
void UnsetOpenSslCallbacks()
Unsets the openssl callbacks. Do not call any DCA function after you have called this function.
int getMaxUsers() const
Returns the maximum allowed users associated with your ticket/license.
void DeinitCUrl()
Deinitializes libcurl. Do not call any DCA function after you have called this function.
MalwareLocales getLocales() const
Returns the contained MalwareLocales.
Encapsulation of a locale class, which allows access to the language id and the display name of local...
#define DCA_LOGDIR
Relative directory for logfile(s).
Definition of a container class for MalwareEnum objects.
#define DCA_INITDIR
DCA subdirectory of the DCA initialization data.
DCA_RESULT_TYPE getReturnCode() const
Gets the code of the error.
std::string name(const std::string &localeString=std::string()) const
Returns the localized (display) name of the enumerable item.
static void PrintToolHeader()
Prints out the name and the version of this sample.
Use a License to initialize a classification package or a toolbox package.
MalwareCategories getCategories() const
Returns the contained MalwareCategories.
bool isLicensed(DCA_MODULE_ID_TYPE id=0, bool force=false) const
Checks whether the given License is valid for the given module id.
static void PrintLicenseInfo(const License &aLicense)
Prints out the information about the provided License.
std::string ticket
The ticket as provided in the license.
This header includes all header files of the DCA Base Package.
DCA_SIZE_TYPE size() const
Returns the number of locales in the container.
Definition of a container class for MalwareLocale objects.
Encapsulates the init and deinit of the DCA API.
std::string product
The product code used with the license.
std::string logDir
the directory in which the DCA log file should be created
static void PrintUsage(const char *name)
Prints out the syntax of the sample.
std::string getLastMessage() const
Returns the last message received from our license server or if none available the last available mes...
size_t DCA_INDEX_TYPE
Type for index access (used for arrays and collections).
size_t DCA_SIZE_TYPE
Type for size (used for size of array and collections).
DCA_SIZE_TYPE size() const
Returns the number of enums in the container.
std::string getTicket() const
Returns the ticket of the license as string.
MalwareCategoriesInfo getCategoriesInfo() const
Retrieve the MalwareCategoriesInfo class.
#define DCA_BINDIR
DCA subdirectory of the DCA binaries.
Definition of a container class for MalwareCategory objects.
int DCA_ENUM_ID_TYPE
Id type for MalwareEnum class.
std::string displayName() const
Returns the display name of the locale.
std::string getSession() const
Returns the session of the license as string.
MalwareEnum byId(DCA_ENUM_ID_TYPE id) const
Returns the MalwareEnums with the given id.
DCA_SIZE_TYPE size() const
Returns the number of categories in the container.
DCA_SIZE_TYPE enumsSize() const
Returns the count of MalwareEnum items associated with current MalwareCategory.
const std::string S_UsageString
Usage string, displayed if a parameter is missing.
This structure is used to initialize the DcaInstance.
MalwareEnums getEnums() const
Returns the contained MalwareEnums.
static DcaInstance create(const InitData &initData)
Creates a DcaInstance, starts up the DCA API and initializes the required main module.
static void SetupLicense(const std::string &ticket, const std::string &product, LicenseData &licenseData)
Sets up the given licenseData by copying the given ticket and product strings.
The MalwareEnum class describes a single enumerable item (currebtly not used for malware)
License createLicense(const LicenseData &licData, const ProxySettings &proxySettings=ProxySettings(), LogLevel aLogLevel=LOG_Initial) const
Creates a License object using the given LicenseData.
int main(int argc, char *argv[])
The main routine.