Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't break something that was working #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -36,4 +53,4 @@ add_executable(launcher WIN32
launcher/launcher.cpp
)

target_link_libraries(launcher shlwapi)
target_link_libraries(launcher ${SHLWAPI_PATH})
9 changes: 8 additions & 1 deletion launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down