From cc1e85a4a8b2001f9fd6cf91b93fb39abef3a0e2 Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Wed, 4 Aug 2021 11:17:40 -0400 Subject: platforms: specify platform types and add bvt platform callbacks --- binaryviewtype.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'binaryviewtype.cpp') diff --git a/binaryviewtype.cpp b/binaryviewtype.cpp index b49191f8..3e0feae2 100644 --- a/binaryviewtype.cpp +++ b/binaryviewtype.cpp @@ -197,6 +197,23 @@ Ref BinaryViewType::GetPlatform(uint32_t id, Architecture* arch) } +void BinaryViewType::RegisterPlatformRecognizer(uint64_t id, BNEndianness endian, const std::function(BinaryView* view, Metadata* metadata)>& callback) +{ + PlatformRecognizerFunction* ctxt = new PlatformRecognizerFunction; + ctxt->action = callback; + BNRegisterPlatformRecognizerForViewType(m_object, id, endian, PlatformRecognizerCallback, ctxt); +} + + +Ref BinaryViewType::RecognizePlatform(uint64_t id, BNEndianness endian, BinaryView* view, Metadata* metadata) +{ + BNPlatform* platform = BNRecognizePlatformForViewType(m_object, id, endian, view->GetObject(), metadata->GetObject()); + if (!platform) + return nullptr; + return new Platform(platform); +} + + string BinaryViewType::GetName() { char* contents = BNGetBinaryViewTypeName(m_object); @@ -244,6 +261,18 @@ void BinaryViewType::BinaryViewEventCallback(void* ctxt, BNBinaryView* view) } +BNPlatform* BinaryViewType::PlatformRecognizerCallback(void* ctxt, BNBinaryView* view, BNMetadata* metadata) +{ + PlatformRecognizerFunction* callback = (PlatformRecognizerFunction*) ctxt; + Ref viewObject = new BinaryView(BNNewViewReference(view)); + Ref metadataObject = new Metadata(BNNewMetadataReference(metadata)); + Ref result = callback->action(viewObject, metadataObject); + if (!result) + return nullptr; + return BNNewPlatformReference(result->GetObject()); +} + + CoreBinaryViewType::CoreBinaryViewType(BNBinaryViewType* type): BinaryViewType(type) { } -- cgit v1.3.1