fix qt/sdl

This commit is contained in:
DanielSvoboda 2025-02-18 18:38:28 -03:00
parent 2d32c27101
commit cba79b8359

View File

@ -388,11 +388,7 @@ void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valu
} }
if (patchMask == PatchMask::Mask_Jump32) { if (patchMask == PatchMask::Mask_Jump32) {
QString valuePart = QString::fromStdString(valueStr); int jumpSize = std::stoi(sizeStr);
QString targetPart = QString::fromStdString(targetStr);
QString sizeStrQt = QString::fromStdString(sizeStr);
int jumpSize = sizeStrQt.toInt();
constexpr int MAX_PATTERN_LENGTH = 256; constexpr int MAX_PATTERN_LENGTH = 256;
if (jumpSize < 5) { if (jumpSize < 5) {
@ -417,20 +413,22 @@ void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valu
std::memcpy(reinterpret_cast<void*>(patchAddress), nopBytes.data(), nopBytes.size()); std::memcpy(reinterpret_cast<void*>(patchAddress), nopBytes.data(), nopBytes.size());
// Use "Target" to locate the start of the code cave // Use "Target" to locate the start of the code cave
uintptr_t jump_target = PatternScan(targetPart.toStdString()); uintptr_t jump_target = PatternScan(targetStr);
if (jump_target == 0) { if (jump_target == 0) {
LOG_ERROR(Loader, "PatternScan failed to Target with pattern: {}", LOG_ERROR(Loader, "PatternScan failed to Target with pattern: {}", targetStr);
targetPart.toStdString());
return; return;
} }
// Converts the Value attribute to a byte array (payload) // Converts the Value attribute to a byte array (payload)
std::vector<u8> payload; std::vector<u8> payload;
for (int i = 0; i < valuePart.length(); i += 2) { for (size_t i = 0; i < valueStr.length(); i += 2) {
bool ok;
unsigned int byteVal = valuePart.mid(i, 2).toUInt(&ok, 16); const char* byteStr = valueStr.substr(i, 2).c_str();
if (!ok) { char* endPtr;
LOG_ERROR(Loader, "Invalid byte in Value: {}", valuePart.mid(i, 2).toStdString()); unsigned int byteVal = std::strtoul(byteStr, &endPtr, 16);
if (endPtr != byteStr + 2) {
LOG_ERROR(Loader, "Invalid byte in Value: {}", valueStr.substr(i, 2));
return; return;
} }
payload.push_back(static_cast<u8>(byteVal)); payload.push_back(static_cast<u8>(byteVal));
@ -460,7 +458,7 @@ void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valu
std::memcpy(reinterpret_cast<void*>(code_cave_end), jumpBack, sizeof(jumpBack)); std::memcpy(reinterpret_cast<void*>(code_cave_end), jumpBack, sizeof(jumpBack));
LOG_INFO(Loader, LOG_INFO(Loader,
"Patch mask_jump32 aplicada: {}, PatchAddress: {:#x}, JumpTarget: {:#x}, " "Applied Patch mask_jump32: {}, PatchAddress: {:#x}, JumpTarget: {:#x}, "
"CodeCaveEnd: {:#x}, JumpSize: {}", "CodeCaveEnd: {:#x}, JumpSize: {}",
modNameStr, patchAddress, jump_target, code_cave_end, jumpSize); modNameStr, patchAddress, jump_target, code_cave_end, jumpSize);
return; return;