Fix Python parsing with input 'bytes'

This commit is contained in:
rthomas
2019-11-28 07:53:27 +01:00
parent ca4e6148fe
commit b0e480c9f2
2 changed files with 45 additions and 19 deletions
+17 -2
View File
@@ -23,7 +23,20 @@ namespace LIEF {
template<>
void create<Parser>(py::module& m) {
m.def("parse",
m.def("parse",
[] (py::bytes bytes, const std::string& name) {
std::string raw_str = bytes;
std::vector<uint8_t> raw = {
std::make_move_iterator(std::begin(raw_str)),
std::make_move_iterator(std::end(raw_str))
};
return Parser::parse(std::move(raw), name);
},
"Parse the given binary and return a " RST_CLASS_REF(lief.Binary) " object",
"raw"_a, "name"_a = "",
py::return_value_policy::take_ownership);
m.def("parse",
static_cast<std::unique_ptr<Binary> (*) (const std::string&)>(&Parser::parse),
"Parse the given binary and return a " RST_CLASS_REF(lief.Binary) " object",
"filepath"_a,
@@ -36,6 +49,7 @@ void create<Parser>(py::module& m) {
py::return_value_policy::take_ownership);
m.def("parse",
[] (py::object byteio, const std::string& name) {
auto&& io = py::module::import("io");
@@ -65,7 +79,8 @@ void create<Parser>(py::module& m) {
std::string raw_str = static_cast<py::bytes>(rawio.attr("readall")());
std::vector<uint8_t> raw = {
std::make_move_iterator(std::begin(raw_str)),
std::make_move_iterator(std::end(raw_str))};
std::make_move_iterator(std::end(raw_str))
};
return Parser::parse(std::move(raw), name);
},