mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
fix: Crashes when switching disassembler architecture while disassembling
This commit is contained in:
@@ -52,6 +52,10 @@ namespace hex::plugin::disasm {
|
||||
|
||||
// Create a capstone disassembler instance
|
||||
if (currArchitecture->start()) {
|
||||
ON_SCOPE_EXIT {
|
||||
currArchitecture->end();
|
||||
};
|
||||
|
||||
std::vector<u8> buffer(1_MiB, 0x00);
|
||||
|
||||
const u64 codeOffset = region.getStartAddress() - m_imageBaseAddress;
|
||||
@@ -93,8 +97,6 @@ namespace hex::plugin::disasm {
|
||||
if (hadError) break;
|
||||
hadError = true;
|
||||
}
|
||||
|
||||
currArchitecture->end();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -136,59 +138,64 @@ namespace hex::plugin::disasm {
|
||||
auto ®ion = m_regionToDisassemble.get(provider);
|
||||
auto &range = m_range.get(provider);
|
||||
|
||||
// Draw region selection picker
|
||||
ui::regionSelectionPicker(®ion, provider, &range, true, true);
|
||||
|
||||
ImGuiExt::Header("hex.disassembler.view.disassembler.position"_lang);
|
||||
|
||||
// Draw base address input
|
||||
ImGui::BeginDisabled(m_disassemblerTask.isRunning());
|
||||
{
|
||||
auto &address = m_imageLoadAddress.get(provider);
|
||||
ImGuiExt::InputHexadecimal("hex.disassembler.view.disassembler.image_load_address"_lang, &address, ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::SameLine();
|
||||
ImGuiExt::HelpHover("hex.disassembler.view.disassembler.image_load_address.hint"_lang, ICON_VS_INFO);
|
||||
}
|
||||
// Draw region selection picker
|
||||
ui::regionSelectionPicker(®ion, provider, &range, true, true);
|
||||
|
||||
// Draw code region start address input
|
||||
ImGui::BeginDisabled(m_range == ui::RegionType::EntireData);
|
||||
{
|
||||
auto &address = m_imageBaseAddress.get(provider);
|
||||
ImGuiExt::InputHexadecimal("hex.disassembler.view.disassembler.image_base_address"_lang, &address, ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::SameLine();
|
||||
ImGuiExt::HelpHover("hex.disassembler.view.disassembler.image_base_address.hint"_lang, ICON_VS_INFO);
|
||||
ImGuiExt::Header("hex.disassembler.view.disassembler.position"_lang);
|
||||
|
||||
// Draw base address input
|
||||
{
|
||||
auto &address = m_imageLoadAddress.get(provider);
|
||||
ImGuiExt::InputHexadecimal("hex.disassembler.view.disassembler.image_load_address"_lang, &address, ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::SameLine();
|
||||
ImGuiExt::HelpHover("hex.disassembler.view.disassembler.image_load_address.hint"_lang, ICON_VS_INFO);
|
||||
}
|
||||
|
||||
// Draw code region start address input
|
||||
ImGui::BeginDisabled(m_range == ui::RegionType::EntireData);
|
||||
{
|
||||
auto &address = m_imageBaseAddress.get(provider);
|
||||
ImGuiExt::InputHexadecimal("hex.disassembler.view.disassembler.image_base_address"_lang, &address, ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::SameLine();
|
||||
ImGuiExt::HelpHover("hex.disassembler.view.disassembler.image_base_address.hint"_lang, ICON_VS_INFO);
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
// Draw settings
|
||||
{
|
||||
ImGuiExt::Header("hex.ui.common.settings"_lang);
|
||||
|
||||
// Draw architecture selector
|
||||
const auto &architectures = ContentRegistry::Disassembler::impl::getArchitectures();
|
||||
if (architectures.empty()) {
|
||||
ImGuiExt::TextSpinner("hex.disassembler.view.disassembler.arch"_lang);
|
||||
} else {
|
||||
const auto &currArchitecture = m_currArchitecture.get(provider);
|
||||
if (currArchitecture == nullptr) {
|
||||
m_currArchitecture = architectures.begin()->second();
|
||||
}
|
||||
|
||||
if (ImGui::BeginCombo("hex.disassembler.view.disassembler.arch"_lang, currArchitecture->getName().c_str())) {
|
||||
for (const auto &[name, creator] : architectures) {
|
||||
if (ImGui::Selectable(name.c_str(), name == currArchitecture->getName())) {
|
||||
m_currArchitecture = creator();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
// Draw sub-settings for each architecture
|
||||
if (ImGuiExt::BeginBox()) {
|
||||
currArchitecture->drawSettings();
|
||||
}
|
||||
ImGuiExt::EndBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
// Draw settings
|
||||
{
|
||||
ImGuiExt::Header("hex.ui.common.settings"_lang);
|
||||
|
||||
// Draw architecture selector
|
||||
const auto &architectures = ContentRegistry::Disassembler::impl::getArchitectures();
|
||||
if (architectures.empty()) {
|
||||
ImGuiExt::TextSpinner("hex.disassembler.view.disassembler.arch"_lang);
|
||||
} else {
|
||||
const auto &currArchitecture = m_currArchitecture.get(provider);
|
||||
if (currArchitecture == nullptr) {
|
||||
m_currArchitecture = architectures.begin()->second();
|
||||
}
|
||||
|
||||
if (ImGui::BeginCombo("hex.disassembler.view.disassembler.arch"_lang, currArchitecture->getName().c_str())) {
|
||||
for (const auto &[name, creator] : architectures) {
|
||||
if (ImGui::Selectable(name.c_str(), name == currArchitecture->getName())) {
|
||||
m_currArchitecture = creator();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
// Draw sub-settings for each architecture
|
||||
if (ImGuiExt::BeginBox()) {
|
||||
currArchitecture->drawSettings();
|
||||
}
|
||||
ImGuiExt::EndBox();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw disassemble button
|
||||
ImGui::BeginDisabled(m_disassemblerTask.isRunning() || region.getStartAddress() < m_imageBaseAddress);
|
||||
|
||||
Reference in New Issue
Block a user