Skip to content

Commit 12c5281

Browse files
committed
[ObjC] Display selectors as @selector(...)
1 parent 6143812 commit 12c5281

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lang/c/pseudoobjc.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "highlevelilinstruction.h"
55
#include <optional>
66
#include <string>
7+
#include <string_view>
78
#include <vector>
89

910
using namespace BinaryNinja;
@@ -350,6 +351,11 @@ void PseudoObjCFunction::GetExpr_CONST_PTR(const BinaryNinja::HighLevelILInstruc
350351
return;
351352
}
352353

354+
if (shortName.rfind("sel_", 0) == 0
355+
&& GetExpr_Selector(
356+
std::string_view(shortName).substr(4), constant, instr, tokens, settings, precedence, statement))
357+
return;
358+
353359
DataVariable variable {};
354360
auto hasVariable = GetFunction()->GetView()->GetDataVariableAtAddress(constant, variable);
355361
if (!hasVariable)
@@ -393,6 +399,21 @@ bool PseudoObjCFunction::GetExpr_OBJC_CLASS(const Symbol& symbol, uint64_t const
393399
return true;
394400
}
395401

402+
bool PseudoObjCFunction::GetExpr_Selector(std::string_view selector, uint64_t constant,
403+
const BinaryNinja::HighLevelILInstruction& instr, BinaryNinja::HighLevelILTokenEmitter& tokens,
404+
BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement)
405+
{
406+
if (selector.empty())
407+
return false;
408+
409+
tokens.Append(KeywordToken, "@selector");
410+
tokens.AppendOpenParen();
411+
tokens.Append(DataSymbolToken, ConstDataTokenContext, std::string(selector), instr.address, constant);
412+
tokens.AppendCloseParen();
413+
414+
return true;
415+
}
416+
396417
bool PseudoObjCFunction::GetExpr_NSConstantString(Ref<Type> type, uint64_t constant,
397418
const BinaryNinja::HighLevelILInstruction& instr, BinaryNinja::HighLevelILTokenEmitter& tokens,
398419
BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement)

lang/c/pseudoobjc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class PseudoObjCFunction : public PseudoCFunction
3131
bool GetExpr_OBJC_CLASS(const BinaryNinja::Symbol& symbol, uint64_t constant,
3232
const BinaryNinja::HighLevelILInstruction& expr, BinaryNinja::HighLevelILTokenEmitter& tokens,
3333
BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement);
34+
bool GetExpr_Selector(std::string_view selector, uint64_t constant,
35+
const BinaryNinja::HighLevelILInstruction& expr, BinaryNinja::HighLevelILTokenEmitter& tokens,
36+
BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement);
3437
bool GetExpr_NSConstantString(BinaryNinja::Ref<BinaryNinja::Type> type, uint64_t constant,
3538
const BinaryNinja::HighLevelILInstruction& expr, BinaryNinja::HighLevelILTokenEmitter& tokens,
3639
BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement);

0 commit comments

Comments
 (0)