Use DEBUG_FUNCTION_LINE_ERR on error.

This commit is contained in:
Maschell
2022-04-22 22:55:53 +02:00
parent 6f607cfec3
commit 48eb915a70
15 changed files with 128 additions and 104 deletions

View File

@@ -4,16 +4,18 @@
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
if (data == nullptr) {
DEBUG_FUNCTION_LINE_ERR("data was NULL");
return nullptr;
}
if (functionName == nullptr) {
DEBUG_FUNCTION_LINE_ERR("functionName was NULL");
return nullptr;
}
dyn_linking_function_t *result = nullptr;
for (auto &curEntry : data->functions) {
if (strlen(curEntry.functionName) == 0) {
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.");
DEBUG_FUNCTION_LINE_ERR("Failed to add function name, it's too long.");
return nullptr;
}
strncpy(curEntry.functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
@@ -44,7 +46,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
for (auto &curEntry : data->imports) {
if (strlen(curEntry.importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.");
DEBUG_FUNCTION_LINE_ERR("Failed to add Import, it's too long.");
return nullptr;
}
strncpy(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
@@ -71,13 +73,13 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
const std::string &name, const std::shared_ptr<ImportRPLInformation> &rplInfo) {
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo->getName().c_str(), rplInfo->isData());
if (importInfoGbl == nullptr) {
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.", DYN_LINK_IMPORT_LIST_LENGTH);
DEBUG_FUNCTION_LINE_ERR("Getting import info failed. Probably maximum of %d rpl files to import reached.", DYN_LINK_IMPORT_LIST_LENGTH);
return false;
}
dyn_linking_function_t *functionInfo = DynamicLinkingHelper::getOrAddFunctionEntryByName(linking_data, name.c_str());
if (functionInfo == nullptr) {
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.", DYN_LINK_FUNCTION_LIST_LENGTH);
DEBUG_FUNCTION_LINE_ERR("Getting import info failed. Probably maximum of %d function to be relocated reached.", DYN_LINK_FUNCTION_LIST_LENGTH);
return false;
}
@@ -100,6 +102,6 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *lin
curEntry->importEntry = importInfo;
return true;
}
DEBUG_FUNCTION_LINE("Failed to find empty slot for saving relocations entry. We ned more than %d slots.", linking_entry_length);
DEBUG_FUNCTION_LINE_ERR("Failed to find empty slot for saving relocations entry. We need more than %d slots.", linking_entry_length);
return false;
}

View File

@@ -15,7 +15,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
auto pluginName = plugin->getMetaInformation()->getName();
if (plugin_count >= MAXIMUM_PLUGINS - 1) {
DEBUG_FUNCTION_LINE("Maximum of %d plugins reached. %s won't be loaded!", MAXIMUM_PLUGINS, pluginName.c_str());
DEBUG_FUNCTION_LINE_ERR("Maximum of %d plugins reached. %s won't be loaded!", MAXIMUM_PLUGINS, pluginName.c_str());
return false;
}
// Copy data to global struct.
@@ -28,37 +28,37 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
auto plugin_meta_data = &plugin_data->meta;
if (pluginMetaInfo->getName().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: name will be truncated.");
DEBUG_FUNCTION_LINE_ERR("Warning: name will be truncated.");
}
strncpy(plugin_meta_data->name, pluginMetaInfo->getName().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
if (pluginMetaInfo->getAuthor().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: author will be truncated.");
DEBUG_FUNCTION_LINE_ERR("Warning: author will be truncated.");
}
strncpy(plugin_meta_data->author, pluginMetaInfo->getAuthor().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
if (pluginMetaInfo->getVersion().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: version will be truncated.");
DEBUG_FUNCTION_LINE_ERR("Warning: version will be truncated.");
}
strncpy(plugin_meta_data->version, pluginMetaInfo->getVersion().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
if (pluginMetaInfo->getLicense().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: license will be truncated.");
DEBUG_FUNCTION_LINE_ERR("Warning: license will be truncated.");
}
strncpy(plugin_meta_data->license, pluginMetaInfo->getLicense().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
if (pluginMetaInfo->getBuildTimestamp().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: build timestamp will be truncated.");
DEBUG_FUNCTION_LINE_ERR("Warning: build timestamp will be truncated.");
}
strncpy(plugin_meta_data->buildTimestamp, pluginMetaInfo->getBuildTimestamp().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
if (pluginMetaInfo->getDescription().size() >= MAXIMUM_PLUGIN_DESCRIPTION_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: description will be truncated.");
DEBUG_FUNCTION_LINE("%s", pluginMetaInfo->getDescription().c_str());
DEBUG_FUNCTION_LINE_ERR("Warning: description will be truncated.");
DEBUG_FUNCTION_LINE_ERR("%s", pluginMetaInfo->getDescription().c_str());
}
strncpy(plugin_meta_data->descripion, pluginMetaInfo->getDescription().c_str(), MAXIMUM_PLUGIN_DESCRIPTION_LENGTH - 1);
if (pluginMetaInfo->getStorageId().length() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: plugin storage id will be truncated.");
DEBUG_FUNCTION_LINE_ERR("Warning: plugin storage id will be truncated.");
}
strncpy(plugin_meta_data->storageId, pluginMetaInfo->getStorageId().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
@@ -70,7 +70,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
auto relocationData = pluginInfo->getRelocationDataList();
for (auto &reloc : relocationData) {
if (!DynamicLinkingHelper::addReloationEntry(&(pluginInformation->linking_data), plugin_data->info.linking_entries, PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) {
DEBUG_FUNCTION_LINE("Failed to add a relocation entry");
DEBUG_FUNCTION_LINE_ERR("Failed to add a relocation entry");
return false;
}
}
@@ -79,16 +79,16 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
auto hook_data_list = pluginInfo->getHookDataList();
if (function_data_list.size() > MAXIMUM_FUNCTION_PER_PLUGIN) {
DEBUG_FUNCTION_LINE("Plugin %s would replace to many function (%d, maximum is %d). It won't be loaded.", pluginName.c_str(), function_data_list.size(), MAXIMUM_FUNCTION_PER_PLUGIN);
DEBUG_FUNCTION_LINE_ERR("Plugin %s would replace to many function (%d, maximum is %d). It won't be loaded.", pluginName.c_str(), function_data_list.size(), MAXIMUM_FUNCTION_PER_PLUGIN);
return false;
}
if (hook_data_list.size() > MAXIMUM_HOOKS_PER_PLUGIN) {
DEBUG_FUNCTION_LINE("Plugin %s would set too many hooks (%d, maximum is %d). It won't be loaded.", pluginName.c_str(), hook_data_list.size(), MAXIMUM_HOOKS_PER_PLUGIN);
DEBUG_FUNCTION_LINE_ERR("Plugin %s would set too many hooks (%d, maximum is %d). It won't be loaded.", pluginName.c_str(), hook_data_list.size(), MAXIMUM_HOOKS_PER_PLUGIN);
return false;
}
if (pluginName.length() > MAXIMUM_PLUGIN_NAME_LENGTH - 1) {
DEBUG_FUNCTION_LINE("Name for plugin %s was too long to be stored.", pluginName.c_str());
DEBUG_FUNCTION_LINE_ERR("Name for plugin %s was too long to be stored.", pluginName.c_str());
return false;
}
@@ -97,7 +97,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
for (auto &curFunction : pluginInfo->getFunctionDataList()) {
function_replacement_data_t *function_data = &plugin_data->info.functions[i];
if (strlen(curFunction->getName().c_str()) > MAXIMUM_FUNCTION_NAME_LENGTH - 1) {
DEBUG_FUNCTION_LINE("Could not add function \"%s\" for plugin \"%s\" function name is too long.", curFunction->getName().c_str(), pluginName.c_str());
DEBUG_FUNCTION_LINE_ERR("Could not add function \"%s\" for plugin \"%s\" function name is too long.", curFunction->getName().c_str(), pluginName.c_str());
continue;
}
@@ -145,7 +145,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
if (foundFreeSlot) {
auto *sectionInfo = &(plugin_data->info.sectionInfos[slot]);
if (curSection.first.length() > MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1) {
DEBUG_FUNCTION_LINE("Could not add section info \"%s\" for plugin \"%s\" section name is too long.", curSection.first.c_str(), pluginName.c_str());
DEBUG_FUNCTION_LINE_ERR("Could not add section info \"%s\" for plugin \"%s\" section name is too long.", curSection.first.c_str(), pluginName.c_str());
break;
}
strncpy(sectionInfo->name, curSection.first.c_str(), MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1);
@@ -153,7 +153,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
sectionInfo->size = curSection.second->getSize();
} else {
DEBUG_FUNCTION_LINE("Failed to store SectionInfos");
DEBUG_FUNCTION_LINE_ERR("Failed to store SectionInfos");
return false;
}
}
@@ -171,7 +171,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
char *stringTable = (char *) MEMAllocFromExpHeapEx(heapHandle, funcSymStringLen, 0x4);
if (stringTable == nullptr) {
DEBUG_FUNCTION_LINE("Failed alloc memory to store string table for function symbol data");
DEBUG_FUNCTION_LINE_ERR("Failed alloc memory to store string table for function symbol data");
return false;
}
memset(stringTable, 0, funcSymStringLen);
@@ -180,7 +180,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
if (entryTable == nullptr) {
MEMFreeToExpHeap((MEMHeapHandle) heapHandle, stringTable);
free(stringTable);
DEBUG_FUNCTION_LINE("Failed alloc memory to store function symbol data");
DEBUG_FUNCTION_LINE_ERR("Failed alloc memory to store function symbol data");
return false;
}
DEBUG_FUNCTION_LINE("Allocated %d for the function symbol data", entryCount * sizeof(plugin_function_symbol_data_t));
@@ -220,7 +220,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPlugins(plugin_information_t *pluginInformation) {
std::vector<std::shared_ptr<PluginContainer>> result;
if (pluginInformation == nullptr) {
DEBUG_FUNCTION_LINE("pluginInformation == nullptr");
DEBUG_FUNCTION_LINE_ERR("pluginInformation == nullptr");
return result;
}
DCFlushRange((void *) pluginInformation, sizeof(plugin_information_t));
@@ -228,7 +228,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
int32_t plugin_count = pluginInformation->number_used_plugins;
if (plugin_count > MAXIMUM_PLUGINS) {
DEBUG_FUNCTION_LINE("pluginInformation->plugin_count was bigger then allowed. %d > %d. Limiting to %d", plugin_count, MAXIMUM_PLUGINS, MAXIMUM_PLUGINS);
DEBUG_FUNCTION_LINE_ERR("pluginInformation->plugin_count was bigger then allowed. %d > %d. Limiting to %d", plugin_count, MAXIMUM_PLUGINS, MAXIMUM_PLUGINS);
plugin_count = MAXIMUM_PLUGINS;
}
for (int32_t i = 0; i < plugin_count; i++) {
@@ -271,7 +271,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
uint32_t hookCount = plugin_data->info.number_used_hooks;
if (hookCount > MAXIMUM_HOOKS_PER_PLUGIN) {
DEBUG_FUNCTION_LINE("number_used_hooks was bigger then allowed. %d > %d. Limiting to %d", hookCount, MAXIMUM_HOOKS_PER_PLUGIN, MAXIMUM_HOOKS_PER_PLUGIN);
DEBUG_FUNCTION_LINE_ERR("number_used_hooks was bigger then allowed. %d > %d. Limiting to %d", hookCount, MAXIMUM_HOOKS_PER_PLUGIN, MAXIMUM_HOOKS_PER_PLUGIN);
hookCount = MAXIMUM_HOOKS_PER_PLUGIN;
}
@@ -288,7 +288,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
}
}
if (!storageHasId) {
DEBUG_FUNCTION_LINE("Plugin is using the storage API but has not set an ID");
DEBUG_FUNCTION_LINE_ERR("Plugin is using the storage API but has not set an ID");
continue;
}
@@ -296,7 +296,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
uint32_t functionReplaceCount = plugin_data->info.number_used_functions;
if (functionReplaceCount > MAXIMUM_FUNCTION_PER_PLUGIN) {
DEBUG_FUNCTION_LINE("number_used_functions was bigger then allowed. %d > %d. Limiting to %d", functionReplaceCount, MAXIMUM_FUNCTION_PER_PLUGIN, MAXIMUM_FUNCTION_PER_PLUGIN);
DEBUG_FUNCTION_LINE_ERR("number_used_functions was bigger then allowed. %d > %d. Limiting to %d", functionReplaceCount, MAXIMUM_FUNCTION_PER_PLUGIN, MAXIMUM_FUNCTION_PER_PLUGIN);
functionReplaceCount = MAXIMUM_FUNCTION_PER_PLUGIN;
}
@@ -315,13 +315,13 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
}
dyn_linking_import_t *importEntry = linking_entry.importEntry;
if (importEntry == nullptr) {
DEBUG_FUNCTION_LINE("importEntry was nullptr, skipping relocation entry");
DEBUG_FUNCTION_LINE_ERR("importEntry was nullptr, skipping relocation entry");
continue;
}
dyn_linking_function_t *functionEntry = linking_entry.functionEntry;
if (functionEntry == nullptr) {
DEBUG_FUNCTION_LINE("functionEntry was nullptr, skipping relocation entry");
DEBUG_FUNCTION_LINE_ERR("functionEntry was nullptr, skipping relocation entry");
continue;
}
auto rplInfo = std::make_shared<ImportRPLInformation>(importEntry->importName, importEntry->isData);

View File

@@ -19,12 +19,12 @@ void PluginData::freeMemory() {
switch (memoryType) {
default:
case eMemTypeExpHeap:
DEBUG_FUNCTION_LINE("Free PluginData buffer %08X on heap %08X", buffer, this->heapHandle);
DEBUG_FUNCTION_LINE_VERBOSE("Free PluginData buffer %08X on heap %08X", buffer, this->heapHandle);
MEMFreeToExpHeap(this->heapHandle, buffer);
this->buffer = nullptr;
break;
case eMemTypeMEM2:
DEBUG_FUNCTION_LINE("Free PluginData buffer %08X on default heap", buffer);
DEBUG_FUNCTION_LINE_VERBOSE("Free PluginData buffer %08X on default heap", buffer);
free(this->buffer);
this->buffer = nullptr;
break;
@@ -44,7 +44,7 @@ PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHand
data_copy = MEMAllocFromExpHeapEx(heapHandle, length, 4);
DEBUG_FUNCTION_LINE_VERBOSE("Allocated %d kb on ExpHeap", length / 1024);
if (data_copy == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate space on exp heap");
DEBUG_FUNCTION_LINE_ERR("Failed to allocate space on exp heap");
} else {
memcpy(data_copy, &input[0], length);
}
@@ -54,7 +54,7 @@ PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHand
data_copy = memalign(4, length);
DEBUG_FUNCTION_LINE_VERBOSE("Allocated %d kb on default heap", length / 1024);
if (data_copy == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate space on default heap");
DEBUG_FUNCTION_LINE_ERR("Failed to allocate space on default heap");
} else {
memcpy(data_copy, &input[0], length);
}

View File

@@ -27,12 +27,12 @@ std::vector<std::shared_ptr<PluginData>> PluginDataFactory::loadDir(const std::s
DIR *dfd;
if (path.empty()) {
DEBUG_FUNCTION_LINE("Path was empty");
DEBUG_FUNCTION_LINE_VERBOSE("Path was empty");
return result;
}
if ((dfd = opendir(path.c_str())) == nullptr) {
DEBUG_FUNCTION_LINE("Couldn't open dir %s", path.c_str());
DEBUG_FUNCTION_LINE_VERBOSE("Couldn't open dir %s", path.c_str());
return result;
}
@@ -41,7 +41,7 @@ std::vector<std::shared_ptr<PluginData>> PluginDataFactory::loadDir(const std::s
std::string full_file_path = StringTools::strfmt("%s/%s", path.c_str(), dp->d_name);
StringTools::RemoveDoubleSlashs(full_file_path);
if (stat(full_file_path.c_str(), &stbuf) == -1) {
DEBUG_FUNCTION_LINE("Unable to stat file: %s", full_file_path.c_str());
DEBUG_FUNCTION_LINE_VERBOSE("Unable to stat file: %s", full_file_path.c_str());
continue;
}
@@ -66,7 +66,7 @@ std::optional<std::shared_ptr<PluginData>> PluginDataFactory::load(const std::st
uint8_t *buffer = nullptr;
uint32_t fsize = 0;
if (FSUtils::LoadFileToMem(filename.c_str(), &buffer, &fsize) < 0) {
DEBUG_FUNCTION_LINE("Failed to load file");
DEBUG_FUNCTION_LINE_VERBOSE("Failed to load file");
return {};
}

View File

@@ -31,12 +31,12 @@ std::optional<std::shared_ptr<PluginInformation>>
PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, MEMHeapHandle heapHandle, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
uint8_t trampolineId) {
if (pluginData->buffer == nullptr) {
DEBUG_FUNCTION_LINE("Buffer was nullptr");
DEBUG_FUNCTION_LINE_ERR("Buffer was nullptr");
return std::nullopt;
}
elfio reader;
if (!reader.load((char *) pluginData->buffer, pluginData->length)) {
DEBUG_FUNCTION_LINE("Can't process PluginData in elfio");
DEBUG_FUNCTION_LINE_ERR("Can't process PluginData in elfio");
return std::nullopt;
}
@@ -71,14 +71,14 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
}
void *text_data = MEMAllocFromExpHeapEx(heapHandle, text_size, 0x1000);
if (text_data == nullptr) {
DEBUG_FUNCTION_LINE("Failed to alloc memory for the .text section (%d bytes)", text_size);
DEBUG_FUNCTION_LINE_ERR("Failed to alloc memory for the .text section (%d bytes)", text_size);
return std::nullopt;
}
DEBUG_FUNCTION_LINE_VERBOSE("Allocated %d kb from ExpHeap", text_size / 1024);
void *data_data = MEMAllocFromExpHeapEx(heapHandle, data_size, 0x1000);
if (data_data == nullptr) {
DEBUG_FUNCTION_LINE("Failed to alloc memory for the .data section (%d bytes)", data_size);
DEBUG_FUNCTION_LINE_ERR("Failed to alloc memory for the .data section (%d bytes)", data_size);
MEMFreeToExpHeap(heapHandle, text_data);
return std::nullopt;
@@ -110,7 +110,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
//destinations[psec->get_index()] = (uint8_t *) data_data;
//destinations[psec->get_index()] -= 0xC0000000;
} else {
DEBUG_FUNCTION_LINE("Unhandled case");
DEBUG_FUNCTION_LINE_ERR("Unhandled case");
free(destinations);
MEMFreeToExpHeap(heapHandle, text_data);
MEMFreeToExpHeap(heapHandle, data_data);
@@ -145,7 +145,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
if (!linkSection(reader, psec->get_index(), (uint32_t) destinations[psec->get_index()], (uint32_t) text_data, (uint32_t) data_data, trampoline_data, trampoline_data_length,
trampolineId)) {
DEBUG_FUNCTION_LINE("elfLink failed");
DEBUG_FUNCTION_LINE_ERR("elfLink failed");
free(destinations);
MEMFreeToExpHeap(heapHandle, text_data);
MEMFreeToExpHeap(heapHandle, data_data);
@@ -273,7 +273,7 @@ std::vector<std::shared_ptr<RelocationData>> PluginInformationFactory::getImport
Elf_Half sym_section_index;
if (!rel.get_entry(j, offset, sym_value, sym_name, type, addend, sym_section_index)) {
DEBUG_FUNCTION_LINE("Failed to get relocation");
DEBUG_FUNCTION_LINE_ERR("Failed to get relocation");
break;
}
@@ -291,7 +291,7 @@ std::vector<std::shared_ptr<RelocationData>> PluginInformationFactory::getImport
std::string rawSectionName = infoMap[sym_section_index];
if (rawSectionName.size() < fimport.size()) {
DEBUG_FUNCTION_LINE("Section name was shorter than expected, skipping this relocation");
DEBUG_FUNCTION_LINE_ERR("Section name was shorter than expected, skipping this relocation");
continue;
} else if (std::equal(fimport.begin(), fimport.end(), rawSectionName.begin())) {
rplName = rawSectionName.substr(fimport.size());
@@ -299,7 +299,7 @@ std::vector<std::shared_ptr<RelocationData>> PluginInformationFactory::getImport
rplName = rawSectionName.substr(dimport.size());
isData = true;
} else {
DEBUG_FUNCTION_LINE("invalid section name");
DEBUG_FUNCTION_LINE_ERR("invalid section name");
continue;
}
@@ -332,7 +332,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
Elf_Half sym_section_index;
if (!rel.get_entry(j, offset, sym_value, sym_name, type, addend, sym_section_index)) {
DEBUG_FUNCTION_LINE("Failed to get relocation");
DEBUG_FUNCTION_LINE_ERR("Failed to get relocation");
break;
}
@@ -350,7 +350,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
} else if (adjusted_sym_value == 0x0) {
//
} else {
DEBUG_FUNCTION_LINE("Unhandled case %08X", adjusted_sym_value);
DEBUG_FUNCTION_LINE_ERR("Unhandled case %08X", adjusted_sym_value);
return false;
}
@@ -366,13 +366,13 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
if (sym_section_index == SHN_ABS) {
//
} else if (sym_section_index > SHN_LORESERVE) {
DEBUG_FUNCTION_LINE("NOT IMPLEMENTED: %04X", sym_section_index);
DEBUG_FUNCTION_LINE_ERR("NOT IMPLEMENTED: %04X", sym_section_index);
return false;
}
// DEBUG_FUNCTION_LINE_VERBOSE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
if (!ElfUtils::elfLinkOne(type, adjusted_offset, addend, destination, adjusted_sym_value, trampoline_data, trampoline_data_length, RELOC_TYPE_FIXED, trampolineId)) {
DEBUG_FUNCTION_LINE("Link failed");
DEBUG_FUNCTION_LINE_ERR("Link failed");
return false;
}
}
@@ -380,6 +380,6 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
return true;
}
}
DEBUG_FUNCTION_LINE_VERBOSE("Failed to find relocation section");
DEBUG_FUNCTION_LINE_ERR("Failed to find relocation section");
return true;
}

View File

@@ -27,12 +27,12 @@ using namespace ELFIO;
std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(const std::shared_ptr<PluginData> &pluginData) {
if (pluginData->buffer == nullptr) {
DEBUG_FUNCTION_LINE("Buffer was nullptr");
DEBUG_FUNCTION_LINE_ERR("Buffer was nullptr");
return std::nullopt;
}
elfio reader;
if (!reader.load((char *) pluginData->buffer, pluginData->length)) {
DEBUG_FUNCTION_LINE("Can't process PluginData in elfio");
DEBUG_FUNCTION_LINE_ERR("Can't process PluginData in elfio");
return {};
}
return loadPlugin(reader);
@@ -44,12 +44,12 @@ std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFacto
uint8_t *buffer = nullptr;
uint32_t length = 0;
if (FSUtils::LoadFileToMem(filePath.c_str(), &buffer, &length) < 0) {
DEBUG_FUNCTION_LINE("Failed to load file to memory");
DEBUG_FUNCTION_LINE_ERR("Failed to load file to memory");
return {};
}
if (!reader.load((char *) buffer, length)) {
DEBUG_FUNCTION_LINE("Can't process PluginData in elfio");
DEBUG_FUNCTION_LINE_ERR("Can't process PluginData in elfio");
return {};
}
auto res = loadPlugin(reader);
@@ -60,7 +60,7 @@ std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFacto
std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(char *buffer, size_t size) {
elfio reader;
if (!reader.load(buffer, size)) {
DEBUG_FUNCTION_LINE("Can't find or process ELF file");
DEBUG_FUNCTION_LINE_ERR("Can't find or process ELF file");
return std::nullopt;
}
@@ -122,7 +122,7 @@ std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFacto
pluginInfo->setStorageId(value);
} else if (key == "wups") {
if (value != "0.7.0") {
DEBUG_FUNCTION_LINE("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
DEBUG_FUNCTION_LINE_ERR("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
return std::nullopt;
}
}