From 879c4c5b3b2618d2628f2509d1dc7ab4464b565a Mon Sep 17 00:00:00 2001 From: Romain Thomas Date: Fri, 10 Nov 2023 18:38:29 +0100 Subject: [PATCH] More span --- api/c/MachO/LoadCommand.cpp | 2 +- api/python/src/MachO/objects/pyLoadCommand.cpp | 5 +++-- include/LIEF/MachO/CodeSignature.hpp | 1 - include/LIEF/MachO/DylibCommand.hpp | 1 - include/LIEF/MachO/ExportInfo.hpp | 1 - include/LIEF/MachO/LoadCommand.hpp | 5 ++++- src/MachO/LoadCommand.cpp | 5 ----- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/api/c/MachO/LoadCommand.cpp b/api/c/MachO/LoadCommand.cpp index 7b3197156a..5952ca899e 100644 --- a/api/c/MachO/LoadCommand.cpp +++ b/api/c/MachO/LoadCommand.cpp @@ -27,7 +27,7 @@ void init_c_commands(Macho_Binary_t* c_binary, Binary* binary) { LoadCommand& cmd = commands[i]; c_binary->commands[i] = static_cast(malloc(sizeof(Macho_Command_t))); - const std::vector& cmd_content = cmd.data(); + const span cmd_content = cmd.data(); auto* content = static_cast(malloc(cmd_content.size() * sizeof(uint8_t))); std::copy( std::begin(cmd_content), diff --git a/api/python/src/MachO/objects/pyLoadCommand.cpp b/api/python/src/MachO/objects/pyLoadCommand.cpp index 8fe240d2ce..0987849371 100644 --- a/api/python/src/MachO/objects/pyLoadCommand.cpp +++ b/api/python/src/MachO/objects/pyLoadCommand.cpp @@ -17,11 +17,13 @@ #include #include #include "nanobind/extra/memoryview.hpp" +#include "nanobind/utils.hpp" #include "LIEF/MachO/LoadCommand.hpp" #include "MachO/pyMachO.hpp" + namespace LIEF::MachO::py { template<> @@ -43,8 +45,7 @@ void create(nb::module_& m) { .def_prop_rw("data", [] (const LoadCommand& cmd) { - const LoadCommand::raw_t& content = cmd.data(); - return nb::memoryview::from_memory(content.data(), content.size()); + return nb::to_memoryview(cmd.data()); }, nb::overload_cast(&LoadCommand::data), "Command's data"_doc) diff --git a/include/LIEF/MachO/CodeSignature.hpp b/include/LIEF/MachO/CodeSignature.hpp index f9208a8f9c..12c6fc622d 100644 --- a/include/LIEF/MachO/CodeSignature.hpp +++ b/include/LIEF/MachO/CodeSignature.hpp @@ -68,7 +68,6 @@ class LIEF_API CodeSignature : public LoadCommand { ~CodeSignature() override; - void accept(Visitor& visitor) const override; std::ostream& print(std::ostream& os) const override; diff --git a/include/LIEF/MachO/DylibCommand.hpp b/include/LIEF/MachO/DylibCommand.hpp index 1365c34e40..8cccb6e832 100644 --- a/include/LIEF/MachO/DylibCommand.hpp +++ b/include/LIEF/MachO/DylibCommand.hpp @@ -109,7 +109,6 @@ class LIEF_API DylibCommand : public LoadCommand { std::ostream& print(std::ostream& os) const override; - void accept(Visitor& visitor) const override; static bool classof(const LoadCommand* cmd); diff --git a/include/LIEF/MachO/ExportInfo.hpp b/include/LIEF/MachO/ExportInfo.hpp index 0a8cf6762f..a221f6b4f2 100644 --- a/include/LIEF/MachO/ExportInfo.hpp +++ b/include/LIEF/MachO/ExportInfo.hpp @@ -93,7 +93,6 @@ class LIEF_API ExportInfo : public Object { ~ExportInfo() override; - void accept(Visitor& visitor) const override; LIEF_API friend std::ostream& operator<<(std::ostream& os, const ExportInfo& export_info); diff --git a/include/LIEF/MachO/LoadCommand.hpp b/include/LIEF/MachO/LoadCommand.hpp index af7d929f52..b08939e83b 100644 --- a/include/LIEF/MachO/LoadCommand.hpp +++ b/include/LIEF/MachO/LoadCommand.hpp @@ -22,6 +22,7 @@ #include "LIEF/types.hpp" #include "LIEF/Object.hpp" #include "LIEF/visibility.h" +#include "LIEF/span.hpp" #include "LIEF/MachO/enums.hpp" @@ -61,7 +62,9 @@ class LIEF_API LoadCommand : public Object { uint32_t size() const; //! Raw command - const raw_t& data() const; + span data() const { + return original_data_; + } //! Offset of the command within the *Load Command Table* uint64_t command_offset() const; diff --git a/src/MachO/LoadCommand.cpp b/src/MachO/LoadCommand.cpp index 9dc429e1d9..0e638c92cc 100644 --- a/src/MachO/LoadCommand.cpp +++ b/src/MachO/LoadCommand.cpp @@ -75,11 +75,6 @@ uint32_t LoadCommand::size() const { return size_; } -const LoadCommand::raw_t& LoadCommand::data() const { - return original_data_; -} - - uint64_t LoadCommand::command_offset() const { return command_offset_; }