Skip to content

Instantly share code, notes, and snippets.

@fumfel
Created June 7, 2017 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumfel/c8b3c7e5be700b2303d2e42d957c5990 to your computer and use it in GitHub Desktop.
Save fumfel/c8b3c7e5be700b2303d2e42d957c5990 to your computer and use it in GitHub Desktop.
/*
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