Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit f0d4a68

Browse files
committed
feat(build): adding CMakeLists.txt
also fixed some little things the clang-tidy was whining about, nothing major
1 parent c455d80 commit f0d4a68

File tree

4 files changed

+62
-46
lines changed

4 files changed

+62
-46
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
cmake-build-debug
3+
.gitignore

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.27)
2+
project(Aplos)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
include_directories(include)
7+
8+
add_executable(Aplos
9+
include/CLI11.hpp
10+
src/Aplos.cpp
11+
)

src/CLI11.hpp include/CLI11.hpp

File renamed without changes.

src/Aplos.cpp

+48-46
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <windows.h>
2-
#include <stdio.h>
2+
#include <cstdio>
33
#include <tchar.h>
44
#include <atlstr.h>
55
#include <fstream>
@@ -32,17 +32,18 @@ vector<string> listFilesInDirectory(const std::string& directoryPath) {
3232
return fileNames;
3333
}
3434

35-
string removeExt(const string& filename) {
35+
string removeExtension(const string& filename) {
3636
size_t dotPos = filename.rfind('.');
3737
if (dotPos == string::npos) {
3838
return filename;
3939
}
4040
return filename.substr(0, dotPos);
4141
}
4242

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)
4445
{
45-
string nfilename = removeExt(filename);
46+
string nfilename = removeExtension(filename);
4647
string outputFileName = outputFolder + "\\" + nfilename + "_id=" + mut + "." + ext;
4748
STARTUPINFOA si;
4849
PROCESS_INFORMATION pi;
@@ -55,19 +56,19 @@ BOOL mutating_inputs(const string& filename, const string& mut, const string& in
5556
si.cb = sizeof(si);
5657

5758
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
6869
)
6970
{
70-
printf("CreateProcess failed GLE=(%d).\n", GetLastError());
71+
printf("CreateProcess failed GLE=(%lu).\n", GetLastError());
7172
return 1;
7273
}
7374

@@ -81,7 +82,7 @@ BOOL mutating_inputs(const string& filename, const string& mut, const string& in
8182

8283
}
8384

84-
void reporting(const string exceptionMessage, DWORD exceptionCode, string inputFile)
85+
void reportCrash(const string& exceptionMessage, DWORD exceptionCode, const string& inputFile)
8586
{
8687
string crashFolder = originalFolder + "crashes";
8788
if (!fs::exists(crashFolder))
@@ -99,7 +100,7 @@ void reporting(const string exceptionMessage, DWORD exceptionCode, string inputF
99100

100101
}
101102

102-
DWORD ProcessDebugEvent(DEBUG_EVENT* debugEvent, string inputFile)
103+
DWORD ProcessDebugEvent(DEBUG_EVENT* debugEvent, const string& inputFile)
103104
{
104105
if (debugEvent->dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
105106
{
@@ -112,51 +113,52 @@ DWORD ProcessDebugEvent(DEBUG_EVENT* debugEvent, string inputFile)
112113
case EXCEPTION_BREAKPOINT:
113114
break;
114115
case EXCEPTION_ACCESS_VIOLATION:
115-
reporting("Critical exception: Access Violation (0x", exceptionCode, inputFile);
116+
reportCrash("Critical exception: Access Violation (0x", exceptionCode, inputFile);
116117
break;
117118

118119
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);
120121
break;
121122

122123
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);
124126
break;
125127

126128
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);
128130
break;
129131

130132
case EXCEPTION_FLT_OVERFLOW:
131-
reporting("Critical exception: Floating-point overflow (0x", exceptionCode, inputFile);
133+
reportCrash("Critical exception: Floating-point overflow (0x", exceptionCode, inputFile);
132134
break;
133135

134136
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);
136138
break;
137139

138140
case EXCEPTION_FLT_UNDERFLOW:
139-
reporting("Critical exception: Floating-point underflow (0x", exceptionCode, inputFile);
141+
reportCrash("Critical exception: Floating-point underflow (0x", exceptionCode, inputFile);
140142
break;
141143

142144
case EXCEPTION_ILLEGAL_INSTRUCTION:
143-
reporting("Critical exception: Illegal instruction encountered (0x", exceptionCode, inputFile);
145+
reportCrash("Critical exception: Illegal instruction encountered (0x", exceptionCode, inputFile);
144146
break;
145147

146148
case EXCEPTION_IN_PAGE_ERROR:
147-
reporting("Critical exception: Page fault (0x", exceptionCode, inputFile);
149+
reportCrash("Critical exception: Page fault (0x", exceptionCode, inputFile);
148150
break;
149151

150152
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);
152154
break;
153155

