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

Method GetExprTextInternal

lang/c/pseudoc.cpp:538–2792  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

536
537
538void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, HighLevelILTokenEmitter& tokens,
539 DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement, optional<bool> signedHint)
540{
541 // The lambdas in this function are here to reduce stack frame size of this function. Without them,
542 // complex expression can cause the process to crash from a stack overflow.
543 auto exprGuard = tokens.SetCurrentExpr(instr);
544
545 if (settings && settings->IsOptionSet(ShowILTypes) && instr.GetType())
546 {
547 tokens.AppendOpenParen();
548 tokens.AppendOpenParen();
549 auto typeTokens = TypePrinter::GetDefault()->GetTypeTokens(
550 instr.GetType(),
551 GetArchitecture()->GetStandalonePlatform(),
552 QualifiedName()
553 );
554 for (auto& token: typeTokens)
555 {
556 tokens.Append(token);
557 }
558 tokens.AppendCloseParen();
559 tokens.Append(TextToken, " ");
560 }
561 if (settings && settings->IsOptionSet(ShowILOpcodes))
562 {
563 tokens.Append(OperationToken, "/*");
564 tokens.Append(OperationToken, fmt::format("{}", instr.operation));
565 tokens.Append(OperationToken, "*/");
566 tokens.Append(TextToken, " ");
567 }
568
569 auto function = m_highLevelIL->GetFunction();
570 if (instr.ast)
571 tokens.PrependCollapseIndicator(function, instr);
572
573 // ensure we claim the line address for top level instrs on a line
574 if (instr.operation != HLIL_BLOCK)
575 tokens.InitLine();
576
577 switch (instr.operation)
578 {
579 case HLIL_BLOCK:
580 [&]() {
581 const auto exprs = instr.GetBlockExprs<HLIL_BLOCK>();
582 bool needSeparator = false;
583 for (auto i = exprs.begin(); i != exprs.end(); ++i)
584 {
585 // Don't show void returns at the very end of the function when printing
586 // the root of an AST, as it is implicit and almost always omitted in
587 // normal source code.
588 auto next = i;
589 ++next;
590 if (instr.ast && (instr.exprIndex == GetHighLevelILFunction()->GetRootExpr().exprIndex)
591 && (exprs.size() > 1) && (next == exprs.end()) && ((*i).operation == HLIL_RET)
592 && ((*i).GetSourceExprs<HLIL_RET>().size() == 0))
593 continue;
594
595 // If the statement is one that contains additional blocks of code, insert a scope separator

Callers

nothing calls this directly

Calls 15

SetCurrentExprMethod · 0.80
AppendOpenParenMethod · 0.80
GetStandalonePlatformMethod · 0.80
AppendCloseParenMethod · 0.80
InitLineMethod · 0.80
GetRootExprMethod · 0.80
ScopeSeparatorMethod · 0.80
NewLineMethod · 0.80
BeginScopeMethod · 0.80
EndScopeMethod · 0.80

Tested by

no test coverage detected