mirror of
https://github.com/QuasarApp/pe-parse.git
synced 2025-05-02 07:09:34 +00:00
Fix Windows build and VS2017 compiler errors for example project (#70)
This commit is contained in:
parent
6fa093aa42
commit
11685390bb
@ -1,17 +1,23 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1)
|
||||||
project(peaddrconv)
|
project(peaddrconv)
|
||||||
|
|
||||||
|
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||||
|
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Default install directory" FORCE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
list(APPEND PEADDRCONV_CXXFLAGS /W4 /analyze)
|
# Default CMAKE_PREFIX_PATH is empty and CMAKE_SYSTEM_PREFIX_PATH is
|
||||||
|
# set to a list of Program Files directories, which is a problem because
|
||||||
|
# pe-parser-library (by default) installs itself to `%SystemDrive%\usr`
|
||||||
|
# directory on Windows its not found by CMake when performing its search.
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH /usr/lib/cmake)
|
||||||
|
|
||||||
|
list(APPEND PEADDRCONV_CXXFLAGS /W4 /WX /analyze)
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||||
list(APPEND PEADDRCONV_CXXFLAGS /Zi)
|
list(APPEND PEADDRCONV_CXXFLAGS /Zi)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
|
||||||
list(APPEND PEADDRCONV_CXXFLAGS /WX)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
else ()
|
else ()
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
@ -33,7 +39,7 @@ find_package(peparse REQUIRED)
|
|||||||
|
|
||||||
add_executable(${PROJECT_NAME} main.cpp)
|
add_executable(${PROJECT_NAME} main.cpp)
|
||||||
target_link_libraries(${PROJECT_NAME} ${PEPARSE_LIBRARIES})
|
target_link_libraries(${PROJECT_NAME} ${PEPARSE_LIBRARIES})
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${PEPARSE_INCLUDE_DIRS})
|
target_include_directories(${PROJECT_NAME} PRIVATE ${PEPARSE_INCLUDE_DIR})
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE ${PEADDRCONV_CXXFLAGS})
|
target_compile_options(${PROJECT_NAME} PRIVATE ${PEADDRCONV_CXXFLAGS})
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME} DESTINATION "bin")
|
install(TARGETS ${PROJECT_NAME} DESTINATION "bin")
|
||||||
|
@ -1 +1,3 @@
|
|||||||
Note that you have to install the library before you can build this example!
|
Note that you have to install the library before you can build this example,
|
||||||
|
which is done by running `cmake --build . --config Release --target install`
|
||||||
|
(noted as optional in the library [README](../../README.md#building)).
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -28,10 +29,10 @@ enum class AddressType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool convertAddress(ParsedPeRef &pe,
|
bool convertAddress(ParsedPeRef &pe,
|
||||||
std::uintptr_t address,
|
std::uint64_t address,
|
||||||
AddressType source_type,
|
AddressType source_type,
|
||||||
AddressType destination_type,
|
AddressType destination_type,
|
||||||
std::uintptr_t &result) noexcept {
|
std::uint64_t &result) noexcept {
|
||||||
if (source_type == destination_type) {
|
if (source_type == destination_type) {
|
||||||
result = address;
|
result = address;
|
||||||
return true;
|
return true;
|
||||||
@ -107,8 +108,8 @@ bool convertAddress(ParsedPeRef &pe,
|
|||||||
if (destination_type == AddressType::RelativeVirtualAddress) {
|
if (destination_type == AddressType::RelativeVirtualAddress) {
|
||||||
struct CallbackData final {
|
struct CallbackData final {
|
||||||
bool found;
|
bool found;
|
||||||
std::uintptr_t address;
|
std::uint64_t address;
|
||||||
std::uintptr_t result;
|
std::uint64_t result;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto L_inspectSection = [](void *N,
|
auto L_inspectSection = [](void *N,
|
||||||
@ -153,7 +154,7 @@ bool convertAddress(ParsedPeRef &pe,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (destination_type == AddressType::VirtualAddress) {
|
} else if (destination_type == AddressType::VirtualAddress) {
|
||||||
std::uintptr_t rva = 0U;
|
std::uint64_t rva = 0U;
|
||||||
if (!convertAddress(pe,
|
if (!convertAddress(pe,
|
||||||
address,
|
address,
|
||||||
source_type,
|
source_type,
|
||||||
@ -180,8 +181,8 @@ bool convertAddress(ParsedPeRef &pe,
|
|||||||
if (destination_type == AddressType::PhysicalOffset) {
|
if (destination_type == AddressType::PhysicalOffset) {
|
||||||
struct CallbackData final {
|
struct CallbackData final {
|
||||||
bool found;
|
bool found;
|
||||||
std::uintptr_t address;
|
std::uint64_t address;
|
||||||
std::uintptr_t result;
|
std::uint64_t result;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto L_inspectSection = [](void *N,
|
auto L_inspectSection = [](void *N,
|
||||||
@ -234,7 +235,7 @@ bool convertAddress(ParsedPeRef &pe,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uintptr_t rva = address - image_base_address;
|
std::uint64_t rva = address - image_base_address;
|
||||||
return convertAddress(pe,
|
return convertAddress(pe,
|
||||||
rva,
|
rva,
|
||||||
AddressType::RelativeVirtualAddress,
|
AddressType::RelativeVirtualAddress,
|
||||||
@ -261,7 +262,7 @@ int main(int argc, char *argv[]) {
|
|||||||
char *last_parsed_char = nullptr;
|
char *last_parsed_char = nullptr;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
auto address = std::strtoull(address_as_string, &last_parsed_char, 16);
|
std::uint64_t address = std::strtoull(address_as_string, &last_parsed_char, 16);
|
||||||
if (address == 0U && *last_parsed_char != 0) {
|
if (address == 0U && *last_parsed_char != 0) {
|
||||||
std::cout << "Invalid address specified\n";
|
std::cout << "Invalid address specified\n";
|
||||||
return 1;
|
return 1;
|
||||||
@ -293,7 +294,7 @@ int main(int argc, char *argv[]) {
|
|||||||
<< "\n";
|
<< "\n";
|
||||||
std::cout << "Converting address 0x" << std::hex << address << "...\n\n";
|
std::cout << "Converting address 0x" << std::hex << address << "...\n\n";
|
||||||
|
|
||||||
std::uintptr_t result = 0U;
|
std::uint64_t result = 0U;
|
||||||
|
|
||||||
std::cout << "as Physical offset (off)\n";
|
std::cout << "as Physical offset (off)\n";
|
||||||
std::cout << " to rva:\t";
|
std::cout << " to rva:\t";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user