MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / AppendPointerTextToken

Method AppendPointerTextToken

lang/rust/pseudorust.cpp:61–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59
60
61BNSymbolDisplayResult PseudoRustFunction::AppendPointerTextToken(const HighLevelILInstruction& instr, int64_t val,
62 vector<InstructionTextToken>& tokens, DisassemblySettings* settings, BNSymbolDisplayType symbolDisplay, BNOperatorPrecedence precedence)
63{
64 Confidence<Ref<Type>> type = instr.GetType();
65 if (type && (type->GetClass() == PointerTypeClass) && type->IsConst())
66 {
67 string stringValue;
68 size_t childWidth = 0;
69 if (auto child = type->GetChildType(); child)
70 childWidth = child->GetWidth();
71 if (auto strType = GetFunction()->GetView()->CheckForStringAnnotationType(val, stringValue, false, false, childWidth); strType.has_value())
72 {
73 if (symbolDisplay == DereferenceNonDataSymbols)
74 {
75 if (precedence > UnaryOperatorPrecedence)
76 tokens.emplace_back(BraceToken, "(");
77 tokens.emplace_back(OperationToken, "*");
78 }
79 tokens.emplace_back(BraceToken, DisassemblyTextRenderer::GetStringLiteralPrefix(strType.value()) + string("\""));
80 tokens.emplace_back(StringToken, StringReferenceTokenContext, stringValue, instr.address, strType.value());
81 tokens.emplace_back(BraceToken, "\"");
82 if (symbolDisplay == DereferenceNonDataSymbols && precedence > UnaryOperatorPrecedence)
83 tokens.emplace_back(BraceToken, ")");
84 return OtherSymbolResult;
85 }
86 }
87
88 if (GetFunction())
89 {
90 // If the pointer has a value of 0, check if it points to a valid address by
91 // 1. If the binary is relocatable, assign the pointer as nullptr
92 // 2. else, check if the constant zero which being referenced is a pointer(display as symbol) or not(display as nullptr)
93 if(val == 0x0 && type && (type->GetClass() == PointerTypeClass))
94 {
95 if (GetFunction()->GetView()->IsRelocatable())
96 {
97 if (symbolDisplay == DereferenceNonDataSymbols)
98 {
99 if (precedence > UnaryOperatorPrecedence)
100 tokens.emplace_back(BraceToken, "(");
101 tokens.emplace_back(OperationToken, "*");
102 }
103 tokens.emplace_back(CodeSymbolToken, InstructionAddressTokenContext, "nullptr", instr.address, val);
104 if (symbolDisplay == DereferenceNonDataSymbols && precedence > UnaryOperatorPrecedence)
105 tokens.emplace_back(BraceToken, ")");
106 return OtherSymbolResult;
107 }
108
109 auto arch = GetHighLevelILFunction()->GetArchitecture();
110 auto refs = GetHighLevelILFunction()->GetFunction()->GetConstantsReferencedByInstructionIfAvailable(
111 arch, instr.address);
112 bool constantZeroBeingReferencedIsPointer = false;
113
114 for (const BNConstantReference& ref : refs)
115 if (ref.value == 0x0 && ref.pointer)
116 constantZeroBeingReferencedIsPointer = true;
117 if (!constantZeroBeingReferencedIsPointer)
118 {

Callers 1

GetExprTextMethod · 0.45

Calls 14

GetClassMethod · 0.80
IsConstMethod · 0.80
GetChildTypeMethod · 0.80
IsRelocatableMethod · 0.80
GetMaximumSymbolWidthMethod · 0.80
GetTypeMethod · 0.45
GetWidthMethod · 0.45
GetViewMethod · 0.45
valueMethod · 0.45
GetArchitectureMethod · 0.45

Tested by

no test coverage detected