From 06a9d7e5afee7fd1feb1cd6265672f7c24753b24 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sat, 4 Nov 2023 10:30:56 +0100 Subject: [PATCH] fxos: make Binary::OSAnalysis const (slight hack) --- include/fxos/binary.h | 4 ++-- lib/binary.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/fxos/binary.h b/include/fxos/binary.h index b385156..f6794da 100644 --- a/include/fxos/binary.h +++ b/include/fxos/binary.h @@ -49,7 +49,7 @@ struct Binary /* OS analysis (performed on-demand). Returns the new or cached OS analysis results, nullptr if analysis failed. */ - OS *OSAnalysis(bool force = false); + OS *OSAnalysis(bool force = false) const; // TODO: Platform information in a binary // TODO: Implement OS analysis @@ -82,7 +82,7 @@ private: VirtualSpace m_vspace; /* OS analysis results */ - std::unique_ptr m_os; + mutable std::unique_ptr m_os; /* All binary objects */ std::multimap> m_objects; diff --git a/lib/binary.cpp b/lib/binary.cpp index 7dc02f8..8954fb9 100644 --- a/lib/binary.cpp +++ b/lib/binary.cpp @@ -44,10 +44,14 @@ void Binary::deserialize(BSON const &b) } } -OS *Binary::OSAnalysis(bool force) +OS *Binary::OSAnalysis(bool force) const { if(!m_os || force) { - m_os = std::make_unique(m_vspace); + /* We break constness a little bit here. We allow access to the OS + analysis for const Binary, even though it uses the VirtualSpace and + technically AbstractMemory allows implementations to modify the + memory in response to reads. */ + m_os = std::make_unique(const_cast(m_vspace)); /* We don't keep an OS analysis result that failed */ if(m_os->type == OS::UNKNOWN) m_os = nullptr;