summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Rowe <mrowe@bdash.net.nz>2025-05-30 09:18:28 -0700
committerkat <kat@vector35.com>2025-06-18 10:41:33 -0400
commita7ff3ca06a7684a688628b9afb36398b3a4d9d45 (patch)
tree09be341274ff355d4a754350e1788a86032a09ae
parentb3b06af27b7c706bb01fc215c342c97082975b14 (diff)
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.
-rw-r--r--lang/c/pseudoc.cpp52
-rw-r--r--lang/c/pseudoc.h3
2 files changed, 28 insertions, 27 deletions
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<InstructionTextToken>{};
- const auto postTypeTokens =
- variableType ?
- TypePrinter::GetDefault()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
- vector<InstructionTextToken>{};
+ const auto prevTypeTokens = variableType ?
+ GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
+ vector<InstructionTextToken> {};
+ const auto postTypeTokens = variableType ?
+ GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
+ vector<InstructionTextToken> {};
// 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<InstructionTextToken>{};
- const auto postTypeTokens =
- variableType ?
- TypePrinter::GetDefault()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
- vector<InstructionTextToken>{};
+ const auto prevTypeTokens = variableType ?
+ GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
+ vector<InstructionTextToken> {};
+ const auto postTypeTokens = variableType ?
+ GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
+ vector<InstructionTextToken> {};
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<BinaryNinja::HighLevelILFunction> m_highLevelIL;
+ BinaryNinja::Ref<BinaryNinja::TypePrinter> 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);