-
-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f6aeb0
commit 7a0dc28
Showing
7 changed files
with
221 additions
and
38 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
set(LIEF_FUZZER_SRC | ||
elf_fuzzer.cpp | ||
pe_fuzzer.cpp | ||
macho_fuzzer.cpp | ||
) | ||
|
||
foreach(fuzzer ${LIEF_FUZZER_SRC}) | ||
string(REGEX REPLACE ".cpp\$" "" output "${fuzzer}") | ||
add_executable("${output}" "${fuzzer}") | ||
add_executable("${output}_shared" "${fuzzer}") | ||
|
||
# Don't use default include dir | ||
set_property(TARGET "${output}" "${output}_shared" PROPERTY INCLUDE_DIRECTORIES "") | ||
|
||
set_property(TARGET "${output}" "${output}_shared" PROPERTY CXX_STANDARD 11) | ||
set_property(TARGET "${output}" "${output}_shared" PROPERTY CXX_STANDARD_REQUIRED ON) | ||
|
||
target_link_libraries("${output}" PUBLIC LIB_LIEF_STATIC) | ||
target_link_libraries("${output}_shared" PUBLIC LIB_LIEF_SHARED) | ||
|
||
endforeach() | ||
|
||
|
||
# Corpus from lief-samples | ||
set(SAMPLES_GIT_URL "https://github.com/lief-project/samples.git" CACHE STRING "URL to tests samples") | ||
set(SAMPLES_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/corpus") | ||
set(SAMPLES_TAG master) | ||
|
||
ExternalProject_Add(lief_fuzzer_corpus | ||
PREFIX ${SAMPLES_PREFIX} | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
GIT_REPOSITORY ${SAMPLES_GIT_URL} | ||
GIT_TAG ${SAMPLES_TAG} | ||
UPDATE_COMMAND ${GIT_EXECUTABLE} pull | ||
) | ||
|
||
ExternalProject_Get_Property(lief_fuzzer_corpus source_dir) | ||
set(LIEF_CORUPUS_DIRECTORY "${source_dir}" CACHE INTERNAL "Path to LIEF samples") | ||
message(STATUS "Samples directory: ${LIEF_CORUPUS_DIRECTORY}") | ||
|
||
|
||
|
||
# ELF | ||
# === | ||
set(ELF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}/elf-output) | ||
|
||
add_custom_target(build-elf-fuzz-output | ||
COMMAND ${CMAKE_COMMAND} -E make_directory ${ELF_WORKING_DIR}) | ||
|
||
add_custom_target("fuzz-elf" | ||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/elf_fuzzer ${LIEF_CORUPUS_DIRECTORY}/ELF -detect_leaks=1 -print_final_stats=1 | ||
DEPENDS elf_fuzzer LIB_LIEF_STATIC build-elf-fuzz-output lief_fuzzer_corpus | ||
WORKING_DIRECTORY ${ELF_WORKING_DIR} | ||
COMMENT "Run ELF fuzzer") | ||
|
||
|
||
# PE | ||
# == | ||
set(PE_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}/pe-output) | ||
|
||
add_custom_target(build-pe-fuzz-output | ||
COMMAND ${CMAKE_COMMAND} -E make_directory ${PE_WORKING_DIR}) | ||
|
||
add_custom_target("fuzz-pe" | ||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/pe_fuzzer ${LIEF_CORUPUS_DIRECTORY}/PE -detect_leaks=1 -print_final_stats=1 | ||
DEPENDS pe_fuzzer LIB_LIEF_STATIC build-pe-fuzz-output lief_fuzzer_corpus | ||
WORKING_DIRECTORY ${PE_WORKING_DIR} | ||
COMMENT "Run PE fuzzer") | ||
|
||
# MachO | ||
# ===== | ||
set(MACHO_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}/macho-output) | ||
|
||
add_custom_target(build-macho-fuzz-output | ||
COMMAND ${CMAKE_COMMAND} -E make_directory ${MACHO_WORKING_DIR}) | ||
|
||
add_custom_target("fuzz-macho" | ||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/macho_fuzzer ${LIEF_CORUPUS_DIRECTORY}/MachO -detect_leaks=1 -print_final_stats=1 | ||
DEPENDS macho_fuzzer LIB_LIEF_STATIC build-macho-fuzz-output lief_fuzzer_corpus | ||
WORKING_DIRECTORY ${MACHO_WORKING_DIR} | ||
COMMENT "Run MachO fuzzer") | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <LIEF/LIEF.hpp> | ||
#include <vector> | ||
#include <memory> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
std::vector<uint8_t> raw = {data, data + size}; | ||
try { | ||
std::unique_ptr<LIEF::ELF::Binary> b{LIEF::ELF::Parser::parse(raw)}; | ||
} catch (const LIEF::exception& e) { | ||
std::cout << e.what() << std::endl; | ||
} | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <LIEF/LIEF.hpp> | ||
#include <vector> | ||
#include <memory> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
std::vector<uint8_t> raw = {data, data + size}; | ||
std::vector<LIEF::MachO::Binary*> binaries; | ||
try { | ||
binaries = LIEF::MachO::Parser::parse(raw); | ||
} catch (const LIEF::exception& e) { | ||
std::cout << e.what() << std::endl; | ||
} | ||
for (LIEF::MachO::Binary* b: binaries) { | ||
delete b; | ||
} | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <LIEF/LIEF.hpp> | ||
#include <vector> | ||
#include <memory> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
std::vector<uint8_t> raw = {data, data + size}; | ||
try { | ||
std::unique_ptr<LIEF::PE::Binary> b{LIEF::PE::Parser::parse(raw)}; | ||
} catch (const LIEF::exception& e) { | ||
std::cout << e.what() << std::endl; | ||
} | ||
return 0; | ||
} |
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