mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
fix: Find view replace and hex editor paste logic being wrong
This commit is contained in:
@@ -157,7 +157,7 @@ namespace hex::plugin::builtin {
|
||||
std::memcpy(&value, bytes.data(), bytes.size());
|
||||
|
||||
if (std::signed_integral<T>)
|
||||
hex::signExtend(bytes.size() * 8, value);
|
||||
value = hex::signExtend(bytes.size() * 8, value);
|
||||
|
||||
return hex::format("{}", value);
|
||||
}
|
||||
@@ -536,13 +536,12 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::BeginDisabled(this->m_replaceBuffer.empty());
|
||||
if (ImGui::Button("hex.builtin.view.find.context.replace"_lang)) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
auto bytes = parseHexString(this->m_replaceBuffer);
|
||||
|
||||
for (const auto &occurrence : *this->m_sortedOccurrences) {
|
||||
if (occurrence.selected) {
|
||||
auto bytes = decodeByteString(this->m_replaceBuffer);
|
||||
|
||||
size_t size = std::min<size_t>(occurrence.region.size, bytes.size());
|
||||
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
provider->write(occurrence.region.getStartAddress(), bytes.data(), size);
|
||||
}
|
||||
}
|
||||
@@ -557,12 +556,13 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::BeginDisabled(this->m_replaceBuffer.empty());
|
||||
if (ImGui::Button("hex.builtin.view.find.context.replace"_lang)) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
auto bytes = decodeByteString(this->m_replaceBuffer);
|
||||
|
||||
for (const auto &occurrence : *this->m_sortedOccurrences) {
|
||||
if (occurrence.selected) {
|
||||
size_t size = std::min<size_t>(occurrence.region.size, this->m_replaceBuffer.size());
|
||||
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
provider->write(occurrence.region.getStartAddress(), this->m_replaceBuffer.data(), size);
|
||||
size_t size = std::min<size_t>(occurrence.region.size, bytes.size());
|
||||
provider->write(occurrence.region.getStartAddress(), bytes.data(), size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,30 +654,7 @@ namespace hex::plugin::builtin {
|
||||
static void pasteBytes(const Region &selection, bool selectionCheck) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
std::string clipboard = ImGui::GetClipboardText();
|
||||
if (clipboard.empty())
|
||||
return;
|
||||
|
||||
// Remove common hex prefixes and commas
|
||||
hex::replaceStrings(clipboard, "0x", "");
|
||||
hex::replaceStrings(clipboard, "0X", "");
|
||||
hex::replaceStrings(clipboard, ",", "");
|
||||
|
||||
// Check for non-hex characters
|
||||
bool isValidHexString = std::find_if(clipboard.begin(), clipboard.end(), [](char c) {
|
||||
return !std::isxdigit(c) && !std::isspace(c);
|
||||
}) == clipboard.end();
|
||||
|
||||
if (!isValidHexString) return;
|
||||
|
||||
// Remove all whitespace
|
||||
clipboard.erase(std::remove_if(clipboard.begin(), clipboard.end(), [](char c) { return std::isspace(c); }), clipboard.end());
|
||||
|
||||
// Only paste whole bytes
|
||||
if (clipboard.length() % 2 != 0) return;
|
||||
|
||||
// Convert hex string to bytes
|
||||
std::vector<u8> buffer = crypt::decode16(clipboard);
|
||||
auto buffer = parseHexString(ImGui::GetClipboardText());
|
||||
|
||||
if (!selectionCheck) {
|
||||
if (selection.getStartAddress() + buffer.size() >= provider->getActualSize())
|
||||
|
||||
Reference in New Issue
Block a user