MCPcopy Create free account
hub / github.com/lief-project/LIEF / from_stream

Function from_stream

api/python/src/pyParser.cpp:61–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59namespace LIEF::py {
60
61typing::OutputParser from_stream(std::unique_ptr<BinaryStream> stream) {
62 if (stream == nullptr) {
63 return nb::none();
64 }
65
66 #if LIEF_PE_SUPPORT
67 if (LIEF::PE::is_pe(*stream)) {
68 return nb::cast(LIEF::PE::Parser::parse(std::move(stream)));
69 }
70 #endif
71
72 #if LIEF_ELF_SUPPORT
73 if (LIEF::ELF::is_elf(*stream)) {
74 return nb::cast(LIEF::ELF::Parser::parse(std::move(stream)));
75 }
76 #endif
77
78 #if LIEF_MACHO_SUPPORT
79 if (LIEF::MachO::is_macho(*stream)) {
80 std::unique_ptr<LIEF::MachO::FatBinary> fat =
81 LIEF::MachO::Parser::parse(std::move(stream));
82
83 // NOTE(romain): We could nb::cast the fat binary object but
84 // to avoid a breaking change in the logic of parse() we return a
85 // `LIEF::MachO::Binary` as we did since the beginning.
86 //
87 // We could introduce this breaking change later though.
88 if (fat == nullptr || fat->empty()) {
89 return nb::none();
90 }
91 return nb::cast(fat->take(0));
92 }
93 #endif
94
95 #if LIEF_COFF_SUPPORT
96 if (LIEF::COFF::is_coff(*stream)) {
97 return nb::cast(LIEF::COFF::Parser::parse(std::move(stream)));
98 }
99 #endif
100
101 return nb::none();
102}
103
104template<>
105void create<Parser>(nb::module_& m) {

Callers 2

initMethod · 0.85
create<Parser>Function · 0.85

Calls 8

takeMethod · 0.80
is_peFunction · 0.50
castFunction · 0.50
parseFunction · 0.50
is_elfFunction · 0.50
is_machoFunction · 0.50
is_coffFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected