Skip to content

Commit

Permalink
Adds build option to disable the launcher target checksum.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Aug 31, 2021
1 parent 051172a commit 8a6700f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 33 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ if(NOT ${OPTION_CUSTOM_DEBUGGER_TARGET_NAME} STREQUAL " ")
message(STATUS " - Custom debugging target: ${OPTION_CUSTOM_DEBUGGER_TARGET_NAME}")
endif()

option(OPTION_CHECK_TARGET_BINARIES "This option controls if the launcher should check target binaries before injection." ON)


################################################################################
# Some general Windows definitions to keep the MSVC compiler happy with our code.
Expand Down Expand Up @@ -242,6 +244,13 @@ set(TARGET_FTS_SIZE 3457296)
set(TARGET_FTS_ENTRY 0x006B7E21) # Entry point (start).
set(TARGET_FTS_HASH "846F0077129CB390BB206431A63E9246E3D8DA72") # SHA hash

# Debug option for the launcher to skip target checksum.
if (OPTION_CHECK_TARGET_BINARIES)
set(CHECK_TARGET_BINARIES "true")
else()
set(CHECK_TARGET_BINARIES "false")
endif()


################################################################################
# Glob all the headers, source files and include directories.
Expand Down
89 changes: 56 additions & 33 deletions src/hooker/launcher.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@

#define UNSUPPORTED_TARGET "@UNSUPPORTED_TARGET_ERROR@"

/**
* Should we check the target binary checksum before we attempt injection?
*/
const bool CheckTargetBinaries = "@CHECK_TARGET_BINARIES@";

/**
* Define the SHA hash to compare against.
*/
Expand Down Expand Up @@ -401,17 +406,30 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
/**
* Check the target binary exists before we attempt injection.
*/
if (!File_Exists(EXEName)) {
char buff[1024];
std::snprintf(buff, sizeof(buff),
"Unable to find %s!\n\n"
"Please check you have the correct version of " TARGET_NAME " installed\n"
"and that it is up to date " UNSUPPORTED_TARGET ".\n",
EXEName
);
MessageBoxA(NULL, buff, "Error!", MB_OK|MB_ICONEXCLAMATION);
return EXIT_FAILURE;
}
if (CheckTargetBinaries) {
if (!File_Exists(EXEName)) {
char buff[1024];
std::snprintf(buff, sizeof(buff),
"Unable to find %s!\n\n"
"Please check you have the correct version of " TARGET_NAME " installed\n"
"and that it is up to date " UNSUPPORTED_TARGET ".\n",
EXEName
);
MessageBoxA(NULL, buff, "Error!", MB_OK|MB_ICONEXCLAMATION);
return EXIT_FAILURE;
}
} else {
if (!File_Exists(EXEName)) {
char buff[1024];
std::snprintf(buff, sizeof(buff),
"Unable to find %s!\n\n"
"Please check you have the correct version of " TARGET_NAME " installed\n",
EXEName
);
MessageBoxA(NULL, buff, "Error!", MB_OK|MB_ICONEXCLAMATION);
return EXIT_FAILURE;
}
}

/**
* Check the DLL exists before we attempt injection.
Expand Down Expand Up @@ -444,35 +462,40 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
return EXIT_FAILURE;
}

bool matches = false;

/**
* Iterate over all the possible target binaries to check if
* they match one we support.
* Check the target binary checksum before we attempt injection.
*/
for (int i = 0; i < 2; ++i) {

if (CheckTargetBinaries) {
bool matches = false;

/**
* Check the filesize and hash matches first before we attempt injection.
* Iterate over all the possible target binaries to check if
* they match one we support.
*/
if (Get_File_Size(EXEName) == BinarySize[i]) {
if (Check_Hash(EXEName, BinaryHash[i])) {
matches = true;
for (int i = 0; i < 2; ++i) {

/**
* Check the filesize and hash matches first before we attempt injection.
*/
if (Get_File_Size(EXEName) == BinarySize[i]) {
if (Check_Hash(EXEName, BinaryHash[i])) {
matches = true;
}
}
}

}
}

if (!matches) {
char buff[1024];
std::snprintf(buff, sizeof(buff),
"Modified or unsupported version of %s detected!\n\n"
"Please check you have the correct version of " TARGET_NAME " installed\n"
"and that it is up to date " UNSUPPORTED_TARGET ".\n",
EXEName
);
MessageBox(NULL, buff, "Error!", MB_OK|MB_ICONEXCLAMATION);
return EXIT_FAILURE;
if (!matches) {
char buff[1024];
std::snprintf(buff, sizeof(buff),
"Modified or unsupported version of %s detected!\n\n"
"Please check you have the correct version of " TARGET_NAME " installed\n"
"and that it is up to date " UNSUPPORTED_TARGET ".\n",
EXEName
);
MessageBox(NULL, buff, "Error!", MB_OK|MB_ICONEXCLAMATION);
return EXIT_FAILURE;
}
}

/**
Expand Down

0 comments on commit 8a6700f

Please sign in to comment.