2021-02-20 20:59:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
|
2023-05-22 21:14:37 +00:00
|
|
|
* Copyright (c) 2023, Tim Schumacher <timschumi@gmx.de>
|
2021-02-20 20:59:23 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-20 20:59:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibCore/ArgsParser.h>
|
2023-02-09 02:02:46 +00:00
|
|
|
#include <LibCore/File.h>
|
2022-03-28 20:56:14 +00:00
|
|
|
#include <LibMain/Main.h>
|
2021-02-20 20:59:23 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-05-22 22:34:01 +00:00
|
|
|
// TODO: Look into generating this from the authoritative list of fuzzing targets in fuzzer.cmake.
|
2021-02-20 20:59:23 +00:00
|
|
|
#define ENUMERATE_TARGETS(T) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(ASN1) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(BMPLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(Brotli) \
|
|
|
|
T(CSSParser) \
|
|
|
|
T(CyrillicDecoder) \
|
2023-07-17 21:36:08 +00:00
|
|
|
T(DDSLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(DeflateCompression) \
|
|
|
|
T(DeflateDecompression) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(ELF) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(FlacLoader) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(Gemini) \
|
|
|
|
T(GIFLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(GzipCompression) \
|
|
|
|
T(GzipDecompression) \
|
|
|
|
T(HebrewDecoder) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(HttpRequest) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(ICCProfile) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(ICOLoader) \
|
2023-08-03 08:52:44 +00:00
|
|
|
T(ILBMLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(IMAPParser) \
|
2023-02-18 21:09:16 +00:00
|
|
|
T(JPEGLoader) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(Js) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(Latin1Decoder) \
|
|
|
|
T(Latin2Decoder) \
|
|
|
|
T(LzmaDecompression) \
|
|
|
|
T(LzmaRoundtrip) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(Markdown) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(MatroskaReader) \
|
|
|
|
T(MD5) \
|
|
|
|
T(MP3Loader) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(PBMLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(PDF) \
|
|
|
|
T(PEM) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(PGMLoader) \
|
|
|
|
T(PNGLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(Poly1305) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(PPMLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(QOALoader) \
|
2021-12-21 11:11:00 +00:00
|
|
|
T(QOILoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(QuotedPrintableParser) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(RegexECMA262) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(RegexPosixBasic) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(RegexPosixExtended) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(RSAKeyParsing) \
|
|
|
|
T(SHA1) \
|
|
|
|
T(SHA256) \
|
|
|
|
T(SHA384) \
|
|
|
|
T(SHA512) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(Shell) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(ShellPosix) \
|
|
|
|
T(SQLParser) \
|
|
|
|
T(Tar) \
|
|
|
|
T(TGALoader) \
|
2021-02-20 20:59:23 +00:00
|
|
|
T(TTF) \
|
2023-07-17 21:33:53 +00:00
|
|
|
T(TinyVGLoader) \
|
2023-05-22 22:34:01 +00:00
|
|
|
T(URL) \
|
|
|
|
T(UTF16BEDecoder) \
|
|
|
|
T(VP9Decoder) \
|
|
|
|
T(WasmParser) \
|
|
|
|
T(WAVLoader) \
|
|
|
|
T(WebPLoader) \
|
|
|
|
T(WOFF) \
|
|
|
|
T(XML) \
|
|
|
|
T(Zip) \
|
|
|
|
T(ZlibDecompression)
|
2021-02-20 20:59:23 +00:00
|
|
|
|
|
|
|
#undef __ENUMERATE_TARGET
|
2022-04-01 17:58:27 +00:00
|
|
|
#define __ENUMERATE_TARGET(x) extern "C" int Test##x(uint8_t const*, size_t);
|
2021-02-20 20:59:23 +00:00
|
|
|
ENUMERATE_TARGETS(__ENUMERATE_TARGET)
|
|
|
|
#undef __ENUMERATE_TARGET
|
|
|
|
|
2022-03-28 20:56:14 +00:00
|
|
|
static auto parse_target_name(StringView name)
|
2021-02-20 20:59:23 +00:00
|
|
|
{
|
2022-03-28 20:56:14 +00:00
|
|
|
if (name == "list"sv) {
|
2021-02-20 20:59:23 +00:00
|
|
|
outln("The following targets are included:");
|
|
|
|
#undef __ENUMERATE_TARGET
|
|
|
|
#define __ENUMERATE_TARGET(x) outln(#x);
|
|
|
|
ENUMERATE_TARGETS(__ENUMERATE_TARGET)
|
|
|
|
#undef __ENUMERATE_TARGET
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef __ENUMERATE_TARGET
|
|
|
|
#define __ENUMERATE_TARGET(x) \
|
|
|
|
if (name == #x) \
|
|
|
|
return Test##x;
|
|
|
|
ENUMERATE_TARGETS(__ENUMERATE_TARGET)
|
|
|
|
#undef __ENUMERATE_TARGET
|
|
|
|
|
|
|
|
warnln("Unknown fuzzing target \"{}\". Try \"list\" to get a full list.", name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2022-03-28 20:56:14 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2021-02-20 20:59:23 +00:00
|
|
|
{
|
2022-03-28 20:56:14 +00:00
|
|
|
StringView type;
|
|
|
|
StringView filename;
|
2021-02-20 20:59:23 +00:00
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
args_parser.add_positional_argument(type, "Type of fuzzing target to run (use \"list\" to list all existing)", "target-kind");
|
2022-03-28 21:27:12 +00:00
|
|
|
args_parser.add_positional_argument(filename, "Input file", "filename", Core::ArgsParser::Required::No);
|
2022-03-28 20:56:14 +00:00
|
|
|
args_parser.parse(arguments);
|
2021-02-20 20:59:23 +00:00
|
|
|
|
2022-03-28 21:27:12 +00:00
|
|
|
if (arguments.strings.size() <= 2 && arguments.strings[1] != "list"sv) {
|
2023-02-21 11:44:41 +00:00
|
|
|
args_parser.print_usage_terminal(stderr, arguments.strings[0]);
|
2022-03-28 21:27:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-20 20:59:23 +00:00
|
|
|
auto fn = parse_target_name(type);
|
|
|
|
|
2023-02-09 02:02:46 +00:00
|
|
|
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Read));
|
2022-12-11 16:49:00 +00:00
|
|
|
auto input = TRY(file->read_until_eof());
|
2021-02-20 20:59:23 +00:00
|
|
|
|
|
|
|
return fn(input.data(), input.size());
|
|
|
|
}
|