| 66 | } |
| 67 | |
| 68 | void 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 | { |
no test coverage detected