-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathSettings.h
115 lines (98 loc) · 3.1 KB
/
Settings.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once
// Settings container
struct SETTINGS
{
#define SETTINGS_FILENAME "SigMakerEx.cfg"
UINT32 version; // Plugin version
// Function signature creation criteria
enum FUNC_CRITERIA: int
{
FUNC_ENTRY_POINT, // Function entry point
FUNC_MIN_SIZE, // By minimal byte size
FUNC_FULL, // Sig of all function instructions (just first section, if has multiple)
};
FUNC_CRITERIA funcCriteria;
enum OUTPUT_FORMAT: int
{
OF_IDA, // IDA and others "AB 78 E8 ?? ?? ?? ?? CC" style spaced bytes with wildcards
OF_CODE, // Escape encoded binary with ASCII mask "code" style in two strings.
// E.g. "\x33\x9A\xFA\x00\x00\x00\x00\x45\x68", "xxxxxxx????xx"
OF_INLINE, // Like "code" style, but byte string with inlined bytes w/wildcard
// E.g. "{0x33,0x9A,0xFA,0xAE,0xAE,0xAE,0xAE,0x45,0x68}", where 0xAE is the wildcard bytes.
};
OUTPUT_FORMAT outputFormat;
// IDA message output log level
enum OUTPUTLEVEL: int
{
LL_TERSE, // Minimal/normal output
LL_VERBOSE // Verbose for monitoring and troubleshooting
};
OUTPUTLEVEL outputLevel;
// Maximum code reference search candidates
// 0 = unlimited
UINT32 maxScanRefCount;
// Optional maximum function entry point signature bytes
// 0 = unlimited
UINT32 maxEntryPointBytes;
// Byte mask/wildcard byte for the "inline" output format
BYTE maskByte;
SETTINGS() { Default(); };
void Default()
{
version = MY_VERSION;
funcCriteria = SETTINGS::FUNC_ENTRY_POINT;
outputFormat = SETTINGS::OF_IDA;
outputLevel = SETTINGS::LL_TERSE;
maxScanRefCount = 0;
maxEntryPointBytes = 0;
maskByte = 0xAE; // Default, one of the least common code byte frequency values
}
void Validate()
{
CLAMP(funcCriteria, SETTINGS::FUNC_ENTRY_POINT, SETTINGS::FUNC_FULL);
CLAMP(outputFormat, SETTINGS::OF_IDA, SETTINGS::OF_INLINE);
CLAMP(outputLevel, SETTINGS::LL_TERSE, SETTINGS::LL_VERBOSE);
}
void Save()
{
char path[MAXSTR];
qsnprintf(path, MAXSTR - 1, "%s\\%s", get_user_idadir(), SETTINGS_FILENAME);
FILE *fp = qfopen(path, "wb");
if (fp)
{
Validate();
qfwrite(fp, this, sizeof(SETTINGS));
qfclose(fp);
}
}
void Load()
{
__try
{
char path[MAXSTR];
qsnprintf(path, MAXSTR - 1, "%s\\%s", get_user_idadir(), SETTINGS_FILENAME);
FILE *fp = qfopen(path, "rb");
if (fp)
{
qfread(fp, this, sizeof(SETTINGS));
qfclose(fp);
// If version is different other than just just the patch version, reset to the new version defaults
if ((GET_VERSION_MAJOR(version) != GET_VERSION_MAJOR(MY_VERSION)) || (GET_VERSION_MINOR(version) != GET_VERSION_MINOR(MY_VERSION)))
{
Default();
Save();
}
else
Validate();
}
}
__except (ReportException(__FUNCTION__, GetExceptionInformation()))
{
Default();
}
}
};
// Global instance
extern SETTINGS settings;
#define LOG_TERSE(...) { if (settings.outputLevel >= SETTINGS::LL_TERSE) msg(__VA_ARGS__); }
#define LOG_VERBOSE(...) { if (settings.outputLevel >= SETTINGS::LL_VERBOSE){ msg(__VA_ARGS__); WaitBox::processIdaEvents(); } }