Fixed shared library + added example
This commit is contained in:
parent
b01c33e401
commit
4dd5814b91
@ -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)
|
||||
|
8
example/dummy.cpp
Normal file
8
example/dummy.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
int GetInt() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
}
|
15
example/main.cpp
Normal file
15
example/main.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <hack/sharedlibrary.hpp>
|
||||
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_f>("GetInt");
|
||||
std::cout << "GetInt Location: " << std::hex << GetInt << std::endl;
|
||||
std::cout << "GetInt: " << GetInt() << std::endl;
|
||||
|
||||
}
|
@ -50,7 +50,7 @@ public:
|
||||
void Clear();
|
||||
LMap GetLMap();
|
||||
template<typename T>
|
||||
T GetSym(SymStr s) { reinterpret_cast<T>(this->GetSymInternal(s)); }
|
||||
T GetSym(SymStr s) { return reinterpret_cast<T>(this->GetSymInternal(s)); }
|
||||
private:
|
||||
void* GetSymInternal(SymStr);
|
||||
bool init_flag = false;
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <iostream>
|
||||
#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<Passthrough*>(_pass);
|
||||
if (!strstr(info->dlpi_name, pass->name.c_str()))
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user