Skip to content

Commit 53fc6f0

Browse files
committed
added disassembler
1 parent 3868c4c commit 53fc6f0

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,8 @@ mono_crash.*
7979
[Dd]ebugPublic/
8080
[Rr]elease/
8181
[Rr]eleases/
82-
x64/
83-
x86/
8482
build/
8583
intermediate/
86-
hypervisor_intermediate/
87-
controller_intermediate/
8884
[Ww][Ii][Nn]32/
8985
[Aa][Rr][Mm]/
9086
[Aa][Rr][Mm]64/
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "disassembler.hpp"
2+
3+
std::uintptr_t x86::disassembler_t::instruction_t::absolute_address() const
4+
{
5+
std::uintptr_t absolute_address = 0;
6+
7+
if (!ZYAN_SUCCESS(ZydisCalcAbsoluteAddress(&this->info, this->operands, this->runtime_address, &absolute_address)))
8+
{
9+
return 0;
10+
}
11+
12+
return absolute_address;
13+
}
14+
15+
bool x86::disassembler_t::initialize()
16+
{
17+
return ZYAN_SUCCESS(ZydisDecoderInit(&this->m_decoder, ZydisMachineMode::ZYDIS_MACHINE_MODE_LONG_64, ZydisStackWidth::ZYDIS_STACK_WIDTH_64));
18+
}
19+
20+
bool x86::disassembler_t::decode(const std::uintptr_t runtime_address, const void* buffer, const std::size_t length, instruction_t& instruction) const
21+
{
22+
instruction.runtime_address = runtime_address;
23+
24+
ZydisDecoderContext ctx;
25+
26+
return ZYAN_SUCCESS(ZydisDecoderDecodeInstruction(&this->m_decoder, &ctx, buffer, length, &instruction.info)) &&
27+
ZYAN_SUCCESS(ZydisDecoderDecodeOperands(&this->m_decoder, &ctx, &instruction.info, instruction.operands, instruction.info.operand_count));
28+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <cstddef>
5+
#include <Zydis/Zydis.h>
6+
7+
namespace x86
8+
{
9+
class disassembler_t
10+
{
11+
ZydisDecoder m_decoder = { };
12+
13+
public:
14+
struct instruction_t
15+
{
16+
std::uintptr_t runtime_address;
17+
ZydisDecodedInstruction info;
18+
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT];
19+
20+
[[nodiscard]] std::uintptr_t absolute_address() const;
21+
};
22+
23+
bool initialize();
24+
25+
bool decode(std::uintptr_t runtime_address, const void* buffer, std::size_t length, instruction_t& instruction) const;
26+
};
27+
}

0 commit comments

Comments
 (0)