Skip to content

Commit a7ff3ca

Browse files
bdash0cyn
authored andcommitted
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 b3b06af commit a7ff3ca

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

lang/c/pseudoc.cpp

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ 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
{
14+
if (!m_typePrinter) {
15+
m_typePrinter = TypePrinter::GetDefault();
16+
}
1317
}
1418

1519

@@ -177,11 +181,7 @@ BNSymbolDisplayResult PseudoCFunction::AppendPointerTextToken(const HighLevelILI
177181

178182
string PseudoCFunction::GetSizeToken(size_t size, bool isSigned)
179183
{
180-
return TypePrinter::GetDefault()->GetTypeString(
181-
Type::IntegerType(size, isSigned),
182-
nullptr,
183-
QualifiedName()
184-
);
184+
return GetTypePrinter()->GetTypeString(Type::IntegerType(size, isSigned), nullptr, QualifiedName());
185185
}
186186

187187

@@ -546,11 +546,8 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
546546
{
547547
tokens.AppendOpenParen();
548548
tokens.AppendOpenParen();
549-
auto typeTokens = TypePrinter::GetDefault()->GetTypeTokens(
550-
instr.GetType(),
551-
GetArchitecture()->GetStandalonePlatform(),
552-
QualifiedName()
553-
);
549+
auto typeTokens = GetTypePrinter()->GetTypeTokens(
550+
instr.GetType(), GetArchitecture()->GetStandalonePlatform(), QualifiedName());
554551
for (auto& token: typeTokens)
555552
{
556553
tokens.Append(token);
@@ -1004,14 +1001,12 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
10041001

10051002
const auto variableType = GetHighLevelILFunction()->GetFunction()->GetVariableType(destExpr);
10061003
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>{};
1004+
const auto prevTypeTokens = variableType ?
1005+
GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
1006+
vector<InstructionTextToken> {};
1007+
const auto postTypeTokens = variableType ?
1008+
GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
1009+
vector<InstructionTextToken> {};
10151010

10161011
// Check to see if the variable appears live
10171012
bool appearsDead = false;
@@ -1070,14 +1065,12 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
10701065

10711066
const auto variableType = GetHighLevelILFunction()->GetFunction()->GetVariableType(variable);
10721067
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>{};
1068+
const auto prevTypeTokens = variableType ?
1069+
GetTypePrinter()->GetTypeTokensBeforeName(variableType, platform, variableType.GetConfidence()) :
1070+
vector<InstructionTextToken> {};
1071+
const auto postTypeTokens = variableType ?
1072+
GetTypePrinter()->GetTypeTokensAfterName(variableType, platform, variableType.GetConfidence()) :
1073+
vector<InstructionTextToken> {};
10811074

10821075
if (variableType)
10831076
{
@@ -2848,6 +2841,11 @@ string PseudoCFunction::GetAnnotationEndString() const
28482841
return " */";
28492842
}
28502843

2844+
TypePrinter* PseudoCFunction::GetTypePrinter() const
2845+
{
2846+
return m_typePrinter;
2847+
}
2848+
28512849

28522850
PseudoCFunctionType::PseudoCFunctionType(): LanguageRepresentationFunctionType("Pseudo C")
28532851
{

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)