Skip to content

Commit

Permalink
Dummy patch dll to start things rolling.
Browse files Browse the repository at this point in the history
  • Loading branch information
nemerle committed Nov 15, 2017
1 parent 949acc6 commit 5ccad3c
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ out/
*.lai
*.la
*.a
*.lib

# Library generated exports
*.exp
1 change: 1 addition & 0 deletions Projects/CoX/Clients/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Client_I0)
19 changes: 19 additions & 0 deletions Projects/CoX/Clients/Client_I0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
LINK_DIRECTORIES(../patch_tools)
set (CMAKE_CXX_STANDARD 17)
if (MSVC_VERSION GREATER_EQUAL "1900")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported)
if (_cpp_latest_flag_supported)
add_compile_options("/std:c++latest")
endif()
endif()
set(SOURCES
utils/dll_patcher.cpp
patch_all_the_things.cpp
dll_core.cpp
)
add_library(cohdll SHARED ${SOURCES})
# we link to the imp lib for the exe
target_link_libraries(cohdll CityOfPatches)
# enforce the dll prefix.
SET_TARGET_PROPERTIES(cohdll PROPERTIES PREFIX "lib")
35 changes: 35 additions & 0 deletions Projects/CoX/Clients/Client_I0/dll_core.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "patch_all_the_things.h"

#include <stdio.h>
#include <windows.h>

HMODULE coh_instance;
extern "C" {
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {

switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
printf ("CoH Patch dll loaded\n");
coh_instance = GetModuleHandle(nullptr);
patch_all_the_things();
break;

case DLL_PROCESS_DETACH:
printf ("Unload working...\n");
break;

case DLL_THREAD_ATTACH:
printf ("Thread attach ???\n");
break;

case DLL_THREAD_DETACH:
printf ("Thread detach ??\n");
break;
}
return TRUE;
}
__declspec(dllexport) int test() {
return 0;
}
}
7 changes: 7 additions & 0 deletions Projects/CoX/Clients/Client_I0/patch_all_the_things.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "patch_all_the_things.h"
#include "utils/dll_patcher.h"
// extern patch_named_module()
void patch_all_the_things()
{
//patch_named_module()
}
28 changes: 28 additions & 0 deletions Projects/CoX/Clients/Client_I0/utils/dll_patcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "dll_patcher.h"

#include <stdio.h>
#include <stdint.h>
#include <windows.h>
#include <cassert>
void break_me()
{
assert(false);
}

extern HMODULE coh_instance;
void patchit(const char *tgt,void *proc)
{
uint8_t *addr = (uint8_t *)GetProcAddress(coh_instance,tgt);
DWORD offset = ((DWORD)proc - (DWORD)addr - 5);
if(addr)
{
*addr = 0xE9; // write JMP
*(DWORD *)(addr+1) = (DWORD)offset; // write target offset
printf("Patched %s\n",tgt);
}
else
{
printf("Couldn't patch %s\n",tgt);
abort();
}
}

0 comments on commit 5ccad3c

Please sign in to comment.