-
-
Save fumfel/c8b3c7e5be700b2303d2e42d957c5990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
clang++ -std=c++11 yara_fuzzer.cc -Iyara/libyara/include/ ./yara/libyara/.libs/libyara.a ./libFuzzer.a -O2 -fno-omit-frame-pointer -g -fsanitize=address -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-gep,trace-div -lcrypto -lssl -o yara_fuzzer | |
*/ | |
#include <stdlib.h> | |
#include <string> | |
#include <yara.h> | |
typedef struct COMPILER_RESULTS | |
{ | |
int errors; | |
int warnings; | |
} COMPILER_RESULTS; | |
int callback( | |
int message, | |
void* message_data, | |
void* user_data) | |
{ | |
return 0; | |
} | |
std::string file_path = "/usr/bin/strings"; | |
int timeout = 1000000; | |
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | |
COMPILER_RESULTS cr; | |
YR_COMPILER* compiler = NULL; | |
YR_RULES* rules = NULL; | |
std::string s(reinterpret_cast<const char *>(Data), Size); | |
yr_initialize(); | |
if (yr_compiler_create(&compiler) != ERROR_SUCCESS){ | |
return 0; | |
} | |
if (yr_compiler_add_string(compiler, s.c_str(), NULL) == 0) | |
{ | |
if (yr_compiler_get_rules(compiler, &rules) == ERROR_SUCCESS) | |
{ | |
yr_rules_scan_file(rules, | |
file_path.c_str(), | |
0, | |
callback, | |
NULL, | |
timeout); | |
} | |
} | |
if(compiler != NULL) { | |
yr_compiler_destroy(compiler); | |
} | |
if(rules != NULL) { | |
yr_rules_destroy(rules); | |
} | |
yr_finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment