mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
provider: Added insert bytes feature
This commit is contained in:
@@ -101,16 +101,40 @@ namespace hex::plugin::builtin::prv {
|
||||
}
|
||||
}
|
||||
|
||||
void FileProvider::resize(ssize_t newSize) {
|
||||
void FileProvider::resize(size_t newSize) {
|
||||
this->close();
|
||||
|
||||
{
|
||||
File(this->m_path, File::Mode::Write).setSize(newSize);
|
||||
auto file = File(this->m_path, File::Mode::Write);
|
||||
|
||||
file.setSize(newSize);
|
||||
this->m_fileSize = file.getSize();
|
||||
}
|
||||
|
||||
this->open();
|
||||
}
|
||||
|
||||
void FileProvider::insert(u64 offset, size_t size) {
|
||||
auto oldSize = this->getActualSize();
|
||||
this->resize(oldSize + size);
|
||||
|
||||
std::vector<u8> buffer(0x1000);
|
||||
const std::vector<u8> zeroBuffer(0x1000);
|
||||
|
||||
auto position = oldSize;
|
||||
while (position > offset) {
|
||||
size_t readSize = (position >= (offset + buffer.size())) ? buffer.size() : (position - offset);
|
||||
|
||||
position -= readSize;
|
||||
|
||||
this->readRaw(position, buffer.data(), readSize);
|
||||
this->writeRaw(position, zeroBuffer.data(), readSize);
|
||||
this->writeRaw(position + size, buffer.data(), readSize);
|
||||
}
|
||||
|
||||
Provider::insert(offset, size);
|
||||
}
|
||||
|
||||
size_t FileProvider::getActualSize() const {
|
||||
return this->m_fileSize;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace hex::plugin::builtin::prv {
|
||||
|
||||
}
|
||||
|
||||
GDBProvider::GDBProvider() : Provider() {
|
||||
GDBProvider::GDBProvider() : Provider(), m_size(0xFFFF'FFFF) {
|
||||
|
||||
}
|
||||
|
||||
@@ -218,12 +218,8 @@ namespace hex::plugin::builtin::prv {
|
||||
|
||||
}
|
||||
|
||||
void GDBProvider::resize(ssize_t newSize) {
|
||||
|
||||
}
|
||||
|
||||
size_t GDBProvider::getActualSize() const {
|
||||
return 0xFFFF'FFFF;
|
||||
return this->m_size;
|
||||
}
|
||||
|
||||
std::string GDBProvider::getName() const {
|
||||
@@ -303,6 +299,12 @@ namespace hex::plugin::builtin::prv {
|
||||
ImGui::InputText("hex.builtin.provider.gdb.ip"_lang, this->m_ipAddress.data(), this->m_ipAddress.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &this->m_ipAddress);
|
||||
ImGui::InputInt("hex.builtin.provider.gdb.port"_lang, &this->m_port, 0, 0);
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::TextUnformatted("0x");
|
||||
ImGui::SameLine();
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_size, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
|
||||
if (this->m_port < 0)
|
||||
this->m_port = 0;
|
||||
else if (this->m_port > 0xFFFF)
|
||||
|
||||
@@ -317,16 +317,40 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupModal("hex.builtin.view.hexeditor.menu.edit.resize"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_resizeSize, nullptr, nullptr, "0x%016llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::TextUnformatted("0x");
|
||||
ImGui::SameLine();
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_resizeSize, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::NewLine();
|
||||
|
||||
confirmButtons("hex.common.set"_lang, "hex.common.cancel"_lang,
|
||||
[this, &provider]{
|
||||
provider->resize(this->m_resizeSize);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}, []{
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
[this, &provider]{
|
||||
provider->resize(this->m_resizeSize);
|
||||
ImGui::CloseCurrentPopup();
|
||||
},
|
||||
[] {
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
|
||||
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupModal("hex.builtin.view.hexeditor.menu.edit.insert"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::TextUnformatted("0x");
|
||||
ImGui::SameLine();
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_resizeSize, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::NewLine();
|
||||
|
||||
confirmButtons("hex.common.set"_lang, "hex.common.cancel"_lang,
|
||||
[this, &provider] {
|
||||
provider->insert(std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), this->m_resizeSize);
|
||||
ImGui::CloseCurrentPopup();
|
||||
},
|
||||
[] {
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
|
||||
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
||||
ImGui::CloseCurrentPopup();
|
||||
@@ -1010,6 +1034,13 @@ namespace hex::plugin::builtin {
|
||||
ImGui::OpenPopup("hex.builtin.view.hexeditor.menu.edit.resize"_lang);
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.edit.insert"_lang, nullptr, false, providerValid && provider->isResizable())) {
|
||||
View::doLater([this]{
|
||||
this->m_resizeSize = 0;
|
||||
ImGui::OpenPopup("hex.builtin.view.hexeditor.menu.edit.insert"_lang);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ViewHexEditor::registerEvents() {
|
||||
|
||||
@@ -244,7 +244,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "Alles auswählen" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "Lesezeichen erstellen" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "Basisadresse setzen" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Grösse ändern" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Grösse ändern..." },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.insert", "Einsetzen..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "Dateninformationen" },
|
||||
{ "hex.builtin.view.information.control", "Einstellungen" },
|
||||
|
||||
@@ -246,7 +246,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "Select all" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "Create bookmark" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "Set base address" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Resize" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Resize..." },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.insert", "Insert..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "Data Information" },
|
||||
{ "hex.builtin.view.information.control", "Control" },
|
||||
|
||||
@@ -243,7 +243,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "Seleziona tutti" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "Crea segnalibro" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "Imposta indirizzo di base" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Ridimensiona" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Ridimensiona..." },
|
||||
//{ "hex.builtin.view.hexeditor.menu.edit.insert", "Insert..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "Informazione sui Dati" },
|
||||
{ "hex.builtin.view.information.control", "Controllo" },
|
||||
|
||||
@@ -243,7 +243,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "全选" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "添加书签" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "设置基地址" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "修改大小" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "修改大小..." },
|
||||
//{ "hex.builtin.view.hexeditor.menu.edit.insert", "Insert..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "数据信息" },
|
||||
{ "hex.builtin.view.information.control", "控制" },
|
||||
|
||||
Reference in New Issue
Block a user