diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f4c207..1242058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,5 +5,10 @@ project(nekohack) set(CMAKE_CXX_STANDARD 17) file(GLOB_RECURSE NEKOHACK_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") add_library(nekohack STATIC ${NEKOHACK_SOURCES}) -target_include_directories(nekohack PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/break") +target_include_directories(nekohack PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/hack") target_include_directories(nekohack PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/") + +add_library(nekohack-dummy SHARED "${CMAKE_CURRENT_SOURCE_DIR}/example/dummy.cpp") +add_executable(nekohack-example "${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp") +target_include_directories(nekohack-example PRIVATE nekohack) +target_link_libraries(nekohack-example PRIVATE nekohack nekohack-dummy dl) diff --git a/example/dummy.cpp b/example/dummy.cpp new file mode 100644 index 0000000..3abcaf3 --- /dev/null +++ b/example/dummy.cpp @@ -0,0 +1,8 @@ + +extern "C" { + +int GetInt() { + return 5; +} + +} diff --git a/example/main.cpp b/example/main.cpp new file mode 100644 index 0000000..74f548a --- /dev/null +++ b/example/main.cpp @@ -0,0 +1,15 @@ + +#include +#include +using namespace neko; + +int main() { + hack::SharedLibrary dummysl("libnekohack-dummy"); + std::cout << "Lmap: " << dummysl.GetLMap() << std::endl; + + using GetInt_f = int (*)(); + GetInt_f GetInt = dummysl.GetSym("GetInt"); + std::cout << "GetInt Location: " << std::hex << GetInt << std::endl; + std::cout << "GetInt: " << GetInt() << std::endl; + +} diff --git a/include/hack/sharedlibrary.hpp b/include/hack/sharedlibrary.hpp index 912396c..9a1f4ae 100644 --- a/include/hack/sharedlibrary.hpp +++ b/include/hack/sharedlibrary.hpp @@ -50,7 +50,7 @@ public: void Clear(); LMap GetLMap(); template - T GetSym(SymStr s) { reinterpret_cast(this->GetSymInternal(s)); } + T GetSym(SymStr s) { return reinterpret_cast(this->GetSymInternal(s)); } private: void* GetSymInternal(SymStr); bool init_flag = false; diff --git a/src/sharedlibrary.cpp b/src/sharedlibrary.cpp index 3bf4b8f..c0c1d17 100644 --- a/src/sharedlibrary.cpp +++ b/src/sharedlibrary.cpp @@ -18,7 +18,7 @@ */ #include - +#include #include "memory.hpp" #include "sharedlibrary.hpp" @@ -47,6 +47,7 @@ void SharedLibrary::Init(std::string_view _name){ Passthrough pass; pass.name = '/' + std::string(_name) + '.'; if (!dl_iterate_phdr([](struct dl_phdr_info* info, size_t, void* _pass) { + std::cout << "Lib: " << info->dlpi_name << std::endl; auto* pass = reinterpret_cast(_pass); if (!strstr(info->dlpi_name, pass->name.c_str())) return 0;