From a7ff3ca06a7684a688628b9afb36398b3a4d9d45 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 30 May 2025 09:18:28 -0700 Subject: Have PseudoCFunction use its language's type printer It was previously explicitly using the default. Retreiving it from the language will make it possible for PseudoObjCFunction to provide its own type printer. --- lang/c/pseudoc.cpp | 52 +++++++++++++++++++++++++--------------------------- lang/c/pseudoc.h | 3 +++ 2 files changed, 28 insertions(+), 27 deletions(-) (limited to 'lang') diff --git a/lang/c/pseudoc.cpp b/lang/c/pseudoc.cpp index 4362ec40..cb6c1b94 100644 --- a/lang/c/pseudoc.cpp +++ b/lang/c/pseudoc.cpp @@ -8,8 +8,12 @@ using namespace BinaryNinja; PseudoCFunction::PseudoCFunction(LanguageRepresentationFunctionType* type, Architecture* arch, Function* owner, HighLevelILFunction* highLevelILFunction) : - LanguageRepresentationFunction(type, arch, owner, highLevelILFunction), m_highLevelIL(highLevelILFunction) + LanguageRepresentationFunction(type, arch, owner, highLevelILFunction), m_highLevelIL(highLevelILFunction), + m_typePrinter(type->GetTypePrinter()) { + if (!m_typePrinter) { + m_typePrinter = TypePrinter::GetDefault(); + } } @@ -177,11 +181,7 @@ BNSymbolDisplayResult PseudoCFunction::AppendPointerTextToken(const HighLevelILI string PseudoCFunction::GetSizeToken(size_t size, bool isSigned) { - return TypePrinter::GetDefault()->GetTypeString( - Type::IntegerType(size, isSigned), - nullptr, - QualifiedName() - ); + return GetTypePrinter()->GetTypeString(Type::IntegerType(size, isSigned), nullptr, QualifiedName()); } @@ -546,11 +546,8 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H { tokens.AppendOpenParen(); tokens.AppendOpenParen(); - auto typeTokens = TypePrinter::GetDefault()->GetTypeTokens( - instr.GetType(), - GetArchitecture()->GetStandalonePlatform(), - QualifiedName() - ); + auto typeTokens = GetTypePrinter()->GetTypeTokens( + instr.GetType(), GetArchitecture()->GetStandalonePlatform(), QualifiedName()); for (auto& token: typeTokens) { tokens.Append(token); @@ -1004,14 +1001,12 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H const auto variableType = GetHighLevelILFunction()->GetFunction()->GetVariableType(destExpr); const auto platform = GetHighLevelILFunction()->GetFunction()->GetPlatform(); - const auto prevTypeTokens = - variableType ? - TypePrinter::GetDefault()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) : - vector{}; - const auto postTypeTokens = - variableType ? - TypePrinter::GetDefault()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) : - vector{}; + const auto prevTypeTokens = variableType ? + GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) : + vector {}; + const auto postTypeTokens = variableType ? + GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) : + vector {}; // Check to see if the variable appears live bool appearsDead = false; @@ -1070,14 +1065,12 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H const auto variableType = GetHighLevelILFunction()->GetFunction()->GetVariableType(variable); const auto platform = GetHighLevelILFunction()->GetFunction()->GetPlatform(); - const auto prevTypeTokens = - variableType ? - TypePrinter::GetDefault()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) : - vector{}; - const auto postTypeTokens = - variableType ? - TypePrinter::GetDefault()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) : - vector{}; + const auto prevTypeTokens = variableType ? + GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) : + vector {}; + const auto postTypeTokens = variableType ? + GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) : + vector {}; if (variableType) { @@ -2848,6 +2841,11 @@ string PseudoCFunction::GetAnnotationEndString() const return " */"; } +TypePrinter* PseudoCFunction::GetTypePrinter() const +{ + return m_typePrinter; +} + PseudoCFunctionType::PseudoCFunctionType(): LanguageRepresentationFunctionType("Pseudo C") { diff --git a/lang/c/pseudoc.h b/lang/c/pseudoc.h index 66178432..65d3fc69 100644 --- a/lang/c/pseudoc.h +++ b/lang/c/pseudoc.h @@ -5,6 +5,7 @@ class PseudoCFunction: public BinaryNinja::LanguageRepresentationFunction { BinaryNinja::Ref m_highLevelIL; + BinaryNinja::Ref m_typePrinter; enum FieldDisplayType { @@ -52,6 +53,8 @@ protected: void EndLines( const BinaryNinja::HighLevelILInstruction& instr, BinaryNinja::HighLevelILTokenEmitter& tokens) override; + BinaryNinja::TypePrinter* GetTypePrinter() const; + virtual void GetExpr_CALL_OR_TAILCALL(const BinaryNinja::HighLevelILInstruction& instr, BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement); -- cgit v1.3.1