binlex
common.h
1 #ifndef COMMON_H
2 #define COMMON_H
3 
4 #include <iostream>
5 #include <iomanip>
6 #include <vector>
7 #include <queue>
8 #include <set>
9 #include <map>
10 #include "args.h"
11 
12 #ifdef _WIN32
13 #define BINLEX_EXPORT __declspec(dllexport)
14 #else
15 #define BINLEX_EXPORT
16 #endif
17 
18 using std::set;
19 using std::map;
20 using std::queue;
21 using std::set;
22 using std::vector;
23 using std::ofstream;
24 using std::stringstream;
25 using std::string;
26 using std::cin;
27 using std::cout;
28 using std::cerr;
29 using std::endl;
30 using std::hex;
31 using std::setfill;
32 using std::setw;
33 
34 #define BINARY_MAX_SECTIONS 256
35 
36 #ifdef _WIN32
37 typedef unsigned int uint;
38 typedef uint useconds_t;
39 #endif
40 
41 extern binlex::Args g_args;
42 
43 // Debug
44 #define PRINT_DEBUG(...) {if (g_args.options.debug) fprintf(stderr, __VA_ARGS__); }
45 #define PRINT_ERROR_AND_EXIT(...) { fprintf(stderr, __VA_ARGS__); exit(EXIT_FAILURE); }
46 void print_data(string title, void *data, uint32_t size);
47 #define PRINT_DATA(title, data, size) { print_data(title, data, size); }
48 
49 namespace binlex {
50  class Common{
54  public:
61  BINLEX_EXPORT static string GetTLSH(const uint8_t *data, size_t len);
68  BINLEX_EXPORT static string GetFileTLSH(const char *file_path);
74  BINLEX_EXPORT static string SHA256(char *trait);
81  BINLEX_EXPORT static string GetFileSHA256(char *file_path);
89  BINLEX_EXPORT static string GetSHA256(const uint8_t *data, size_t len);
95  BINLEX_EXPORT static vector<char> TraitToChar(string trait);
101  BINLEX_EXPORT static string RemoveWildcards(string trait);
107  BINLEX_EXPORT static uint GetByteSize(string s);
113  BINLEX_EXPORT static string RemoveSpaces(string s);
120  BINLEX_EXPORT static string WildcardTrait(string trait, string bytes);
126  BINLEX_EXPORT static string TrimRight(const std::string &s);
133  BINLEX_EXPORT static string HexdumpBE(const void *data, size_t size);
139  BINLEX_EXPORT static string Wildcards(uint count);
140  BINLEX_EXPORT static string HexdumpMemDisp(uint64_t disp);
141  BINLEX_EXPORT static float Entropy(string trait);
148  BINLEX_EXPORT static void Hexdump(const char * desc, const void * addr, const int len);
149  };
150 }
151 
152 #endif
binlex::Common::GetFileTLSH
static BINLEX_EXPORT string GetFileTLSH(const char *file_path)
binlex::Common::RemoveSpaces
static BINLEX_EXPORT string RemoveSpaces(string s)
binlex::Common::SHA256
static BINLEX_EXPORT string SHA256(char *trait)
binlex::Common::GetFileSHA256
static BINLEX_EXPORT string GetFileSHA256(char *file_path)
binlex::Common::Hexdump
static BINLEX_EXPORT void Hexdump(const char *desc, const void *addr, const int len)
binlex::Common
Definition: common.h:50
binlex::Common::RemoveWildcards
static BINLEX_EXPORT string RemoveWildcards(string trait)
binlex::Common::GetTLSH
static BINLEX_EXPORT string GetTLSH(const uint8_t *data, size_t len)
binlex::Common::TrimRight
static BINLEX_EXPORT string TrimRight(const std::string &s)
binlex::Common::WildcardTrait
static BINLEX_EXPORT string WildcardTrait(string trait, string bytes)
binlex::Common::GetByteSize
static BINLEX_EXPORT uint GetByteSize(string s)
binlex::Args
Definition: args.h:28
binlex::Common::TraitToChar
static BINLEX_EXPORT vector< char > TraitToChar(string trait)
binlex::Common::Wildcards
static BINLEX_EXPORT string Wildcards(uint count)
binlex::Common::HexdumpBE
static BINLEX_EXPORT string HexdumpBE(const void *data, size_t size)
binlex::Common::GetSHA256
static BINLEX_EXPORT string GetSHA256(const uint8_t *data, size_t len)
binlex
the binlex namespace