From d5b4b096b4ee690b9dc65435041660b1563bb7d4 Mon Sep 17 00:00:00 2001 From: Angie Date: Thu, 7 Jul 2022 00:44:30 -0400 Subject: [PATCH] Allow disabling upper case for immediates --- include/common/RabbitizerConfig.h | 3 ++- rabbitizer/Config.pyi | 3 ++- rabbitizer/rabbitizer_global_config.c | 6 ++++-- src/common/RabbitizerConfig.c | 3 ++- .../RabbitizerInstruction_Disassemble.c | 17 ++++++++++++----- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/common/RabbitizerConfig.h b/include/common/RabbitizerConfig.h index 4c76a53..8a881a9 100644 --- a/include/common/RabbitizerConfig.h +++ b/include/common/RabbitizerConfig.h @@ -57,7 +57,8 @@ typedef struct RabbitizerConfig_ToolchainTweaks { typedef struct RabbitizerConfig_Misc { int opcodeLJust; // The minimal number of characters to left-align the opcode name bool unknownInstrComment; // Generate a pseudo-disassembly comment when disassembling non implemented instructions - bool omit0XOnSmallHex; + bool omit0XOnSmallImm; + bool upperCaseImm; } RabbitizerConfig_Misc; typedef struct RabbitizerConfig { diff --git a/rabbitizer/Config.pyi b/rabbitizer/Config.pyi index 3c51504..ad95205 100644 --- a/rabbitizer/Config.pyi +++ b/rabbitizer/Config.pyi @@ -39,6 +39,7 @@ class _RabbitizerConfig: misc_opcodeLJust: int = 11 misc_unknownInstrComment: bool = True - misc_omit0XOnSmallHex: bool = False + misc_omit0XOnSmallImm: bool = False + misc_upperCaseImm: bool = False config: _RabbitizerConfig diff --git a/rabbitizer/rabbitizer_global_config.c b/rabbitizer/rabbitizer_global_config.c index b401d6a..61606ac 100644 --- a/rabbitizer/rabbitizer_global_config.c +++ b/rabbitizer/rabbitizer_global_config.c @@ -124,7 +124,8 @@ DEF_MEMBER_GET_SET_BOOL(toolchainTweaks, sn64DivFix) DEF_MEMBER_GET_SET_INT(misc, opcodeLJust, false, 0, 0) DEF_MEMBER_GET_SET_BOOL(misc, unknownInstrComment) -DEF_MEMBER_GET_SET_BOOL(misc, omit0XOnSmallHex) +DEF_MEMBER_GET_SET_BOOL(misc, omit0XOnSmallImm) +DEF_MEMBER_GET_SET_BOOL(misc, upperCaseImm) static PyGetSetDef rabbitizer_global_config_GetSets[] = { @@ -148,7 +149,8 @@ static PyGetSetDef rabbitizer_global_config_GetSets[] = { MEMBER_GET_SET(misc, opcodeLJust, "", NULL), MEMBER_GET_SET(misc, unknownInstrComment, "", NULL), - MEMBER_GET_SET(misc, omit0XOnSmallHex, "", NULL), + MEMBER_GET_SET(misc, omit0XOnSmallImm, "", NULL), + MEMBER_GET_SET(misc, upperCaseImm, "", NULL), { 0 }, }; diff --git a/src/common/RabbitizerConfig.c b/src/common/RabbitizerConfig.c index aec8885..ff61691 100644 --- a/src/common/RabbitizerConfig.c +++ b/src/common/RabbitizerConfig.c @@ -45,6 +45,7 @@ RabbitizerConfig RabbitizerConfig_Cfg = { .misc = { .opcodeLJust = 7+4, .unknownInstrComment = true, - .omit0XOnSmallHex = false, + .omit0XOnSmallImm = false, + .upperCaseImm = true, } }; diff --git a/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c b/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c index 9e26340..6ee74b7 100644 --- a/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c +++ b/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c @@ -151,8 +151,7 @@ size_t RabbitizerOperandType_processLabel(const RabbitizerInstruction *self, cha return immOverrideLength; } - RABUTILS_BUFFER_CPY(dst, totalSize, "func_"); - RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%06X", RabbitizerInstruction_getInstrIndexAsVram(self)); + RABUTILS_BUFFER_SPRINTF(dst, totalSize, "func_%06X", RabbitizerInstruction_getInstrIndexAsVram(self)); return totalSize; } @@ -166,16 +165,24 @@ size_t RabbitizerOperandType_processImmediate(const RabbitizerInstruction *self, } number = RabbitizerInstruction_getProcessedImmediate(self); - if (RabbitizerConfig_Cfg.misc.omit0XOnSmallHex) { + if (RabbitizerConfig_Cfg.misc.omit0XOnSmallImm) { if (number > -10 && number < 10) { RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", number); return totalSize; } } if (number < 0) { - RABUTILS_BUFFER_SPRINTF(dst, totalSize, "-0x%X", -number); + if (RabbitizerConfig_Cfg.misc.upperCaseImm) { + RABUTILS_BUFFER_SPRINTF(dst, totalSize, "-0x%X", -number); + } else { + RABUTILS_BUFFER_SPRINTF(dst, totalSize, "-0x%x", -number); + } } else { - RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%X", number); + if (RabbitizerConfig_Cfg.misc.upperCaseImm) { + RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%X", number); + } else { + RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%x", number); + } } return totalSize; }