Skip to content

Commit 94bd12a

Browse files
authored
Fix peaddrconv example compilation failure (#158)
Add option to build examples with main CMake. Build examples in CI now. Add target alias with prefix for main pe-parse library.
1 parent 41a08eb commit 94bd12a

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
6565
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
6666
-DPEPARSE_ENABLE_TESTING=ON \
67+
-DPEPARSE_ENABLE_EXAMPLES=ON \
6768
${SANITIZER_FLAG} \
6869
..
6970
cmake --build .
@@ -126,6 +127,7 @@ jobs:
126127
-A ${{ matrix.build-arch }} `
127128
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} `
128129
-DPEPARSE_ENABLE_TESTING=ON `
130+
-DPEPARSE_ENABLE_EXAMPLES=ON `
129131
$Env:SANITIZER_FLAG `
130132
..
131133
cmake --build . --config ${{ matrix.build-type }}

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ message(STATUS "Build Shared: ${BUILD_SHARED_LIBS} ${BUILD_SHARED_LIBS_MESSAGE}"
6464
message(STATUS "Build Command Line Tools: ${BUILD_COMMAND_LINE_TOOLS}")
6565
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
6666

67+
option(PEPARSE_ENABLE_EXAMPLES "Enable building examples" OFF)
68+
if (PEPARSE_ENABLE_EXAMPLES)
69+
message(STATUS "Building Examples")
70+
add_subdirectory(examples)
71+
endif()
72+
6773
option(PEPARSE_ENABLE_TESTING "Enable building tests" OFF)
6874
if (PEPARSE_ENABLE_TESTING)
6975
enable_testing()

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ You can build the (catch2-based) tests by adding `-DPEPARSE_ENABLE_TESTING=ON` d
9494

9595
To run the full test suite with the [Corkami test suite](https://github.com/corkami/pocs/tree/master/PE), you must clone the submodule with `git submodule update --init`.
9696

97+
## Examples
98+
99+
You can build the included examples by adding `-DPEPARSE_ENABLE_EXAMPLES=ON` during CMake configuration.
100+
97101
## Building with Sanitizers
98102

99103
If you are familiar with C++ sanitizers and any specific development environment requirements for them (compiler, instrumented standard library, etc.), you can choose to compile with any of the following sanitizers: `Address`, `HWAddress`, `Undefined`, `Memory`, `MemoryWithOrigins`, `Leak`, `Address,Undefined`.

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(peaddrconv)

examples/peaddrconv/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
22
project(peaddrconv)
33

44
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
5-
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Default install directory" FORCE)
5+
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Default install directory" FORCE)
66
endif ()
77

88
if (MSVC)
@@ -35,7 +35,9 @@ else ()
3535
endif ()
3636
endif ()
3737

38-
find_package(pe-parse REQUIRED)
38+
if (NOT TARGET pe-parse::pe-parse)
39+
find_package(pe-parse REQUIRED)
40+
endif()
3941

4042
add_executable(${PROJECT_NAME} main.cpp)
4143
target_link_libraries(${PROJECT_NAME} pe-parse::pe-parse)

examples/peaddrconv/main.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ bool convertAddress(ParsedPeRef &pe,
5353
std::uintptr_t highest_offset;
5454
};
5555

56-
auto L_getSectionAddressLimits = [](void *N,
57-
peparse::VA secBase,
58-
std::string &secName,
59-
peparse::image_section_header s,
60-
peparse::bounded_buffer *data) -> int {
56+
auto L_getSectionAddressLimits =
57+
[](void *N,
58+
const peparse::VA &secBase,
59+
const std::string &secName,
60+
const peparse::image_section_header &s,
61+
const peparse::bounded_buffer *data) -> int {
6162
static_cast<void>(secBase);
6263
static_cast<void>(secName);
6364
static_cast<void>(data);
@@ -113,10 +114,10 @@ bool convertAddress(ParsedPeRef &pe,
113114
};
114115

115116
auto L_inspectSection = [](void *N,
116-
peparse::VA secBase,
117-
std::string &secName,
118-
peparse::image_section_header s,
119-
peparse::bounded_buffer *data) -> int {
117+
const peparse::VA &secBase,
118+
const std::string &secName,
119+
const peparse::image_section_header &s,
120+
const peparse::bounded_buffer *data) -> int {
120121
static_cast<void>(secBase);
121122
static_cast<void>(secName);
122123
static_cast<void>(data);
@@ -186,10 +187,10 @@ bool convertAddress(ParsedPeRef &pe,
186187
};
187188

188189
auto L_inspectSection = [](void *N,
189-
peparse::VA secBase,
190-
std::string &secName,
191-
peparse::image_section_header s,
192-
peparse::bounded_buffer *data) -> int {
190+
const peparse::VA &secBase,
191+
const std::string &secName,
192+
const peparse::image_section_header &s,
193+
const peparse::bounded_buffer *data) -> int {
193194
static_cast<void>(secBase);
194195
static_cast<void>(secName);
195196
static_cast<void>(data);

pe-parser-library/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ else()
2525
endif()
2626

2727
add_library(${PROJECT_NAME} ${PEPARSERLIB_SOURCEFILES})
28+
add_library(pe-parse::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
2829

2930
if(PEPARSE_LIBRARY_WARNINGS)
3031
target_compile_definitions(${PROJECT_NAME} PRIVATE PEPARSE_LIBRARY_WARNINGS=1)

0 commit comments

Comments
 (0)