Better logic

This commit is contained in:
quaK 2022-05-28 20:22:00 +03:00
parent 4047857317
commit 9d0ba116c8

View File

@ -42,13 +42,17 @@ launcher::mode detect_mode_from_arguments()
bool apply_aslr_patch(std::string* data) bool apply_aslr_patch(std::string* data)
{ {
if (data->size() < 0x1EE || (data->at(0x1EE) != static_cast<char>(0x60) && data->at(0x1EE) != static_cast<char>(0x20))) // mp binary, sp binary
{ if (data->size() != 0x1B97788 && data->size() != 0x1346D88)
// what the fuck is wrong with this binary data?
return false; return false;
}
data->at(0x1EE) = static_cast<char>(0x20); auto* dos_header = reinterpret_cast<PIMAGE_DOS_HEADER>(&data->at(0));
auto* nt_headers = reinterpret_cast<PIMAGE_NT_HEADERS>(&data->at(dos_header->e_lfanew));
auto* optional_header = &nt_headers->OptionalHeader;
if(optional_header->DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE)
optional_header->DllCharacteristics &= ~(IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE);
return true; return true;
} }
@ -56,19 +60,16 @@ void get_aslr_patched_binary(std::string* binary, std::string* data)
{ {
std::string patched_binary = "h1-mod\\" + *binary; std::string patched_binary = "h1-mod\\" + *binary;
if (!apply_aslr_patch(data)) if (!apply_aslr_patch(data) ||
(!utils::io::file_exists(patched_binary) &&
!utils::io::write_file(patched_binary, *data, false)))
{ {
throw std::runtime_error(utils::string::va( throw std::runtime_error(utils::string::va(
"Could not create aslr patched binary!\n(%s)", "Could not create aslr patched binary!\n(%s)",
binary->data() binary->data()
)); ));
} }
if (!utils::io::file_exists(patched_binary))
{
utils::io::write_file(patched_binary, *data, false);
}
*binary = patched_binary; *binary = patched_binary;
} }