1b9f4f33de
### 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>
47 lines
991 B
C++
47 lines
991 B
C++
#pragma once
|
|
|
|
#include <hex/api/task_manager.hpp>
|
|
|
|
#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_baseAddress = 0;
|
|
ui::RegionType m_range = ui::RegionType::EntireData;
|
|
Region m_codeRegion = { 0, 0 };
|
|
|
|
Architecture m_architecture = Architecture::ARM;
|
|
cs_mode m_mode = cs_mode(0);
|
|
|
|
std::vector<Disassembly> m_disassembly;
|
|
|
|
void disassemble();
|
|
void exportToFile();
|
|
};
|
|
|
|
} |