| 25 | |
| 26 | namespace LIEF::py::typing { |
| 27 | std::unique_ptr<BinaryStream> InputParser::into_stream() { |
| 28 | if (auto path_str = path_to_str(*this)) { |
| 29 | if (auto strm = VectorStream::from_file(*path_str)) { |
| 30 | return std::make_unique<VectorStream>(std::move(*strm)); |
| 31 | } |
| 32 | return nullptr; |
| 33 | } |
| 34 | |
| 35 | if (nb::isinstance<nb::bytes>(*this)) { |
| 36 | auto bytes = nb::cast<nb::bytes>(*this); |
| 37 | return std::make_unique<SpanStream>( |
| 38 | static_cast<const uint8_t*>(bytes.data()), bytes.size() |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | if (nb::isinstance<nb::list>(*this)) { |
| 43 | auto bytes = nb::cast<std::vector<uint8_t>>(*this); |
| 44 | return std::make_unique<VectorStream>(std::move(bytes)); |
| 45 | } |
| 46 | |
| 47 | if (auto stream = PyIOStream::from_python(*this)) { |
| 48 | return std::make_unique<PyIOStream>(std::move(*stream)); |
| 49 | } |
| 50 | |
| 51 | logging::log(logging::LEVEL::ERR, |
| 52 | "LIEF parser interface does not support this Python object: " + |
| 53 | type2str(*this)); |
| 54 | return nullptr; |
| 55 | } |
| 56 | } |
no test coverage detected