More plugin support work
This commit is contained in:
parent
dbbc525174
commit
8ba96904a6
@ -11,8 +11,6 @@ set(Python_FIND_FRAMEWORK NEVER)
|
||||
|
||||
# Find packages
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(GLFW REQUIRED glfw3)
|
||||
pkg_search_module(GLM REQUIRED glm)
|
||||
pkg_search_module(CRYPTO REQUIRED libcrypto)
|
||||
pkg_search_module(CAPSTONE REQUIRED capstone)
|
||||
find_package(OpenGL REQUIRED)
|
||||
@ -20,9 +18,9 @@ find_package(nlohmann_json REQUIRED)
|
||||
find_package(Python COMPONENTS Interpreter Development)
|
||||
|
||||
add_subdirectory(external/llvm/Demangle)
|
||||
add_subdirectory(external/ImGui)
|
||||
add_subdirectory(plugins/libimhex)
|
||||
|
||||
|
||||
if(Python_VERSION LESS 3)
|
||||
message(STATUS ${PYTHON_VERSION_MAJOR_MINOR})
|
||||
message(FATAL_ERROR "No valid version of Python 3 was found.")
|
||||
@ -34,7 +32,7 @@ if(NOT MAGIC_FOUND)
|
||||
endif()
|
||||
|
||||
# Add include directories
|
||||
include_directories(include ${GLFW_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS} ${CRYPTO_INCLUDE_DIRS} ${CAPSTONE_INCLUDE_DIRS} ${MAGIC_INCLUDE_DIRS} ${Python_INCLUDE_DIRS})
|
||||
include_directories(include ${CRYPTO_INCLUDE_DIRS} ${CAPSTONE_INCLUDE_DIRS} ${MAGIC_INCLUDE_DIRS} ${Python_INCLUDE_DIRS})
|
||||
|
||||
# Get Python major and minor
|
||||
string(REPLACE "." ";" PYTHON_VERSION_MAJOR_MINOR ${Python_VERSION})
|
||||
@ -88,7 +86,6 @@ add_executable(imhex
|
||||
source/main.cpp
|
||||
source/window.cpp
|
||||
|
||||
source/helpers/utils.cpp
|
||||
source/helpers/crypto.cpp
|
||||
source/helpers/patches.cpp
|
||||
source/helpers/math_evaluator.cpp
|
||||
@ -123,12 +120,12 @@ add_executable(imhex
|
||||
|
||||
set_target_properties(imhex PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
target_link_directories(imhex PRIVATE ${GLFW_LIBRARY_DIRS} ${CRYPTO_LIBRARY_DIRS} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS})
|
||||
target_link_directories(imhex PRIVATE ${CRYPTO_LIBRARY_DIRS} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS})
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(imhex libglfw3.a libgcc.a libstdc++.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a shlwapi.lib libcrypto.a libwinpthread.a libcapstone.a LLVMDemangle imgui libimhex ${Python_LIBRARIES} nlohmann_json::nlohmann_json dl)
|
||||
target_link_libraries(imhex libgcc.a libstdc++.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a shlwapi.lib libcrypto.a libwinpthread.a libcapstone.a LLVMDemangle imgui libimhex ${Python_LIBRARIES} nlohmann_json::nlohmann_json dl)
|
||||
elseif (UNIX)
|
||||
target_link_libraries(imhex glfw magic crypto ${CMAKE_DL_LIBS} capstone LLVMDemangle imgui libimhex ${Python_LIBRARIES} nlohmann_json::nlohmann_json dl)
|
||||
target_link_libraries(imhex magic crypto ${CMAKE_DL_LIBS} capstone LLVMDemangle imgui libimhex ${Python_LIBRARIES} nlohmann_json::nlohmann_json dl)
|
||||
endif()
|
||||
|
||||
install(TARGETS imhex DESTINATION bin)
|
||||
|
8
external/ImGui/CMakeLists.txt
vendored
8
external/ImGui/CMakeLists.txt
vendored
@ -5,6 +5,7 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Freetype REQUIRED)
|
||||
pkg_search_module(GLM REQUIRED glm)
|
||||
pkg_search_module(GLFW REQUIRED glfw3)
|
||||
|
||||
add_library(imgui
|
||||
@ -23,13 +24,12 @@ add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../glad ${CMAKE_CURRENT_BINARY_DIR}/external/glad)
|
||||
|
||||
target_include_directories(imgui PUBLIC include)
|
||||
target_include_directories(imgui PRIVATE ${FREETYPE_INCLUDE_DIRS} ${GLFW_INCLUDE_DIRS})
|
||||
target_include_directories(imgui PUBLIC include ${FREETYPE_INCLUDE_DIRS} ${GLFW_INCLUDE_DIRS})
|
||||
|
||||
target_link_directories(imgui PRIVATE ${GLFW_LIBRARY_DIRS})
|
||||
target_link_directories(imgui PUBLIC ${GLM_INCLUDE_DIRS} ${GLFW_LIBRARY_DIRS})
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(imgui Freetype::Freetype glad libglfw3.a)
|
||||
elseif (UNIX)
|
||||
target_link_libraries(imgui Freetype::Freetype glad glfw)
|
||||
target_link_libraries(imgui Freetype::Freetype glad glfw3)
|
||||
endif()
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <string_view>
|
||||
|
||||
#include "patches.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "helpers/utils.hpp"
|
||||
|
||||
namespace hex {
|
||||
|
||||
|
@ -3,8 +3,10 @@ project(example)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/ImGui ${CMAKE_CURRENT_BINARY_DIR}/external/ImGui)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
|
||||
if (TARGET ${CMAKE_PROJECT_NAME})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/ImGui ${CMAKE_CURRENT_BINARY_DIR}/external/ImGui)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
|
||||
endif()
|
||||
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "plugin")
|
||||
|
||||
@ -13,4 +15,4 @@ add_library(example SHARED
|
||||
)
|
||||
|
||||
target_include_directories(example PUBLIC include)
|
||||
target_link_libraries(example imgui libimhex)
|
||||
target_link_libraries(example PRIVATE imgui libimhex)
|
||||
|
@ -3,17 +3,18 @@ project(libimhex)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
if (TARGET libimhex)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/ImGui ${CMAKE_CURRENT_BINARY_DIR}/external/ImGui)
|
||||
endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/ImGui ${CMAKE_CURRENT_BINARY_DIR}/external/ImGui)
|
||||
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "")
|
||||
|
||||
add_library(libimhex STATIC
|
||||
source/helpers/event.cpp
|
||||
source/helpers/utils.cpp
|
||||
|
||||
source/providers/provider.cpp
|
||||
|
||||
source/views/view.cpp
|
||||
)
|
||||
)
|
||||
|
||||
target_include_directories(libimhex PUBLIC include)
|
||||
target_link_libraries(libimhex PRIVATE imgui)
|
||||
|
137
plugins/libimhex/include/helpers/utils.hpp
Normal file
137
plugins/libimhex/include/helpers/utils.hpp
Normal file
@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
|
||||
#define TOKEN_CONCAT_IMPL(x, y) x ## y
|
||||
#define TOKEN_CONCAT(x, y) TOKEN_CONCAT_IMPL(x, y)
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define off64_t off_t
|
||||
#define fopen64 fopen
|
||||
#define fseeko64 fseek
|
||||
#define ftello64 ftell
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <winsock.h>
|
||||
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
namespace hex {
|
||||
|
||||
template<typename ... Args>
|
||||
inline std::string format(const char *format, Args ... args) {
|
||||
ssize_t size = snprintf( nullptr, 0, format, args ... );
|
||||
|
||||
if (size <= 0)
|
||||
return "";
|
||||
|
||||
std::vector<char> buffer(size + 1, 0x00);
|
||||
snprintf(buffer.data(), size + 1, format, args ...);
|
||||
|
||||
return std::string(buffer.data(), buffer.data() + size);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr inline u64 extract(u8 from, u8 to, const hex::unsigned_integral auto &value) {
|
||||
std::remove_cvref_t<decltype(value)> mask = (std::numeric_limits<std::remove_cvref_t<decltype(value)>>::max() >> (((sizeof(value) * 8) - 1) - (from - to))) << to;
|
||||
return (value & mask) >> to;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr inline u64 signExtend(u64 value, u8 currWidth, u8 targetWidth) {
|
||||
u64 mask = 1LLU << (currWidth - 1);
|
||||
return (((value ^ mask) - mask) << (64 - targetWidth)) >> (64 - targetWidth);
|
||||
}
|
||||
|
||||
std::string toByteString(u64 bytes);
|
||||
std::string makePrintable(char c);
|
||||
|
||||
template<typename T>
|
||||
struct always_false : std::false_type {};
|
||||
|
||||
template<typename T>
|
||||
constexpr T changeEndianess(T value, std::endian endian) {
|
||||
if (endian == std::endian::native)
|
||||
return value;
|
||||
|
||||
if constexpr (sizeof(T) == 1)
|
||||
return value;
|
||||
else if constexpr (sizeof(T) == 2)
|
||||
return __builtin_bswap16(value);
|
||||
else if constexpr (sizeof(T) == 4)
|
||||
return __builtin_bswap32(value);
|
||||
else if constexpr (sizeof(T) == 8)
|
||||
return __builtin_bswap64(value);
|
||||
else
|
||||
static_assert(always_false<T>::value, "Invalid type provided!");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T changeEndianess(T value, size_t size, std::endian endian) {
|
||||
if (endian == std::endian::native)
|
||||
return value;
|
||||
|
||||
if (size == 1)
|
||||
return value;
|
||||
else if (size == 2)
|
||||
return __builtin_bswap16(value);
|
||||
else if (size == 4)
|
||||
return __builtin_bswap32(value);
|
||||
else if (size == 8)
|
||||
return __builtin_bswap64(value);
|
||||
else
|
||||
throw std::invalid_argument("Invalid value size!");
|
||||
}
|
||||
|
||||
template< class T >
|
||||
constexpr T bit_width(T x) noexcept {
|
||||
return std::numeric_limits<T>::digits - std::countl_zero(x);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T bit_ceil(T x) noexcept {
|
||||
if (x <= 1u)
|
||||
return T(1);
|
||||
|
||||
return T(1) << bit_width(T(x - 1));
|
||||
}
|
||||
|
||||
std::vector<u8> readFile(std::string_view path);
|
||||
|
||||
#define SCOPE_EXIT(func) ScopeExit TOKEN_CONCAT(scopeGuard, __COUNTER__)([&] { func })
|
||||
class ScopeExit {
|
||||
public:
|
||||
ScopeExit(std::function<void()> func) : m_func(std::move(func)) {}
|
||||
~ScopeExit() { if (!this->m_released) this->m_func(); }
|
||||
|
||||
void release() {
|
||||
this->m_released = true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_released = false;
|
||||
std::function<void()> m_func;
|
||||
};
|
||||
|
||||
struct Region {
|
||||
u64 address;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct Bookmark {
|
||||
Region region;
|
||||
|
||||
std::vector<char> name;
|
||||
std::vector<char> comment;
|
||||
};
|
||||
}
|
@ -20,6 +20,7 @@ extern char **mainArgv;
|
||||
|
||||
#define IMHEX_PLUGIN namespace hex::plugin::internal { \
|
||||
void setImGuiContext(ImGuiContext *ctx) { \
|
||||
gladLoadGL(); \
|
||||
ImGui::SetCurrentContext(ctx); \
|
||||
} \
|
||||
} \
|
||||
|
Loading…
Reference in New Issue
Block a user