mirror of
https://github.com/QuasarApp/pe-parse.git
synced 2025-04-26 04:14:32 +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)
|
||||
project(peaddrconv)
|
||||
|
||||
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Default install directory" FORCE)
|
||||
endif ()
|
||||
|
||||
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")
|
||||
list(APPEND PEADDRCONV_CXXFLAGS /Zi)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
list(APPEND PEADDRCONV_CXXFLAGS /WX)
|
||||
endif ()
|
||||
|
||||
else ()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
@ -33,7 +39,7 @@ find_package(peparse REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
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})
|
||||
|
||||
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 <limits>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
@ -28,10 +29,10 @@ enum class AddressType {
|
||||
};
|
||||
|
||||
bool convertAddress(ParsedPeRef &pe,
|
||||
std::uintptr_t address,
|
||||
std::uint64_t address,
|
||||
AddressType source_type,
|
||||
AddressType destination_type,
|
||||
std::uintptr_t &result) noexcept {
|
||||
std::uint64_t &result) noexcept {
|
||||
if (source_type == destination_type) {
|
||||
result = address;
|
||||
return true;
|
||||
@ -107,8 +108,8 @@ bool convertAddress(ParsedPeRef &pe,
|
||||
if (destination_type == AddressType::RelativeVirtualAddress) {
|
||||
struct CallbackData final {
|
||||
bool found;
|
||||
std::uintptr_t address;
|
||||
std::uintptr_t result;
|
||||
std::uint64_t address;
|
||||
std::uint64_t result;
|
||||
};
|
||||
|
||||
auto L_inspectSection = [](void *N,
|
||||
@ -153,7 +154,7 @@ bool convertAddress(ParsedPeRef &pe,
|
||||
return true;
|
||||
|
||||
} else if (destination_type == AddressType::VirtualAddress) {
|
||||
std::uintptr_t rva = 0U;
|
||||
std::uint64_t rva = 0U;
|
||||
if (!convertAddress(pe,
|
||||
address,
|
||||
source_type,
|
||||
@ -180,8 +181,8 @@ bool convertAddress(ParsedPeRef &pe,
|
||||
if (destination_type == AddressType::PhysicalOffset) {
|
||||
struct CallbackData final {
|
||||
bool found;
|
||||
std::uintptr_t address;
|
||||
std::uintptr_t result;
|
||||
std::uint64_t address;
|
||||
std::uint64_t result;
|
||||
};
|
||||
|
||||
auto L_inspectSection = [](void *N,
|
||||
@ -234,7 +235,7 @@ bool convertAddress(ParsedPeRef &pe,
|
||||
return false;
|
||||
}
|
||||
|
||||
std::uintptr_t rva = address - image_base_address;
|
||||
std::uint64_t rva = address - image_base_address;
|
||||
return convertAddress(pe,
|
||||
rva,
|
||||
AddressType::RelativeVirtualAddress,
|
||||
@ -261,7 +262,7 @@ int main(int argc, char *argv[]) {
|
||||
char *last_parsed_char = nullptr;
|
||||
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) {
|
||||
std::cout << "Invalid address specified\n";
|
||||
return 1;
|
||||
@ -293,7 +294,7 @@ int main(int argc, char *argv[]) {
|
||||
<< "\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 << " to rva:\t";
|
||||
|
Loading…
x
Reference in New Issue
Block a user