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

Function ApplySymbol

view/sharedcache/core/Utility.cpp:68–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68void ApplySymbol(Ref<BinaryView> view, Ref<TypeLibrary> typeLib, Ref<Symbol> symbol, Ref<Type> type)
69{
70 auto symbolAddress = symbol->GetAddress();
71 auto symbolName = symbol->GetFullName();
72
73 // Sometimes the symbol will be duplicated, so lets not do this work again.
74 if (view->GetSymbolByAddress(symbolAddress))
75 return;
76
77 // Define the symbol!
78 view->DefineAutoSymbol(symbol);
79
80 // Try and pull a type from a type library to apply at the symbol location.
81 // The type library type will take precedence over the passed in type.
82 Ref<Type> selectedType = type;
83 if (typeLib)
84 selectedType = view->ImportTypeLibraryObject(typeLib, {symbolName});
85
86 Ref<Function> func = nullptr;
87 if (symbol->GetType() == FunctionSymbol)
88 {
89 Ref<Platform> targetPlatform = view->GetDefaultPlatform();
90 // Make sure to check for already added function from the function table.
91 // Unless we have retrieved a type here we don't need to make a new function.
92 func = view->GetAnalysisFunction(targetPlatform, symbolAddress);
93 if (!func || selectedType)
94 func = view->AddFunctionForAnalysis(targetPlatform, symbolAddress, false, selectedType);
95 }
96 else
97 {
98 // Other symbol types can just use this, they don't need to worry about linear sweep removing them.
99 view->DefineAutoSymbolAndVariableOrFunction(view->GetDefaultPlatform(), symbol, selectedType);
100 }
101
102 if (func)
103 {
104 // objective c type adjustment stuff.
105 if (symbolName == "_objc_msgSend")
106 {
107 func->SetHasVariableArguments(false);
108 }
109 else if (symbolName.find("_objc_retain_x") != std::string::npos
110 || symbolName.find("_objc_release_x") != std::string::npos)
111 {
112 auto x = symbolName.rfind('x');
113 auto num = symbolName.substr(x + 1);
114
115 std::vector<FunctionParameter> callTypeParams;
116 auto cc = view->GetDefaultArchitecture()->GetCallingConventionByName("apple-arm64-objc-fast-arc-" + num);
117
118 if (auto idType = view->GetTypeByName({"id"}))
119 {
120 callTypeParams.emplace_back("obj", idType, true, Variable());
121 auto funcType = Type::FunctionType(idType, cc, callTypeParams);
122 func->SetUserType(funcType);
123 }
124 else
125 {

Callers 1

ApplyHeaderMethod · 0.85

Calls 15

GetFullNameMethod · 0.80
GetSymbolByAddressMethod · 0.80
DefineAutoSymbolMethod · 0.80
GetDefaultPlatformMethod · 0.80
GetAnalysisFunctionMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected