1
1
#include < windows.h>
2
- #include < stdio.h >
2
+ #include < cstdio >
3
3
#include < tchar.h>
4
4
#include < atlstr.h>
5
5
#include < fstream>
@@ -32,17 +32,18 @@ vector<string> listFilesInDirectory(const std::string& directoryPath) {
32
32
return fileNames;
33
33
}
34
34
35
- string removeExt (const string& filename) {
35
+ string removeExtension (const string& filename) {
36
36
size_t dotPos = filename.rfind (' .' );
37
37
if (dotPos == string::npos) {
38
38
return filename;
39
39
}
40
40
return filename.substr (0 , dotPos);
41
41
}
42
42
43
- BOOL mutating_inputs (const string& filename, const string& mut, const string& inputFolder, const string& outputFolder, string ext)
43
+
44
+ BOOL mutateInputs (const string& filename, const string& mut, const string& inputFolder, const string& outputFolder, string ext)
44
45
{
45
- string nfilename = removeExt (filename);
46
+ string nfilename = removeExtension (filename);
46
47
string outputFileName = outputFolder + " \\ " + nfilename + " _id=" + mut + " ." + ext;
47
48
STARTUPINFOA si;
48
49
PROCESS_INFORMATION pi ;
@@ -55,19 +56,19 @@ BOOL mutating_inputs(const string& filename, const string& mut, const string& in
55
56
si.cb = sizeof (si);
56
57
57
58
if (!CreateProcessA (
58
- NULL , // Target app
59
- cmd, // Command line
60
- NULL , // Process handle not inheritable
61
- NULL , // Thread handle not inheritable
62
- FALSE , // Set handle inheritance to FALSE
63
- 0 , // No creation flag
64
- NULL , // Use parent's environment block
65
- NULL , // Use parent's starting directory
66
- &si, // Pointer to STARTUPINFO structure
67
- &pi ) // Pointer to PROCESS_INFORMATION structure
59
+ nullptr , // Target app
60
+ cmd, // Command line
61
+ nullptr , // Process handle not inheritable
62
+ nullptr , // Thread handle not inheritable
63
+ FALSE , // Set handle inheritance to FALSE
64
+ 0 , // No creation flag
65
+ nullptr , // Use parent's environment block
66
+ nullptr , // Use parent's starting directory
67
+ &si, // Pointer to STARTUPINFO structure
68
+ &pi ) // Pointer to PROCESS_INFORMATION structure
68
69
)
69
70
{
70
- printf (" CreateProcess failed GLE=(%d ).\n " , GetLastError ());
71
+ printf (" CreateProcess failed GLE=(%lu ).\n " , GetLastError ());
71
72
return 1 ;
72
73
}
73
74
@@ -81,7 +82,7 @@ BOOL mutating_inputs(const string& filename, const string& mut, const string& in
81
82
82
83
}
83
84
84
- void reporting (const string exceptionMessage, DWORD exceptionCode, string inputFile)
85
+ void reportCrash (const string& exceptionMessage, DWORD exceptionCode, const string& inputFile)
85
86
{
86
87
string crashFolder = originalFolder + " crashes" ;
87
88
if (!fs::exists (crashFolder))
@@ -99,7 +100,7 @@ void reporting(const string exceptionMessage, DWORD exceptionCode, string inputF
99
100
100
101
}
101
102
102
- DWORD ProcessDebugEvent (DEBUG_EVENT* debugEvent, string inputFile)
103
+ DWORD ProcessDebugEvent (DEBUG_EVENT* debugEvent, const string& inputFile)
103
104
{
104
105
if (debugEvent->dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
105
106
{
@@ -112,51 +113,52 @@ DWORD ProcessDebugEvent(DEBUG_EVENT* debugEvent, string inputFile)
112
113
case EXCEPTION_BREAKPOINT:
113
114
break ;
114
115
case EXCEPTION_ACCESS_VIOLATION:
115
- reporting (" Critical exception: Access Violation (0x" , exceptionCode, inputFile);
116
+ reportCrash (" Critical exception: Access Violation (0x" , exceptionCode, inputFile);
116
117
break ;
117
118
118
119
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
119
- reporting (" Critical exception: Array Bounds Exceeded (0x" , exceptionCode, inputFile);
120
+ reportCrash (" Critical exception: Array Bounds Exceeded (0x" , exceptionCode, inputFile);
120
121
break ;
121
122
122
123
case EXCEPTION_FLT_DENORMAL_OPERAND:
123
- reporting (" Critical exception: Invalid floating-point operation (denormal operand) (0x" , exceptionCode, inputFile);
124
+ reportCrash (" Critical exception: Invalid floating-point operation (denormal operand) (0x" , exceptionCode,
125
+ inputFile);
124
126
break ;
125
127
126
128
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
127
- reporting (" Critical exception: Floating-point division by zero (0x" , exceptionCode, inputFile);
129
+ reportCrash (" Critical exception: Floating-point division by zero (0x" , exceptionCode, inputFile);
128
130
break ;
129
131
130
132
case EXCEPTION_FLT_OVERFLOW:
131
- reporting (" Critical exception: Floating-point overflow (0x" , exceptionCode, inputFile);
133
+ reportCrash (" Critical exception: Floating-point overflow (0x" , exceptionCode, inputFile);
132
134
break ;
133
135
134
136
case EXCEPTION_FLT_STACK_CHECK:
135
- reporting (" Critical exception: Hardware floating-point stack overflow (0x" , exceptionCode, inputFile);
137
+ reportCrash (" Critical exception: Hardware floating-point stack overflow (0x" , exceptionCode, inputFile);
136
138
break ;
137
139
138
140
case EXCEPTION_FLT_UNDERFLOW:
139
- reporting (" Critical exception: Floating-point underflow (0x" , exceptionCode, inputFile);
141
+ reportCrash (" Critical exception: Floating-point underflow (0x" , exceptionCode, inputFile);
140
142
break ;
141
143
142
144
case EXCEPTION_ILLEGAL_INSTRUCTION:
143
- reporting (" Critical exception: Illegal instruction encountered (0x" , exceptionCode, inputFile);
145
+ reportCrash (" Critical exception: Illegal instruction encountered (0x" , exceptionCode, inputFile);
144
146
break ;
145
147
146
148
case EXCEPTION_IN_PAGE_ERROR:
147
- reporting (" Critical exception: Page fault (0x" , exceptionCode, inputFile);
149
+ reportCrash (" Critical exception: Page fault (0x" , exceptionCode, inputFile);
148
150
break ;
149
151
150
152
case EXCEPTION_INT_DIVIDE_BY_ZERO:
151
- reporting (" Critical exception: Integer division by zero (0x" , exceptionCode, inputFile);
153
+ reportCrash (" Critical exception: Integer division by zero (0x" , exceptionCode, inputFile);
152
154
break ;
153
155
154
156
case EXCEPTION_INT_OVERFLOW:
155
- reporting (" Critical exception: Integer overflow (0x" , exceptionCode, inputFile);
157
+ reportCrash (" Critical exception: Integer overflow (0x" , exceptionCode, inputFile);
156
158
break ;
157
159
158
160
case EXCEPTION_STACK_OVERFLOW:
159
- reporting (" Critical exception: Stack overflow (0x" , exceptionCode, inputFile);
161
+ reportCrash (" Critical exception: Stack overflow (0x" , exceptionCode, inputFile);
160
162
break ;
161
163
162
164
default :
@@ -171,30 +173,30 @@ BOOL runTargetProcess(const string& targetApp, const string& inputFile)
171
173
STARTUPINFOA si;
172
174
PROCESS_INFORMATION pi ;
173
175
DEBUG_EVENT debug_event;
174
- string arg1 = targetApp. c_str () ;
176
+ const string& arg1 = targetApp;
175
177
string arg2 = " " ;
176
- string arg3 = inputFile. c_str () ;
178
+ const string& arg3 = inputFile;
177
179
string args = arg1 + arg2 + arg3;
178
- LPSTR cmd = (LPSTR)args.c_str ();
180
+ auto cmd = (LPSTR)args.c_str ();
179
181
180
182
ZeroMemory (&si, sizeof (si));
181
183
ZeroMemory (&pi , sizeof (pi ));
182
184
si.cb = sizeof (si);
183
185
184
186
if (!CreateProcessA (
185
- NULL , // NULL
187
+ nullptr , // NULL
186
188
cmd, // Command line
187
- NULL , // Process handle not inheritable
188
- NULL , // Thread handle not inheritable
189
+ nullptr , // Process handle not inheritable
190
+ nullptr , // Thread handle not inheritable
189
191
TRUE , // Set handle inheritance to FALSE
190
192
DEBUG_ONLY_THIS_PROCESS, // Debug only this process flag
191
- NULL , // Use parent's environment block
192
- NULL , // Use parent's starting directory
193
+ nullptr , // Use parent's environment block
194
+ nullptr , // Use parent's starting directory
193
195
&si, // Pointer to STARTUPINFO structure
194
196
&pi ) // Pointer to PROCESS_INFORMATION structure
195
197
)
196
198
{
197
- printf (" CreateProcess failed GLE=(%d ).\n " , GetLastError ());
199
+ printf (" CreateProcess failed GLE=(%lu ).\n " , GetLastError ());
198
200
return 1 ;
199
201
}
200
202
@@ -215,12 +217,12 @@ BOOL runTargetProcess(const string& targetApp, const string& inputFile)
215
217
int _tmain (int argc, char *argv[])
216
218
{
217
219
// Declaring mutation arguments list
218
- vector<string> mylist = {" ab" , " bd" , " bf" , " bi" , " br" , " bp" , " bei" , " bed" , " ber" , " sr" , " sd" , " ld" , " lds" , " lr2" ,
219
- " li" , " lr" , " ls" , " lp" , " lis" , " lrs" , " td" , " tr2" , " ts1" , " ts2" , " tr" , " uw" , " ui" , " num" , " xp" , " ft" , " fn" ,
220
- " fo" };
220
+ vector<string> mutationArguments = {" ab" , " bd" , " bf" , " bi" , " br" , " bp" , " bei" , " bed" , " ber" , " sr" , " sd" , " ld" , " lds" , " lr2" ,
221
+ " li" , " lr" , " ls" , " lp" , " lis" , " lrs" , " td" , " tr2" , " ts1" , " ts2" , " tr" , " uw" , " ui" , " num" , " xp" , " ft" , " fn" ,
222
+ " fo" };
221
223
222
224
// Command line interface logic
223
- CLI::App aplos{" Applos is a simple fuzzer." };
225
+ CLI::App aplos{" Aplos is a simple fuzzer." };
224
226
argv = aplos.ensure_utf8 (argv);
225
227
226
228
string targetApp, inputs, ext;
@@ -239,8 +241,8 @@ int _tmain(int argc, char *argv[])
239
241
CLI11_PARSE (aplos, argc, argv);
240
242
241
243
// Create timestamp for the initial output folder
242
- time_t now = time (0 );
243
- struct tm formattedTime;
244
+ time_t now = time (nullptr );
245
+ struct tm formattedTime{} ;
244
246
localtime_s (&formattedTime, &now);
245
247
stringstream timestampStream;
246
248
timestampStream << setw (2 ) << setfill (' 0' ) << formattedTime.tm_mday << " _"
@@ -287,10 +289,10 @@ for (int generation = 1;; ++generation)
287
289
// Mutating each file with every mutation
288
290
for (const string& file : files)
289
291
{
290
- for (const string& mut : mylist )
292
+ for (const string& mut : mutationArguments )
291
293
{
292
294
cout << " Mutating file: " << file << " with mutation " << mut << endl;
293
- mutating_inputs (file, mut, inputFolder, outputFolder, ext);
295
+ mutateInputs (file, mut, inputFolder, outputFolder, ext);
294
296
}
295
297
}
296
298
0 commit comments