Skip to content

Commit 13ce138

Browse files
committed
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.
1 parent 6143812 commit 13ce138

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

lang/c/pseudoc.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ using namespace BinaryNinja;
88

99
PseudoCFunction::PseudoCFunction(LanguageRepresentationFunctionType* type, Architecture* arch, Function* owner,
1010
HighLevelILFunction* highLevelILFunction) :
11-
LanguageRepresentationFunction(type, arch, owner, highLevelILFunction), m_highLevelIL(highLevelILFunction)
11+
LanguageRepresentationFunction(type, arch, owner, highLevelILFunction), m_highLevelIL(highLevelILFunction),
12+
m_typePrinter(type->GetTypePrinter())
1213
{
1314
}
1415

@@ -177,11 +178,7 @@ BNSymbolDisplayResult PseudoCFunction::AppendPointerTextToken(const HighLevelILI
177178

178179
string PseudoCFunction::GetSizeToken(size_t size, bool isSigned)
179180
{
180-
return TypePrinter::GetDefault()->GetTypeString(
181-
Type::IntegerType(size, isSigned),
182-
nullptr,
183-
QualifiedName()
184-
);
181+
return GetTypePrinter()->GetTypeString(Type::IntegerType(size, isSigned), nullptr, QualifiedName());
185182
}
186183

187184

@@ -546,11 +543,8 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
546543
{
547544
tokens.AppendOpenParen();
548545
tokens.AppendOpenParen();
549-
auto typeTokens = TypePrinter::GetDefault()->GetTypeTokens(
550-
instr.GetType(),
551-
GetArchitecture()->GetStandalonePlatform(),
552-
QualifiedName()
553-
);
546+
auto typeTokens = GetTypePrinter()->GetTypeTokens(
547+
instr.GetType(), GetArchitecture()->GetStandalonePlatform(), QualifiedName());
554548
for (auto& token: typeTokens)
555549
{
556550
tokens.Append(token);
@@ -1004,14 +998,12 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
1004998

1005999
const auto variableType = GetHighLevelILFunction()->GetFunction()->GetVariableType(destExpr);
10061000
const auto platform = GetHighLevelILFunction()->GetFunction()->GetPlatform();
1007-
const auto prevTypeTokens =
1008-
variableType ?
1009-
TypePrinter::GetDefault()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
1010-
vector<InstructionTextToken>{};
1011-
const auto postTypeTokens =
1012-
variableType ?
1013-
TypePrinter::GetDefault()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
1014-
vector<InstructionTextToken>{};
1001+
const auto prevTypeTokens = variableType ?
1002+
GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
1003+
vector<InstructionTextToken> {};
1004+
const auto postTypeTokens = variableType ?
1005+
GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
1006+
vector<InstructionTextToken> {};
10151007

10161008
// Check to see if the variable appears live
10171009
bool appearsDead = false;
@@ -1070,14 +1062,12 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
10701062

10711063
const auto variableType = GetHighLevelILFunction()->GetFunction()->GetVariableType(variable);
10721064
const auto platform = GetHighLevelILFunction()->GetFunction()->GetPlatform();
1073-
const auto prevTypeTokens =
1074-
variableType ?
1075-
TypePrinter::GetDefault()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
1076-
vector<InstructionTextToken>{};
1077-
const auto postTypeTokens =
1078-
variableType ?
1079-
TypePrinter::GetDefault()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
1080-
vector<InstructionTextToken>{};
1065+
const auto prevTypeTokens = variableType ?
1066+
GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
1067+
vector<InstructionTextToken> {};
1068+
const auto postTypeTokens = variableType ?
1069+
GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
1070+
vector<InstructionTextToken> {};
10811071

10821072
if (variableType)
10831073
{
@@ -2848,6 +2838,11 @@ string PseudoCFunction::GetAnnotationEndString() const
28482838
return " */";
28492839
}
28502840

2841+
TypePrinter* PseudoCFunction::GetTypePrinter() const
2842+
{
2843+
return m_typePrinter;
2844+
}
2845+
28512846

28522847
PseudoCFunctionType::PseudoCFunctionType(): LanguageRepresentationFunctionType("Pseudo C")
28532848
{

lang/c/pseudoc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class PseudoCFunction: public BinaryNinja::LanguageRepresentationFunction
66
{
77
BinaryNinja::Ref<BinaryNinja::HighLevelILFunction> m_highLevelIL;
8+
BinaryNinja::Ref<BinaryNinja::TypePrinter> m_typePrinter;
89

910
enum FieldDisplayType
1011
{
@@ -52,6 +53,8 @@ class PseudoCFunction: public BinaryNinja::LanguageRepresentationFunction
5253
void EndLines(
5354
const BinaryNinja::HighLevelILInstruction& instr, BinaryNinja::HighLevelILTokenEmitter& tokens) override;
5455

56+
BinaryNinja::TypePrinter* GetTypePrinter() const;
57+
5558
virtual void GetExpr_CALL_OR_TAILCALL(const BinaryNinja::HighLevelILInstruction& instr,
5659
BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
5760
BNOperatorPrecedence precedence, bool statement);

0 commit comments

Comments
 (0)