Skip to content

Commit

Permalink
Enable creating a RPathCommand
Browse files Browse the repository at this point in the history
Resolve #1078
  • Loading branch information
romainthomas committed Nov 2, 2024
1 parent ee4e12a commit 86e1769
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api/python/lief/MachO.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,8 @@ class ParserConfig:
class RPathCommand(LoadCommand):
path: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def create(path: str) -> Optional[lief.MachO.RPathCommand]: ...

class Relocation(lief.Relocation):
class ORIGIN:
Expand Down
6 changes: 6 additions & 0 deletions api/python/src/MachO/objects/pyRPathCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string>
#include <sstream>
#include <nanobind/stl/string.h>
#include <nanobind/stl/unique_ptr.h>

#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/RPathCommand.hpp"
Expand All @@ -28,6 +29,11 @@ template<>
void create<RPathCommand>(nb::module_& m) {
nb::class_<RPathCommand, LoadCommand>(m, "RPathCommand")

.def_static("create", &RPathCommand::create,
R"doc(Create a new RPathCommand for the provided ``path``)doc"_doc,
"path"_a
)

.def_prop_rw("path",
nb::overload_cast<>(&RPathCommand::path, nb::const_),
nb::overload_cast<std::string>(&RPathCommand::path),
Expand Down
6 changes: 6 additions & 0 deletions include/LIEF/MachO/RPathCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct rpath_command;
class LIEF_API RPathCommand : public LoadCommand {
public:
RPathCommand() = default;
RPathCommand(std::string path);
RPathCommand(const details::rpath_command& rpathCmd);

RPathCommand& operator=(const RPathCommand& copy) = default;
Expand All @@ -45,6 +46,11 @@ class LIEF_API RPathCommand : public LoadCommand {
return std::unique_ptr<RPathCommand>(new RPathCommand(*this));
}

/// Create a new RPath command for the provided `path`
static std::unique_ptr<RPathCommand> create(std::string path) {
return std::unique_ptr<RPathCommand>(new RPathCommand(std::move(path)));
}

~RPathCommand() override = default;

/// The rpath value as a string
Expand Down
11 changes: 9 additions & 2 deletions src/MachO/RPathCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iomanip>

#include "LIEF/Visitor.hpp"
#include "LIEF/utils.hpp"

#include "LIEF/MachO/RPathCommand.hpp"
#include "MachO/Structures.hpp"

namespace LIEF {
namespace MachO {

RPathCommand::RPathCommand(std::string path) :
LoadCommand::LoadCommand(LoadCommand::TYPE::RPATH, 0),
path_(std::move(path))
{
size_ = align(sizeof(details::rpath_command) + path.size() + 1, sizeof(uint64_t));
original_data_.resize(size_);
}

RPathCommand::RPathCommand(const details::rpath_command& rpath) :
LoadCommand::LoadCommand{LoadCommand::TYPE(rpath.cmd), rpath.cmdsize}
{}
Expand Down

0 comments on commit 86e1769

Please sign in to comment.