2020-11-22 23:07:50 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-18 14:50:43 +01:00
|
|
|
#include <hex/api/task_manager.hpp>
|
2023-05-14 21:50:58 +02:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/ui/view.hpp>
|
2022-08-07 12:20:40 +02:00
|
|
|
#include <ui/widgets.hpp>
|
2021-01-13 17:28:27 +01:00
|
|
|
|
2023-12-22 23:39:38 +01:00
|
|
|
#include <content/helpers/disassembler.hpp>
|
2020-11-22 23:07:50 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-12-23 21:09:41 +01:00
|
|
|
namespace hex::plugin::disasm {
|
2020-11-22 23:07:50 +01:00
|
|
|
|
|
|
|
struct Disassembly {
|
|
|
|
u64 address;
|
|
|
|
u64 offset;
|
2020-11-23 13:10:14 +01:00
|
|
|
size_t size;
|
2020-11-22 23:07:50 +01:00
|
|
|
std::string bytes;
|
2020-11-23 15:22:26 +01:00
|
|
|
std::string mnemonic;
|
|
|
|
std::string operators;
|
2020-11-22 23:07:50 +01:00
|
|
|
};
|
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
class ViewDisassembler : public View::Window {
|
2020-11-22 23:07:50 +01:00
|
|
|
public:
|
2020-12-27 15:39:06 +01:00
|
|
|
explicit ViewDisassembler();
|
2020-11-22 23:07:50 +01:00
|
|
|
~ViewDisassembler() override;
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void drawContent() override;
|
2020-11-22 23:07:50 +01:00
|
|
|
|
|
|
|
private:
|
2022-08-17 16:15:36 +02:00
|
|
|
TaskHolder m_disassemblerTask;
|
2020-11-22 23:07:50 +01:00
|
|
|
|
2022-08-07 12:20:40 +02:00
|
|
|
u64 m_baseAddress = 0;
|
2023-04-10 14:08:21 +02:00
|
|
|
ui::RegionType m_range = ui::RegionType::EntireData;
|
2022-08-07 12:20:40 +02:00
|
|
|
Region m_codeRegion = { 0, 0 };
|
2020-11-22 23:07:50 +01:00
|
|
|
|
2020-12-05 17:32:30 +01:00
|
|
|
Architecture m_architecture = Architecture::ARM;
|
2022-02-01 22:09:44 +01:00
|
|
|
cs_mode m_mode = cs_mode(0);
|
2020-11-22 23:07:50 +01:00
|
|
|
|
|
|
|
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();
|
2020-11-22 23:07:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|