mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-19 18:04:56 +00:00
initial disasm class using zydis
This commit is contained in:
parent
b124bac0f7
commit
dfc234f363
4 changed files with 60 additions and 2 deletions
33
src/Util/Disassembler.cpp
Normal file
33
src/Util/Disassembler.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "Disassembler.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
Disassembler::Disassembler()
|
||||
{
|
||||
ZydisDecoderInit(&m_decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64);
|
||||
ZydisFormatterInit(&m_formatter, ZYDIS_FORMATTER_STYLE_INTEL);
|
||||
}
|
||||
|
||||
Disassembler::~Disassembler()
|
||||
{
|
||||
}
|
||||
|
||||
void Disassembler::printInstruction(void* code)//print a single instruction
|
||||
{
|
||||
ZydisDecodedInstruction instruction;
|
||||
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
|
||||
ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, ZYDIS_MAX_INSTRUCTION_LENGTH,&instruction, operands);
|
||||
if (!ZYAN_SUCCESS(status))
|
||||
{
|
||||
printf("decode instruction failed at %p\n", code);
|
||||
printInst(instruction, operands);
|
||||
}
|
||||
}
|
||||
|
||||
void Disassembler::printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands)
|
||||
{
|
||||
const int bufLen = 256;
|
||||
char szBuffer[bufLen];
|
||||
ZydisFormatterFormatInstruction(&m_formatter, &inst, operands,inst.operand_count_visible, szBuffer, sizeof(szBuffer), 0,NULL);
|
||||
printf("instruction: %s\n", szBuffer);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue