diff --git a/CMakeLists.txt b/CMakeLists.txt index a47624b..e457ff2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,22 @@ cmake_minimum_required(VERSION 3.16) -set (CMAKE_SYSTEM_NAME Windows) +# Common stuff + +# You might need to adjust this +set(MINGW_PATH /usr/x86_64-w64-mingw32) + +set(SHLWAPI_PATH ${MINGW_PATH}/mingw/lib/libshlwapi.a) +set(WINPTHREAD_PATH ${MINGW_PATH}/usr/lib/libwinpthread.a) + +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) # Injected library project(mhynot2 VERSION 1.0.0 DESCRIPTION "mhyprot2 user-mode emulator") +add_compile_definitions(mhynot2 UNICODE) + add_library(mhynot2 SHARED mhynot2-rewritten/Common.cpp mhynot2-rewritten/dllmain.cpp @@ -16,17 +27,23 @@ add_library(mhynot2 SHARED mhynot2-rewritten/PassthroughBackend.cpp ) -target_compile_features(mhynot2 PRIVATE cxx_std_17) +# Really hacky way, but I wasn't able to figure a better one +#set_target_properties(mhynot2 PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(mhynot2 PROPERTIES VERSION dll) +set_target_properties(mhynot2 PROPERTIES PREFIX "") +#set_target_properties(mhynot2 PROPERTIES SUFFIX .dll) +set_target_properties(mhynot2 PROPERTIES SUFFIX "") + +set_target_properties(mhynot2 PROPERTIES SOVERSION 1) -add_subdirectory(minhook) -target_compile_definitions(mhynot2 PRIVATE UNICODE) target_include_directories(mhynot2 PRIVATE mhynot2-rewritten) -target_link_libraries(mhynot2 minhook shlwapi) +target_include_directories(mhynot2 PRIVATE minhook/include) + +target_link_libraries(mhynot2 ${CMAKE_SOURCE_DIR}/minhook/libMinHook.a) +target_link_libraries(mhynot2 ${SHLWAPI_PATH}) +target_link_libraries(mhynot2 ${WINPTHREAD_PATH}) -if (MINGW) - target_link_libraries(mhynot2 winpthread) - target_link_options(mhynot2 PRIVATE -static-libgcc -static-libstdc++ -static) -endif() +target_link_options(mhynot2 PRIVATE -static-libgcc -static-libstdc++) # Launcher executable @@ -36,4 +53,4 @@ add_executable(launcher WIN32 launcher/launcher.cpp ) -target_link_libraries(launcher shlwapi) +target_link_libraries(launcher ${SHLWAPI_PATH}) diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index c506f11..db96770 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -6,6 +6,7 @@ int inject_library(HANDLE hProcess, const char* dll) { auto loadlibrary = LoadLibraryA; // i actually had no idea that the address of kernel32 is the same between all processes auto mem = VirtualAllocEx(hProcess, NULL, strlen(dll) + 1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + printf("Injecting library %s\n", dll); printf("LoadLibraryA %p\n", loadlibrary); printf("allocated path addr %p\n", mem); if (!mem) { @@ -30,7 +31,13 @@ int inject_library(HANDLE hProcess, const char* dll) printf("waiting for the dll loading thread to exit\n"); WaitForSingleObject(new_thread, INFINITE); - printf("looks like the dll injected properly\n"); + + DWORD ExitCode = 0; + if (GetExitCodeThread(new_thread, &ExitCode) == 0) { + printf("Loading thread EPIC FAIL: code %d, GLE 0x%x\n", ExitCode, GetLastError()); + } else { + printf("looks like the dll injected properly\n"); + } VirtualFreeEx(hProcess, mem, 0, MEM_RELEASE);