1
0
mirror of synced 2025-01-11 13:52:15 +01:00
ImHex/plugins/disassembler/include/content/views/view_disassembler.hpp

48 lines
1.0 KiB
C++
Raw Normal View History

#pragma once
#include <hex/api/task_manager.hpp>
2023-05-14 21:50:58 +02:00
#include <hex/ui/view.hpp>
#include <ui/widgets.hpp>
#include <content/helpers/disassembler.hpp>
#include <string>
#include <vector>
namespace hex::plugin::disasm {
struct Disassembly {
u64 address;
u64 offset;
size_t size;
std::string bytes;
std::string mnemonic;
std::string operators;
};
class ViewDisassembler : public View::Window {
public:
explicit ViewDisassembler();
~ViewDisassembler() override;
void drawContent() override;
private:
TaskHolder m_disassemblerTask;
u64 m_imageLoadAddress = 0;
u64 m_imageBaseAddress = 0;
ui::RegionType m_range = ui::RegionType::EntireData;
Region m_regionToDisassemble = { };
Architecture m_architecture = Architecture::ARM;
2022-02-01 22:09:44 +01:00
cs_mode m_mode = cs_mode(0);
std::vector<Disassembly> m_disassembly;
2021-02-22 11:56:33 +01:00
void disassemble();
feat: Added export disassembler results to ASM file (#1987) ### Problem description <!-- Describe the bug that you fixed/feature request that you implemented, or link to an existing issue describing it --> This PR implements the feature request #1781, that suggests adding a button to export disassembled instructions into an ASM file. ### Implementation description This adds a button to export the current disassembled instructions to an ASM file. Said file is suffixed by an `.asm` extension if not specified at file creation. *Note: the file is written to for every `Disassembly` item in the vector, as it was the easiest and most memory-conservative way of doing it.* The file creation task is implemented based on IPS patch exports, so it fits the same pattern. A `ToastError` is raised when the ASM export could not complete successfully. Translations have been implemented for both `en_US` and `de_DE` for the two new keys: - `hex.disassembler.view.disassembler.export`: file export button - `hex.disassembler.view.disassembler.export.popup.error`: error popup text ### Screenshots The button is disabled when the disassembler is working, or when the disassembly vector is empty. Here is a complete breakdown of the visual changes: ![image](https://github.com/user-attachments/assets/af0ce701-9d77-45f1-9a5a-90d68d00bb0d) ### Additional things As expected, the exporter writes every item's `mnemonic` and `operators` to the file, producing an output like this: `example.asm` ```asm .byte 0x7f, 0x45, 0x4c, 0x46 andeq r0, r1, r2, lsl #2 andeq r0, r0, r0 andeq r0, r0, r0 eorseq r0, lr, r3 andeq r0, r0, r1 andeq r1, r0, r0, asr #32 andeq r0, r0, r0 andeq r0, r0, r0, asr #32 ``` --------- Signed-off-by: BioTheWolff <47079795+BioTheWolff@users.noreply.github.com>
2024-12-05 23:04:38 +01:00
void exportToFile();
};
}