summaryrefslogtreecommitdiff
path: root/lang/c/objctypes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lang/c/objctypes.cpp')
-rw-r--r--lang/c/objctypes.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/lang/c/objctypes.cpp b/lang/c/objctypes.cpp
new file mode 100644
index 00000000..83a097be
--- /dev/null
+++ b/lang/c/objctypes.cpp
@@ -0,0 +1,45 @@
+#include "objctypes.h"
+#include "binaryninjaapi.h"
+
+using namespace BinaryNinja;
+
+namespace {
+
+bool IsPointerToObjCObject(const Ref<Type>& type)
+{
+ if (!type || type->GetClass() != PointerTypeClass)
+ return false;
+
+ auto childType = type->GetChildType();
+ if (!childType || childType->GetClass() != NamedTypeReferenceClass)
+ return false;
+
+ auto namedType = childType->GetNamedTypeReference();
+ return namedType && namedType->GetName().GetString() == "objc_object";
+}
+
+} // unnamed namespace
+
+PseudoObjCTypePrinter::PseudoObjCTypePrinter() : TypePrinter("Objective-C") {}
+
+std::vector<InstructionTextToken> PseudoObjCTypePrinter::GetTypeTokensBeforeName(
+ Ref<Type> type, Ref<Platform> platform, uint8_t baseConfidence, Ref<Type> parentType, BNTokenEscapingType escaping)
+{
+ // It is idiomatic in Objective-C to use `id` rather than `objc_object*`.
+ if (IsPointerToObjCObject(type))
+ return {InstructionTextToken {baseConfidence, TypeNameToken, "id"}};
+
+ return TypePrinter::GetDefault()->GetTypeTokensBeforeName(type, platform, baseConfidence, parentType, escaping);
+}
+
+std::vector<InstructionTextToken> PseudoObjCTypePrinter::GetTypeTokensAfterName(
+ Ref<Type> type, Ref<Platform> platform, uint8_t baseConfidence, Ref<Type> parentType, BNTokenEscapingType escaping)
+{
+ return TypePrinter::GetDefault()->GetTypeTokensAfterName(type, platform, baseConfidence, parentType, escaping);
+}
+
+std::vector<TypeDefinitionLine> PseudoObjCTypePrinter::GetTypeLines(Ref<Type> type, const TypeContainer& types,
+ const QualifiedName& name, int paddingCols, bool collapsed, BNTokenEscapingType escaping)
+{
+ return TypePrinter::GetDefault()->GetTypeLines(type, types, name, paddingCols, collapsed, escaping);
+}