forked from kweatherman/sigmakerex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.h
90 lines (77 loc) · 2.42 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
#pragma once
// Settings container
struct SETTINGS
{
#define SETTINGS_FILENAME "SigMakerEx.cfg"
// Function signature creation criteria
enum FUNC_CRITERIA
{
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;
// Byte mask/wildcard byte for the "inline" output format
BYTE maskByte;
SETTINGS()
{
funcCriteria = SETTINGS::FUNC_ENTRY_POINT;
outputFormat = SETTINGS::OF_IDA;
outputLevel = SETTINGS::LL_TERSE;
maxScanRefCount = 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()
{
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);
Validate();
}
}
};
// 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__); }