From 6e0806b4d18e456ebfb1d1d45b2ccc55713309c8 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 3 Oct 2025 00:31:32 -0400 Subject: Add DecodeWithContext method to Transform API layers. --- transform.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'transform.cpp') diff --git a/transform.cpp b/transform.cpp index 468cc0f2..735fb1b9 100644 --- a/transform.cpp +++ b/transform.cpp @@ -107,6 +107,18 @@ bool Transform::EncodeCallback( } +bool Transform::DecodeWithContextCallback(void* ctxt, BNTransformContext* context, BNTransformParameter* params, size_t paramCount) +{ + map paramMap; + for (size_t i = 0; i < paramCount; i++) + paramMap[params[i].name] = DataBuffer(BNDuplicateDataBuffer(params[i].value)); + + CallbackRef xform(ctxt); + Ref contextRef = new TransformContext(BNNewTransformContextReference(context)); + return xform->DecodeWithContext(contextRef, paramMap); +} + + bool Transform::CanDecodeCallback(void* ctxt, BNBinaryView* input) { CallbackRef xform(ctxt); @@ -150,6 +162,7 @@ void Transform::Register(Transform* xform) callbacks.freeParameters = FreeParametersCallback; callbacks.decode = DecodeCallback; callbacks.encode = EncodeCallback; + callbacks.decodeWithContext = DecodeWithContextCallback; callbacks.canDecode = CanDecodeCallback; xform->AddRefForRegistration(); xform->m_object = BNRegisterTransformTypeWithCapabilities(xform->m_typeForRegister, xform->m_capabilitiesForRegister, @@ -199,6 +212,12 @@ bool Transform::SupportsDetection() const } +bool Transform::SupportsContext() const +{ + return BNTransformSupportsContext(m_object); +} + + string Transform::GetName() const { char* name = BNGetTransformName(m_object); @@ -246,6 +265,12 @@ bool Transform::Encode(const DataBuffer&, DataBuffer&, const map, const map&) +{ + return false; +} + + bool Transform::CanDecode(Ref input) const { return false; @@ -310,6 +335,23 @@ bool CoreTransform::Encode(const DataBuffer& input, DataBuffer& output, const ma } +bool CoreTransform::DecodeWithContext(Ref context, const map& params) +{ + BNTransformParameter* list = new BNTransformParameter[params.size()]; + size_t idx = 0; + for (auto& i : params) + { + list[idx].name = i.first.c_str(); + list[idx++].value = i.second.GetBufferObject(); + } + + bool result = BNDecodeWithContext(m_object, context->GetObject(), list, idx); + + delete[] list; + return result; +} + + bool CoreTransform::CanDecode(Ref input) const { return BNCanDecode(m_object, input->GetObject()); -- cgit v1.3.1