Remove the elfio reader from the PluginData class, use it when it's needed

This commit is contained in:
Maschell
2020-06-03 18:34:31 +02:00
parent 1917ff9fb4
commit 2b517b5699
8 changed files with 46 additions and 97 deletions

View File

@@ -6,7 +6,6 @@ PluginData::PluginData(const PluginData &obj) {
this->heapHandle = obj.heapHandle;
this->memoryType = obj.memoryType;
this->length = obj.length;
loadReader();
}
void PluginData::freeMemory() {
@@ -30,26 +29,6 @@ void PluginData::freeMemory() {
PluginData::PluginData(std::vector<uint8_t> buffer) : PluginData(buffer, 0, eMemTypeMEM2) {
}
void PluginData::loadReader() {
if (this->buffer == NULL) {
this->reader = std::nullopt;
} else {
elfio *nReader = new elfio;
if (nReader != NULL && nReader->load((char *) this->buffer, length)) {
DEBUG_FUNCTION_LINE("Loading was okay");
this->reader = nReader;
} else {
if (nReader) {
delete nReader;
nReader = NULL;
}
DEBUG_FUNCTION_LINE("Loading failed");
this->reader = std::nullopt;
}
}
}
PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
heapHandle(heapHandle),
memoryType(memoryType),
@@ -78,7 +57,6 @@ PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMe
this->buffer = data_copy;
break;
}
loadReader();
}
std::optional<PluginData> PluginData::createFromExistingData(const void *buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length) {