-
Notifications
You must be signed in to change notification settings - Fork 2
/
redsigc.h
69 lines (54 loc) · 1.82 KB
/
redsigc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef REDSIGC_H
#define REDSIGC_H
#define REDSIGC_VERSION std::string("0.8")
#include <vector>
#include <string>
#include <cxxopts.hpp>
#include <redasm/redasm_api.h>
#include "patterngenerator.h"
struct SelectedOptions
{
SelectedOptions(): flags(0) { }
int flags;
std::vector<std::string> defaultargs;
std::string prefix, suffix, symbol, infolder, name;
bool has(int flag) const { return flags & flag; }
const std::string& input() const { return defaultargs.front(); }
std::string output() const { return (defaultargs.front() == defaultargs.back()) ? (defaultargs.back() + ".json") : defaultargs.back(); }
};
class REDSigC
{
private:
enum { None = 0, JSONSourceOutput = 1, AutoPrefix = 2, Disassemble = 4, Folder = 8 };
public:
REDSigC();
int run(int argc, char **argv);
private:
static std::string autoModuleName(std::string infile);
PatternGenerator* getPatternGenerator(const std::list<std::string>& infiles);
void getInputFiles(std::list<std::string>& infiles) const;
bool disassemblePattern(PatternGenerator* patterngenerator);
bool checkOptions(int argc, char **argv);
private:
template<typename T> static bool checkOption(const cxxopts::ParseResult& parseresult, const std::string& option, T* result = NULL);
private:
SelectedOptions m_options;
};
template<typename T> bool REDSigC::checkOption(const cxxopts::ParseResult& parseresult, const std::string& option, T *result)
{
try
{
if(!parseresult.count(option))
return false;
T opt = parseresult[option].as<T>();
if(result)
*result = opt;
}
catch(const cxxopts::OptionException& e)
{
std::cout << e.what() << std::endl;
return false;
}
return true;
}
#endif // REDSIGC_H