Addned functions to load plugin meta information from a path or buffer

This commit is contained in:
Maschell 2020-05-17 20:50:31 +02:00
parent 3d642c25d0
commit a2816cea61
2 changed files with 30 additions and 1 deletions

View File

@ -34,13 +34,36 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
DEBUG_FUNCTION_LINE("Can't find or process ELF file"); DEBUG_FUNCTION_LINE("Can't find or process ELF file");
return std::nullopt; return std::nullopt;
} }
auto reader = readerOpt.value(); return loadPlugin(readerOpt.value());
}
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const std::string filePath) {
auto reader = new elfio;
if (reader == NULL || !reader->load(filePath)) {
DEBUG_FUNCTION_LINE("Can't find or process ELF file\n");
delete reader;
return std::nullopt;
}
return loadPlugin(reader);
}
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(char *buffer, size_t size) {
auto reader = new elfio;
if (reader == NULL || !reader->load(buffer, size)) {
DEBUG_FUNCTION_LINE("Can't find or process ELF file\n");
delete reader;
return std::nullopt;
}
return loadPlugin(reader);
}
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(elfio *reader) {
DEBUG_FUNCTION_LINE("Found elfio reader"); DEBUG_FUNCTION_LINE("Found elfio reader");
size_t pluginSize = 0; size_t pluginSize = 0;
PluginMetaInformation pluginInfo; PluginMetaInformation pluginInfo;
uint32_t sec_num = reader->sections.size(); uint32_t sec_num = reader->sections.size();
DEBUG_FUNCTION_LINE("%d number of sections", sec_num); DEBUG_FUNCTION_LINE("%d number of sections", sec_num);

View File

@ -26,4 +26,10 @@
class PluginMetaInformationFactory { class PluginMetaInformationFactory {
public: public:
static std::optional<PluginMetaInformation> loadPlugin(const PluginData &pluginData); static std::optional<PluginMetaInformation> loadPlugin(const PluginData &pluginData);
static std::optional<PluginMetaInformation> loadPlugin(const std::string filePath);
static std::optional<PluginMetaInformation> loadPlugin(char *buffer, size_t size);
static std::optional<PluginMetaInformation> loadPlugin(elfio *reader);
}; };