shadPS4/src/common/disassembler.cpp

34 lines
1.2 KiB
C++
Raw Normal View History

2023-11-05 11:41:10 +00:00
#include "common/disassembler.h"
#include <fmt/format.h>
2023-05-30 10:33:52 +00:00
namespace Common {
Disassembler::Disassembler() {
2023-05-30 10:33:52 +00:00
ZydisDecoderInit(&m_decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64);
ZydisFormatterInit(&m_formatter, ZYDIS_FORMATTER_STYLE_INTEL);
}
Disassembler::~Disassembler() = default;
2023-05-30 10:33:52 +00:00
void Disassembler::printInstruction(void* code, u64 address) {
2023-05-30 10:33:52 +00:00
ZydisDecodedInstruction instruction;
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code),
&instruction, operands);
if (!ZYAN_SUCCESS(status)) {
fmt::print("decode instruction failed at {}\n", fmt::ptr(code));
} else {
2023-05-30 13:27:11 +00:00
printInst(instruction, operands,address);
2023-05-30 10:33:52 +00:00
}
}
void Disassembler::printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands, u64 address) {
2023-05-30 10:33:52 +00:00
const int bufLen = 256;
char szBuffer[bufLen];
ZydisFormatterFormatInstruction(&m_formatter, &inst, operands,inst.operand_count_visible,
szBuffer, sizeof(szBuffer), address, ZYAN_NULL);
fmt::print("instruction: {}\n", szBuffer);
}
} // namespace Common