initial disasm class using zydis
This commit is contained in:
parent
b124bac0f7
commit
dfc234f363
|
@ -33,7 +33,7 @@ add_executable(shadps4
|
||||||
src/Core/Memory.h
|
src/Core/Memory.h
|
||||||
src/Core/PS4/Linker.cpp
|
src/Core/PS4/Linker.cpp
|
||||||
src/Core/PS4/Linker.h
|
src/Core/PS4/Linker.h
|
||||||
"src/Util/Singleton.h")
|
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h")
|
||||||
|
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "zydis/Zydis.h"
|
||||||
|
|
||||||
|
class Disassembler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Disassembler();
|
||||||
|
~Disassembler();
|
||||||
|
void printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands);
|
||||||
|
void printInstruction(void* code);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZydisDecoder m_decoder;
|
||||||
|
ZydisFormatter m_formatter;
|
||||||
|
};
|
|
@ -19,11 +19,20 @@ target_include_directories(stb INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/stb")
|
||||||
set(SDL3_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDL)
|
set(SDL3_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDL)
|
||||||
add_subdirectory(${SDL3_DIR})
|
add_subdirectory(${SDL3_DIR})
|
||||||
|
|
||||||
|
#================ Zydis ========================
|
||||||
|
# Register Zydis dependency.
|
||||||
|
# Disable build of tools and examples.
|
||||||
|
option(ZYDIS_BUILD_TOOLS "" OFF)
|
||||||
|
option(ZYDIS_BUILD_EXAMPLES "" OFF)
|
||||||
|
set(zydis_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zydis)
|
||||||
|
add_subdirectory(${zydis_DIR})
|
||||||
|
|
||||||
#=================== IMGUI ===================
|
#=================== IMGUI ===================
|
||||||
|
|
||||||
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
|
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
|
||||||
add_library(IMGUI STATIC)
|
add_library(IMGUI STATIC)
|
||||||
|
|
||||||
|
|
||||||
target_sources( IMGUI
|
target_sources( IMGUI
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${IMGUI_DIR}/imgui_demo.cpp
|
${IMGUI_DIR}/imgui_demo.cpp
|
||||||
|
@ -47,6 +56,6 @@ find_package(OpenGL REQUIRED)
|
||||||
target_link_libraries(IMGUI PUBLIC ${OPENGL_LIBRARIES})
|
target_link_libraries(IMGUI PUBLIC ${OPENGL_LIBRARIES})
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS})
|
target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS} Zydis)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue