code: Replace printf/scanf with type safe fmt

This commit is contained in:
GPUCode 2023-10-26 23:29:05 +03:00
parent 33729d634e
commit 28819dede1
9 changed files with 50 additions and 52 deletions

View file

@ -1,6 +1,5 @@
#include "Disassembler.h"
#include <stdio.h>
#include <fmt/format.h>
Disassembler::Disassembler()
{
@ -15,11 +14,11 @@ Disassembler::~Disassembler()
void Disassembler::printInstruction(void* code,u64 address)//print a single instruction
{
ZydisDecodedInstruction instruction;
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code), &instruction, operands);
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code), &instruction, operands);
if (!ZYAN_SUCCESS(status))
{
printf("decode instruction failed at %p\n", code);
fmt::print("decode instruction failed at {}\n", fmt::ptr(code));
}
else
{
@ -30,7 +29,7 @@ void Disassembler::printInstruction(void* code,u64 address)//print a single inst
void Disassembler::printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands,u64 address)
{
const int bufLen = 256;
char szBuffer[bufLen];
char szBuffer[bufLen];
ZydisFormatterFormatInstruction(&m_formatter, &inst, operands,inst.operand_count_visible, szBuffer, sizeof(szBuffer), address, ZYAN_NULL);
printf("instruction: %s\n", szBuffer);
}
fmt::print("instruction: {}\n", szBuffer);
}