|
| 1 | +#include "objctypes.h" |
| 2 | +#include "binaryninjaapi.h" |
| 3 | + |
| 4 | +using namespace BinaryNinja; |
| 5 | + |
| 6 | +namespace { |
| 7 | + |
| 8 | +bool IsPointerToObjCObject(const Ref<Type>& type) |
| 9 | +{ |
| 10 | + if (!type || type->GetClass() != PointerTypeClass) |
| 11 | + return false; |
| 12 | + |
| 13 | + auto childType = type->GetChildType(); |
| 14 | + if (!childType || childType->GetClass() != NamedTypeReferenceClass) |
| 15 | + return false; |
| 16 | + |
| 17 | + auto namedType = childType->GetNamedTypeReference(); |
| 18 | + return namedType && namedType->GetName().GetString() == "objc_object"; |
| 19 | +} |
| 20 | + |
| 21 | +} // unnamed namespace |
| 22 | + |
| 23 | +PseudoObjCTypePrinter::PseudoObjCTypePrinter() : TypePrinter("Objective-C") {} |
| 24 | + |
| 25 | +std::vector<InstructionTextToken> PseudoObjCTypePrinter::GetTypeTokensBeforeName( |
| 26 | + Ref<Type> type, Ref<Platform> platform, uint8_t baseConfidence, Ref<Type> parentType, BNTokenEscapingType escaping) |
| 27 | +{ |
| 28 | + // It is idiomatic in Objective-C to use `id` rather than `objc_object*`. |
| 29 | + if (IsPointerToObjCObject(type)) |
| 30 | + return {InstructionTextToken {baseConfidence, TypeNameToken, "id"}}; |
| 31 | + |
| 32 | + return TypePrinter::GetDefault()->GetTypeTokensBeforeName(type, platform, baseConfidence, parentType, escaping); |
| 33 | +} |
| 34 | + |
| 35 | +std::vector<InstructionTextToken> PseudoObjCTypePrinter::GetTypeTokensAfterName( |
| 36 | + Ref<Type> type, Ref<Platform> platform, uint8_t baseConfidence, Ref<Type> parentType, BNTokenEscapingType escaping) |
| 37 | +{ |
| 38 | + return TypePrinter::GetDefault()->GetTypeTokensAfterName(type, platform, baseConfidence, parentType, escaping); |
| 39 | +} |
| 40 | + |
| 41 | +std::vector<TypeDefinitionLine> PseudoObjCTypePrinter::GetTypeLines(Ref<Type> type, const TypeContainer& types, |
| 42 | + const QualifiedName& name, int paddingCols, bool collapsed, BNTokenEscapingType escaping) |
| 43 | +{ |
| 44 | + return TypePrinter::GetDefault()->GetTypeLines(type, types, name, paddingCols, collapsed, escaping); |
| 45 | +} |
0 commit comments