154156
case EXCEPTION_INT_OVERFLOW:
155-
reporting("Critical exception: Integer overflow (0x", exceptionCode, inputFile);
157+
reportCrash("Critical exception: Integer overflow (0x", exceptionCode, inputFile);
156158
break;
157159

158160
case EXCEPTION_STACK_OVERFLOW:
159-
reporting("Critical exception: Stack overflow (0x", exceptionCode, inputFile);
161+
reportCrash("Critical exception: Stack overflow (0x", exceptionCode, inputFile);
160162
break;
161163

162164
default:
@@ -171,30 +173,30 @@ BOOL runTargetProcess(const string& targetApp, const string& inputFile)
171173
STARTUPINFOA si;
172174
PROCESS_INFORMATION pi;
173175
DEBUG_EVENT debug_event;
174-
string arg1 = targetApp.c_str();
176+
const string& arg1 = targetApp;
175177
string arg2 = " ";
176-
string arg3 = inputFile.c_str();
178+
const string& arg3 = inputFile;
177179
string args = arg1 + arg2 + arg3;
178-
LPSTR cmd = (LPSTR)args.c_str();
180+
auto cmd = (LPSTR)args.c_str();
179181

180182
ZeroMemory(&si, sizeof(si));
181183
ZeroMemory(&pi, sizeof(pi));
182184
si.cb = sizeof(si);
183185

184186
if (!CreateProcessA(
185-
NULL, // NULL
187+
nullptr, // NULL
186188
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
189191
TRUE, // Set handle inheritance to FALSE
190192
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
193195
&si, // Pointer to STARTUPINFO structure
194196
&pi) // Pointer to PROCESS_INFORMATION structure
195197
)
196198
{
197-
printf("CreateProcess failed GLE=(%d).\n", GetLastError());
199+
printf("CreateProcess failed GLE=(%lu).\n", GetLastError());
198200
return 1;
199201
}
200202

@@ -215,12 +217,12 @@ BOOL runTargetProcess(const string& targetApp, const string& inputFile)
215217
int _tmain(int argc, char *argv[])
216218
{
217219
// 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"};
221223

222224
// Command line interface logic
223-
CLI::App aplos{"Applos is a simple fuzzer."};
225+
CLI::App aplos{"Aplos is a simple fuzzer."};
224226
argv = aplos.ensure_utf8(argv);
225227

226228
string targetApp, inputs, ext;
@@ -239,8 +241,8 @@ int _tmain(int argc, char *argv[])
239241
CLI11_PARSE(aplos, argc, argv);
240242

241243
// 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{};
244246
localtime_s(&formattedTime, &now);
245247
stringstream timestampStream;
246248
timestampStream << setw(2) << setfill('0') << formattedTime.tm_mday << "_"
@@ -287,10 +289,10 @@ for (int generation = 1;; ++generation)
287289
// Mutating each file with every mutation
288290
for (const string& file : files)
289291
{
290-
for (const string& mut : mylist)
292+
for (const string& mut : mutationArguments)
291293
{
292294
cout << "Mutating file: " << file << " with mutation " << mut << endl;
293-
mutating_inputs(file, mut, inputFolder, outputFolder, ext);
295+
mutateInputs(file, mut, inputFolder, outputFolder, ext);
294296
}
295297
}
296298

0 commit comments

Comments
 (0)