mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-09-11 21:38:47 -05:00
Even more formatting
This commit is contained in:
@@ -6,26 +6,26 @@
|
||||
#include "utils/logger.h"
|
||||
#include "common/plugin_defines.h"
|
||||
|
||||
dyn_linking_function_t * DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t * data, const char* functionName) {
|
||||
if(data == NULL) {
|
||||
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
|
||||
if (data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if(functionName == NULL) {
|
||||
if (functionName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
dyn_linking_function_t * result = NULL;
|
||||
for(int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) {
|
||||
dyn_linking_function_t * curEntry = &(data->functions[i]);
|
||||
if(strlen(curEntry->functionName) == 0) {
|
||||
if(strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
|
||||
dyn_linking_function_t *result = NULL;
|
||||
for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) {
|
||||
dyn_linking_function_t *curEntry = &(data->functions[i]);
|
||||
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.\n");
|
||||
return NULL;
|
||||
}
|
||||
strncpy(curEntry->functionName,functionName,DYN_LINK_FUNCTION_NAME_LENGTH);
|
||||
strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
|
||||
result = curEntry;
|
||||
break;
|
||||
}
|
||||
if(strncmp(curEntry->functionName,functionName,DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
|
||||
if (strncmp(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
|
||||
result = curEntry;
|
||||
break;
|
||||
}
|
||||
@@ -33,68 +33,71 @@ dyn_linking_function_t * DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_l
|
||||
return result;
|
||||
}
|
||||
|
||||
dyn_linking_import_t * DynamicLinkingHelper::getOrAddFunctionImportByName(dyn_linking_relocation_data_t * data, const char* importName) {
|
||||
dyn_linking_import_t *DynamicLinkingHelper::getOrAddFunctionImportByName(dyn_linking_relocation_data_t *data, const char *importName) {
|
||||
return getOrAddImport(data, importName, false);
|
||||
}
|
||||
|
||||
dyn_linking_import_t * DynamicLinkingHelper::getOrAddDataImportByName(dyn_linking_relocation_data_t * data, const char* importName) {
|
||||
dyn_linking_import_t *DynamicLinkingHelper::getOrAddDataImportByName(dyn_linking_relocation_data_t *data, const char *importName) {
|
||||
return getOrAddImport(data, importName, true);
|
||||
}
|
||||
|
||||
dyn_linking_import_t * DynamicLinkingHelper::getOrAddImport(dyn_linking_relocation_data_t * data, const char* importName, bool isData) {
|
||||
if(importName == NULL || data == NULL) {
|
||||
dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocation_data_t *data, const char *importName, bool isData) {
|
||||
if (importName == NULL || data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
dyn_linking_import_t * result = NULL;
|
||||
for(int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) {
|
||||
dyn_linking_import_t * curEntry = &(data->imports[i]);
|
||||
if(strlen(curEntry->importName) == 0) {
|
||||
if(strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
|
||||
dyn_linking_import_t *result = NULL;
|
||||
for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) {
|
||||
dyn_linking_import_t *curEntry = &(data->imports[i]);
|
||||
if (strlen(curEntry->importName) == 0) {
|
||||
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.\n");
|
||||
return NULL;
|
||||
}
|
||||
strncpy(curEntry->importName,importName,DYN_LINK_IMPORT_NAME_LENGTH);
|
||||
strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
|
||||
curEntry->isData = isData;
|
||||
result = curEntry;
|
||||
break;
|
||||
}
|
||||
if(strncmp(curEntry->importName,importName,DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry->isData == isData)) {
|
||||
if (strncmp(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry->isData == isData)) {
|
||||
return curEntry;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t * linking_data, dyn_linking_relocation_entry_t * linking_entries, uint32_t linking_entry_length, const RelocationData& relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(), relocationData.getImportRPLInformation());
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(),
|
||||
relocationData.getImportRPLInformation());
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t * linking_data, dyn_linking_relocation_entry_t * linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, const std::string& name, const ImportRPLInformation& rplInfo) {
|
||||
dyn_linking_import_t * importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(),rplInfo.isData());
|
||||
if(importInfoGbl == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n",DYN_LINK_IMPORT_LIST_LENGTH);
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
|
||||
const std::string &name, const ImportRPLInformation &rplInfo) {
|
||||
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
|
||||
if (importInfoGbl == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n", DYN_LINK_IMPORT_LIST_LENGTH);
|
||||
return false;
|
||||
}
|
||||
|
||||
dyn_linking_function_t * functionInfo = DynamicLinkingHelper::getOrAddFunctionEntryByName(linking_data, name.c_str());
|
||||
if(functionInfo == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.\n",DYN_LINK_FUNCTION_LIST_LENGTH);
|
||||
dyn_linking_function_t *functionInfo = DynamicLinkingHelper::getOrAddFunctionEntryByName(linking_data, name.c_str());
|
||||
if (functionInfo == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.\n", DYN_LINK_FUNCTION_LIST_LENGTH);
|
||||
return false;
|
||||
}
|
||||
|
||||
return addReloationEntry(linking_entries, linking_entry_length, type, offset, addend, destination, functionInfo, importInfoGbl);
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t * linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t * functionName, dyn_linking_import_t * importInfo) {
|
||||
for(uint32_t i = 0; i < linking_entry_length; i++) {
|
||||
dyn_linking_relocation_entry_t * curEntry = &(linking_entries[i]);
|
||||
if(curEntry->functionEntry != NULL) {
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo) {
|
||||
for (uint32_t i = 0; i < linking_entry_length; i++) {
|
||||
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
|
||||
if (curEntry->functionEntry != NULL) {
|
||||
continue;
|
||||
}
|
||||
curEntry->type = type;
|
||||
curEntry->offset = offset;
|
||||
curEntry->addend = addend;
|
||||
curEntry->destination = (void*) destination;
|
||||
curEntry->destination = (void *) destination;
|
||||
curEntry->functionEntry = functionName;
|
||||
curEntry->importEntry = importInfo;
|
||||
return true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/dynamic_linking_defines.h"
|
||||
#include "utils/logger.h"
|
||||
#include <string>
|
||||
@@ -13,7 +14,7 @@ public:
|
||||
\param functionName Name of the function
|
||||
\return Returns a pointer to the entry which contains the functionName. Null on error or if the list full.
|
||||
**/
|
||||
static dyn_linking_function_t * getOrAddFunctionEntryByName(dyn_linking_relocation_data_t * data, const char * functionName);
|
||||
static dyn_linking_function_t *getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName);
|
||||
|
||||
/**
|
||||
Gets the function import entry for a given function name. If the import is not present in the list, it will be added.
|
||||
@@ -22,7 +23,7 @@ public:
|
||||
\param importName Name of the function
|
||||
\return Returns a pointer to the function import entry which contains the importName. Null on error or if the list full.
|
||||
**/
|
||||
static dyn_linking_import_t * getOrAddFunctionImportByName(dyn_linking_relocation_data_t * data, const char * importName);
|
||||
static dyn_linking_import_t *getOrAddFunctionImportByName(dyn_linking_relocation_data_t *data, const char *importName);
|
||||
|
||||
|
||||
/**
|
||||
@@ -32,7 +33,7 @@ public:
|
||||
\param importName Name of the data
|
||||
\return Returns a pointer to the data import entry which contains the importName. Null on error or if the list full.
|
||||
**/
|
||||
static dyn_linking_import_t * getOrAddDataImportByName(dyn_linking_relocation_data_t * data, const char * importName);
|
||||
static dyn_linking_import_t *getOrAddDataImportByName(dyn_linking_relocation_data_t *data, const char *importName);
|
||||
|
||||
|
||||
/**
|
||||
@@ -44,13 +45,17 @@ public:
|
||||
|
||||
\return Returns a pointer to the data import entry which contains the importName. Null on error or if the list full.
|
||||
**/
|
||||
static dyn_linking_import_t * getOrAddImport(dyn_linking_relocation_data_t * data, const char * importName, bool isData);
|
||||
static dyn_linking_import_t *getOrAddImport(dyn_linking_relocation_data_t *data, const char *importName, bool isData);
|
||||
|
||||
static bool addReloationEntry(dyn_linking_relocation_data_t * linking_data, dyn_linking_relocation_entry_t * linking_entries, uint32_t linking_entry_length, const RelocationData& relocationData);
|
||||
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData);
|
||||
|
||||
static bool addReloationEntry(dyn_linking_relocation_data_t * linking_data, dyn_linking_relocation_entry_t * linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, const std::string& name, const ImportRPLInformation& rplInfo);
|
||||
static bool
|
||||
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, const std::string &name,
|
||||
const ImportRPLInformation &rplInfo);
|
||||
|
||||
static bool addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo);
|
||||
|
||||
static bool addReloationEntry(dyn_linking_relocation_entry_t * linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t * functionName, dyn_linking_import_t * importInfo);
|
||||
private:
|
||||
DynamicLinkingHelper() {
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
class FunctionData {
|
||||
|
||||
public:
|
||||
FunctionData(void * paddress, void * vaddress, const std::string& name, wups_loader_library_type_t library, void * replaceAddr, void * replaceCall) {
|
||||
FunctionData(void *paddress, void *vaddress, const std::string &name, wups_loader_library_type_t library, void *replaceAddr, void *replaceCall) {
|
||||
this->paddress = paddress;
|
||||
this->vaddress = vaddress;
|
||||
this->name = name;
|
||||
@@ -35,35 +35,36 @@ public:
|
||||
|
||||
}
|
||||
|
||||
const std::string& getName() const{
|
||||
const std::string &getName() const {
|
||||
return this->name;
|
||||
}
|
||||
|
||||
wups_loader_library_type_t getLibrary() const{
|
||||
wups_loader_library_type_t getLibrary() const {
|
||||
return this->library;
|
||||
}
|
||||
|
||||
const void * getPhysicalAddress() const{
|
||||
const void *getPhysicalAddress() const {
|
||||
return paddress;
|
||||
}
|
||||
const void * getVirtualAddress() const{
|
||||
|
||||
const void *getVirtualAddress() const {
|
||||
return vaddress;
|
||||
}
|
||||
|
||||
const void * getReplaceAddress() const{
|
||||
const void *getReplaceAddress() const {
|
||||
return replaceAddr;
|
||||
}
|
||||
|
||||
const void * getReplaceCall() const{
|
||||
const void *getReplaceCall() const {
|
||||
return replaceCall;
|
||||
}
|
||||
|
||||
private:
|
||||
void * paddress = NULL;
|
||||
void * vaddress = NULL;
|
||||
void *paddress = NULL;
|
||||
void *vaddress = NULL;
|
||||
std::string name;
|
||||
wups_loader_library_type_t library;
|
||||
void * replaceAddr = NULL;
|
||||
void * replaceCall = NULL;
|
||||
void *replaceAddr = NULL;
|
||||
void *replaceCall = NULL;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
class HookData {
|
||||
|
||||
public:
|
||||
HookData(void * function_pointer, wups_loader_hook_type_t type) {
|
||||
HookData(void *function_pointer, wups_loader_hook_type_t type) {
|
||||
this->function_pointer = function_pointer;
|
||||
this->type = type;
|
||||
}
|
||||
@@ -32,14 +32,15 @@ public:
|
||||
|
||||
}
|
||||
|
||||
void * getFunctionPointer() const{
|
||||
void *getFunctionPointer() const {
|
||||
return function_pointer;
|
||||
}
|
||||
|
||||
wups_loader_hook_type_t getType() const{
|
||||
wups_loader_hook_type_t getType() const {
|
||||
return this->type;
|
||||
}
|
||||
|
||||
private:
|
||||
void * function_pointer;
|
||||
void *function_pointer;
|
||||
wups_loader_hook_type_t type;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
return name;
|
||||
}
|
||||
|
||||
bool isData() const{
|
||||
bool isData() const {
|
||||
return _isData;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,30 +23,31 @@
|
||||
|
||||
class PluginContainer {
|
||||
public:
|
||||
PluginContainer(){
|
||||
PluginContainer() {
|
||||
|
||||
}
|
||||
const PluginMetaInformation& getMetaInformation() const{
|
||||
|
||||
const PluginMetaInformation &getMetaInformation() const {
|
||||
return this->metaInformation;
|
||||
}
|
||||
|
||||
void setMetaInformation(PluginMetaInformation& metaInfo){
|
||||
void setMetaInformation(PluginMetaInformation &metaInfo) {
|
||||
this->metaInformation = metaInfo;
|
||||
}
|
||||
|
||||
const PluginInformation& getPluginInformation() const{
|
||||
const PluginInformation &getPluginInformation() const {
|
||||
return pluginInformation;
|
||||
}
|
||||
|
||||
void setPluginInformation(PluginInformation& pluginInformation){
|
||||
void setPluginInformation(PluginInformation &pluginInformation) {
|
||||
this->pluginInformation = pluginInformation;
|
||||
}
|
||||
|
||||
const PluginData& getPluginData() const{
|
||||
const PluginData &getPluginData() const {
|
||||
return pluginData;
|
||||
}
|
||||
|
||||
void setPluginData(PluginData& pluginData){
|
||||
void setPluginData(PluginData &pluginData) {
|
||||
this->pluginData = pluginData;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "PluginInformation.h"
|
||||
#include "RelocationData.h"
|
||||
|
||||
bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInformation, PluginContainer& plugin) {
|
||||
bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin) {
|
||||
|
||||
int32_t plugin_count = pluginInformation->number_used_plugins;
|
||||
|
||||
@@ -17,50 +17,50 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInforma
|
||||
//auto pluginPath = plugin.getMetaInformation().getPath();
|
||||
|
||||
|
||||
if(plugin_count >= MAXIMUM_PLUGINS - 1) {
|
||||
if (plugin_count >= MAXIMUM_PLUGINS - 1) {
|
||||
DEBUG_FUNCTION_LINE("Maximum of %d plugins reached. %s won't be loaded!\n", MAXIMUM_PLUGINS, pluginName.c_str());
|
||||
return false;
|
||||
}
|
||||
// Copy data to global struct.
|
||||
plugin_information_single_t * plugin_data = &(pluginInformation->plugin_data[plugin_count]);
|
||||
plugin_information_single_t *plugin_data = &(pluginInformation->plugin_data[plugin_count]);
|
||||
|
||||
DEBUG_FUNCTION_LINE("%08X", plugin_data);
|
||||
// Make sure everything is reset.
|
||||
//plugin_data = {};
|
||||
memset((void*)plugin_data, 0, sizeof(plugin_information_single_t));
|
||||
memset((void *) plugin_data, 0, sizeof(plugin_information_single_t));
|
||||
|
||||
auto pluginMetaInfo = plugin.getMetaInformation();
|
||||
auto plugin_meta_data = &plugin_data->meta;
|
||||
auto plugin_meta_data = &plugin_data->meta;
|
||||
|
||||
if(pluginMetaInfo.getName().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
if (pluginMetaInfo.getName().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("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) {
|
||||
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.");
|
||||
}
|
||||
strncpy(plugin_meta_data->author, pluginMetaInfo.getAuthor().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH-1);
|
||||
strncpy(plugin_meta_data->author, pluginMetaInfo.getAuthor().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
|
||||
|
||||
if(pluginMetaInfo.getVersion().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
if (pluginMetaInfo.getVersion().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Warning: version will be truncated.");
|
||||
}
|
||||
strncpy(plugin_meta_data->version, pluginMetaInfo.getVersion().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH-1);
|
||||
strncpy(plugin_meta_data->version, pluginMetaInfo.getVersion().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
|
||||
|
||||
if(pluginMetaInfo.getLicense().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
if (pluginMetaInfo.getLicense().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Warning: license will be truncated.");
|
||||
}
|
||||
strncpy(plugin_meta_data->license, pluginMetaInfo.getLicense().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH-1);
|
||||
strncpy(plugin_meta_data->license, pluginMetaInfo.getLicense().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
|
||||
|
||||
if(pluginMetaInfo.getBuildTimestamp().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
if (pluginMetaInfo.getBuildTimestamp().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Warning: build timestampt will be truncated.");
|
||||
}
|
||||
strncpy(plugin_meta_data->buildTimestamp, pluginMetaInfo.getBuildTimestamp().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH-1);
|
||||
strncpy(plugin_meta_data->buildTimestamp, pluginMetaInfo.getBuildTimestamp().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1);
|
||||
|
||||
if(pluginMetaInfo.getDescription().size() >= MAXIMUM_PLUGIN_DESCRIPTION_LENGTH) {
|
||||
if (pluginMetaInfo.getDescription().size() >= MAXIMUM_PLUGIN_DESCRIPTION_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Warning: description will be truncated.");
|
||||
DEBUG_FUNCTION_LINE("%s", pluginMetaInfo.getDescription().c_str());
|
||||
}
|
||||
strncpy(plugin_meta_data->descripion, pluginMetaInfo.getDescription().c_str(), MAXIMUM_PLUGIN_DESCRIPTION_LENGTH-1);
|
||||
strncpy(plugin_meta_data->descripion, pluginMetaInfo.getDescription().c_str(), MAXIMUM_PLUGIN_DESCRIPTION_LENGTH - 1);
|
||||
|
||||
plugin_meta_data->size = pluginMetaInfo.getSize();
|
||||
|
||||
@@ -69,8 +69,8 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInforma
|
||||
|
||||
// Relocation
|
||||
std::vector<RelocationData> 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)) {
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
@@ -81,32 +81,32 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInforma
|
||||
std::vector<HookData> 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);
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
if(hook_data_list.size() > MAXIMUM_HOOKS_PER_PLUGIN) {
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(pluginName.length() > MAXIMUM_PLUGIN_NAME_LENGTH-1) {
|
||||
if (pluginName.length() > MAXIMUM_PLUGIN_NAME_LENGTH - 1) {
|
||||
DEBUG_FUNCTION_LINE("Name for plugin %s was too long to be stored.", pluginName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Store function replacement information */
|
||||
uint32_t i = 0;
|
||||
for(auto & curFunction : pluginInfo.getFunctionDataList()) {
|
||||
replacement_data_function_t * function_data = &plugin_data->info.functions[i];
|
||||
if(strlen(curFunction.getName().c_str()) > MAXIMUM_FUNCTION_NAME_LENGTH-1) {
|
||||
for (auto &curFunction : pluginInfo.getFunctionDataList()) {
|
||||
replacement_data_function_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());
|
||||
continue;
|
||||
}
|
||||
|
||||
DEBUG_FUNCTION_LINE("Adding function \"%s\" for plugin \"%s\"",curFunction.getName().c_str(), pluginName.c_str());
|
||||
DEBUG_FUNCTION_LINE("Adding function \"%s\" for plugin \"%s\"", curFunction.getName().c_str(), pluginName.c_str());
|
||||
|
||||
strncpy(function_data->function_name, curFunction.getName().c_str(),MAXIMUM_FUNCTION_NAME_LENGTH-1);
|
||||
strncpy(function_data->function_name, curFunction.getName().c_str(), MAXIMUM_FUNCTION_NAME_LENGTH - 1);
|
||||
|
||||
function_data->library = curFunction.getLibrary();
|
||||
function_data->replaceAddr = (uint32_t) curFunction.getReplaceAddress();
|
||||
@@ -119,37 +119,37 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInforma
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for(auto & curHook : pluginInfo.getHookDataList()) {
|
||||
replacement_data_hook_t * hook_data = &plugin_data->info.hooks[i];
|
||||
for (auto &curHook : pluginInfo.getHookDataList()) {
|
||||
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[i];
|
||||
|
||||
DEBUG_FUNCTION_LINE("Set hook for plugin \"%s\" of type %08X to target %08X",plugin_data->meta.name, curHook.getType(),(void*) curHook.getFunctionPointer());
|
||||
DEBUG_FUNCTION_LINE("Set hook for plugin \"%s\" of type %08X to target %08X", plugin_data->meta.name, curHook.getType(), (void *) curHook.getFunctionPointer());
|
||||
|
||||
hook_data->func_pointer = (void*) curHook.getFunctionPointer();
|
||||
hook_data->type = curHook.getType();
|
||||
hook_data->func_pointer = (void *) curHook.getFunctionPointer();
|
||||
hook_data->type = curHook.getType();
|
||||
|
||||
plugin_data->info.number_used_hooks++;
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Saving SectionInfos */
|
||||
for(auto & curSection : pluginInfo.getSectionInfoList()) {
|
||||
for (auto &curSection : pluginInfo.getSectionInfoList()) {
|
||||
bool foundFreeSlot = false;
|
||||
uint32_t slot = 0;
|
||||
for(uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
|
||||
plugin_section_info_t * sectionInfo = &(plugin_data->info.sectionInfos[i]);
|
||||
if(sectionInfo->addr == 0 && sectionInfo->size == 0) {
|
||||
for (uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[i]);
|
||||
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
|
||||
foundFreeSlot = true;
|
||||
slot = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(foundFreeSlot) {
|
||||
plugin_section_info_t * sectionInfo = &(plugin_data->info.sectionInfos[slot]);
|
||||
if(strlen(curSection.first.c_str()) > 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());
|
||||
if (foundFreeSlot) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[slot]);
|
||||
if (strlen(curSection.first.c_str()) > 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());
|
||||
break;
|
||||
}
|
||||
strncpy(sectionInfo->name, curSection.first.c_str(), MAXIMUM_PLUGIN_SECTION_NAME_LENGTH-1);
|
||||
strncpy(sectionInfo->name, curSection.first.c_str(), MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1);
|
||||
sectionInfo->addr = curSection.second.getAddress();
|
||||
sectionInfo->size = curSection.second.getSize();
|
||||
|
||||
@@ -165,42 +165,42 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInforma
|
||||
|
||||
/* Copy plugin data */
|
||||
auto pluginData = plugin.getPluginData();
|
||||
auto plugin_data_data = &plugin_data->data;
|
||||
auto plugin_data_data = &plugin_data->data;
|
||||
|
||||
plugin_data_data->buffer = (char*)pluginData.buffer;
|
||||
plugin_data_data->buffer = (char *) pluginData.buffer;
|
||||
plugin_data_data->bufferLength = pluginData.length;
|
||||
plugin_data_data->memoryType = pluginData.memoryType;
|
||||
plugin_data_data->heapHandle = (int)pluginData.heapHandle;
|
||||
plugin_data_data->heapHandle = (int) pluginData.heapHandle;
|
||||
|
||||
pluginInformation->number_used_plugins++;
|
||||
|
||||
DCFlushRange((void*)pluginInformation,sizeof(plugin_information_t));
|
||||
ICInvalidateRange((void*)pluginInformation,sizeof(plugin_information_t));
|
||||
DCFlushRange((void *) pluginInformation, sizeof(plugin_information_t));
|
||||
ICInvalidateRange((void *) pluginInformation, sizeof(plugin_information_t));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_information_t * pluginInformation) {
|
||||
std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_information_t *pluginInformation) {
|
||||
std::vector<PluginContainer> result;
|
||||
if(pluginInformation == NULL) {
|
||||
if (pluginInformation == NULL) {
|
||||
DEBUG_FUNCTION_LINE("pluginInformation == NULL");
|
||||
return result;
|
||||
}
|
||||
DCFlushRange((void*)pluginInformation,sizeof(plugin_information_t));
|
||||
ICInvalidateRange((void*)pluginInformation,sizeof(plugin_information_t));
|
||||
DCFlushRange((void *) pluginInformation, sizeof(plugin_information_t));
|
||||
ICInvalidateRange((void *) pluginInformation, sizeof(plugin_information_t));
|
||||
|
||||
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);
|
||||
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);
|
||||
plugin_count = MAXIMUM_PLUGINS;
|
||||
}
|
||||
for(int32_t i = 0; i < plugin_count; i++) {
|
||||
for (int32_t i = 0; i < plugin_count; i++) {
|
||||
// Copy data from struct.
|
||||
plugin_information_single_t * plugin_data = &(pluginInformation->plugin_data[i]);
|
||||
plugin_information_single_t *plugin_data = &(pluginInformation->plugin_data[i]);
|
||||
|
||||
PluginMetaInformation metaInformation;
|
||||
|
||||
plugin_meta_info_t * meta = &(plugin_data->meta);
|
||||
plugin_meta_info_t *meta = &(plugin_data->meta);
|
||||
metaInformation.setAuthor(meta->author);
|
||||
metaInformation.setVersion(meta->version);
|
||||
metaInformation.setBuildTimestamp(meta->buildTimestamp);
|
||||
@@ -211,7 +211,7 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
|
||||
|
||||
PluginData pluginData;
|
||||
|
||||
plugin_data_t * data = &(plugin_data->data);
|
||||
plugin_data_t *data = &(plugin_data->data);
|
||||
|
||||
pluginData.buffer = data->buffer;
|
||||
pluginData.length = data->bufferLength;
|
||||
@@ -225,9 +225,9 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
|
||||
pluginInformation.allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress;
|
||||
pluginInformation.allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress;
|
||||
|
||||
for(uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
|
||||
plugin_section_info_t * sectionInfo = &(plugin_data->info.sectionInfos[i]);
|
||||
if(sectionInfo->addr == 0 && sectionInfo->size == 0) {
|
||||
for (uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[i]);
|
||||
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
|
||||
continue;
|
||||
}
|
||||
DEBUG_FUNCTION_LINE("Add SectionInfo %s", sectionInfo->name);
|
||||
@@ -237,13 +237,13 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
|
||||
/* load hook data */
|
||||
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);
|
||||
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);
|
||||
hookCount = MAXIMUM_HOOKS_PER_PLUGIN;
|
||||
}
|
||||
|
||||
for(uint32_t j = 0; j < hookCount; j++) {
|
||||
replacement_data_hook_t * hook_entry = &(plugin_data->info.hooks[j]);
|
||||
for (uint32_t j = 0; j < hookCount; j++) {
|
||||
replacement_data_hook_t *hook_entry = &(plugin_data->info.hooks[j]);
|
||||
HookData curHook(hook_entry->func_pointer, hook_entry->type);
|
||||
pluginInformation.addHookData(curHook);
|
||||
}
|
||||
@@ -251,39 +251,39 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
|
||||
/* load function replacement data */
|
||||
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);
|
||||
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);
|
||||
functionReplaceCount = MAXIMUM_FUNCTION_PER_PLUGIN;
|
||||
}
|
||||
|
||||
for(uint32_t j = 0; j < functionReplaceCount; j++) {
|
||||
replacement_data_function_t * entry = &(plugin_data->info.functions[j]);
|
||||
for (uint32_t j = 0; j < functionReplaceCount; j++) {
|
||||
replacement_data_function_t *entry = &(plugin_data->info.functions[j]);
|
||||
FunctionData func((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, entry->library, (void *) entry->replaceAddr, (void *) entry->replaceCall);
|
||||
pluginInformation.addFunctionData(func);
|
||||
}
|
||||
|
||||
/* load relocation data */
|
||||
for(uint32_t j = 0; j < PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH; j++) {
|
||||
dyn_linking_relocation_entry_t * linking_entry = &(plugin_data->info.linking_entries[j]);
|
||||
if(linking_entry->destination == NULL) {
|
||||
for (uint32_t j = 0; j < PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH; j++) {
|
||||
dyn_linking_relocation_entry_t *linking_entry = &(plugin_data->info.linking_entries[j]);
|
||||
if (linking_entry->destination == NULL) {
|
||||
break;
|
||||
}
|
||||
dyn_linking_import_t* importEntry = linking_entry->importEntry;
|
||||
if(importEntry == NULL) {
|
||||
dyn_linking_import_t *importEntry = linking_entry->importEntry;
|
||||
if (importEntry == NULL) {
|
||||
DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
if(importEntry->importName == NULL) {
|
||||
if (importEntry->importName == NULL) {
|
||||
DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
dyn_linking_function_t* functionEntry = linking_entry->functionEntry;
|
||||
dyn_linking_function_t *functionEntry = linking_entry->functionEntry;
|
||||
|
||||
if(functionEntry == NULL) {
|
||||
if (functionEntry == NULL) {
|
||||
DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
if(functionEntry->functionName == NULL) {
|
||||
if (functionEntry->functionName == NULL) {
|
||||
DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
class PluginContainerPersistence {
|
||||
public:
|
||||
static bool savePlugin(plugin_information_t * pluginInformation, PluginContainer& plugin);
|
||||
static std::vector<PluginContainer> loadPlugins(plugin_information_t * pluginInformation);
|
||||
static bool savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin);
|
||||
|
||||
static std::vector<PluginContainer> loadPlugins(plugin_information_t *pluginInformation);
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
#include "PluginData.h"
|
||||
|
||||
void PluginData::freeMemory() {
|
||||
if(buffer == NULL) {
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch(memoryType) {
|
||||
default:
|
||||
case eMemTypeExpHeap:
|
||||
MEMFreeToExpHeap(this->heapHandle, buffer);
|
||||
this->buffer = NULL;
|
||||
break;
|
||||
case eMemTypeMEM2:
|
||||
free(this->buffer);
|
||||
this->buffer = NULL;
|
||||
break;
|
||||
switch (memoryType) {
|
||||
default:
|
||||
case eMemTypeExpHeap:
|
||||
MEMFreeToExpHeap(this->heapHandle, buffer);
|
||||
this->buffer = NULL;
|
||||
break;
|
||||
case eMemTypeMEM2:
|
||||
free(this->buffer);
|
||||
this->buffer = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ PluginData::PluginData(std::vector<uint8_t> buffer) : PluginData(buffer, 0, eMem
|
||||
}
|
||||
|
||||
void PluginData::loadReader() {
|
||||
if(this->buffer == NULL) {
|
||||
if (this->buffer == NULL) {
|
||||
this->reader = std::nullopt;
|
||||
} else {
|
||||
elfio * nReader = new elfio;
|
||||
if(nReader != NULL && nReader->load((char*)this->buffer, length)) {
|
||||
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){
|
||||
if (nReader) {
|
||||
delete nReader;
|
||||
nReader = NULL;
|
||||
}
|
||||
@@ -41,36 +41,36 @@ void PluginData::loadReader() {
|
||||
}
|
||||
|
||||
|
||||
PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMemoryTypes memoryType):
|
||||
heapHandle(heapHandle),
|
||||
memoryType(memoryType),
|
||||
length(input.size()) {
|
||||
void * data_copy = NULL;
|
||||
switch(memoryType) {
|
||||
default:
|
||||
case eMemTypeExpHeap:
|
||||
data_copy = MEMAllocFromExpHeapEx(heapHandle, length, 4);
|
||||
if(data_copy == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Failed to allocate space on exp heap");
|
||||
} else {
|
||||
memcpy(data_copy, &input[0], length);
|
||||
}
|
||||
this->buffer = data_copy;
|
||||
DEBUG_FUNCTION_LINE("copied data to exp heap");
|
||||
break;
|
||||
case eMemTypeMEM2:
|
||||
data_copy = memalign(length, 4);
|
||||
if(data_copy == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Failed to allocate space on default heap");
|
||||
} else {
|
||||
memcpy(data_copy, &input[0], length);
|
||||
}
|
||||
this->buffer = data_copy;
|
||||
break;
|
||||
PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
|
||||
heapHandle(heapHandle),
|
||||
memoryType(memoryType),
|
||||
length(input.size()) {
|
||||
void *data_copy = NULL;
|
||||
switch (memoryType) {
|
||||
default:
|
||||
case eMemTypeExpHeap:
|
||||
data_copy = MEMAllocFromExpHeapEx(heapHandle, length, 4);
|
||||
if (data_copy == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Failed to allocate space on exp heap");
|
||||
} else {
|
||||
memcpy(data_copy, &input[0], length);
|
||||
}
|
||||
this->buffer = data_copy;
|
||||
DEBUG_FUNCTION_LINE("copied data to exp heap");
|
||||
break;
|
||||
case eMemTypeMEM2:
|
||||
data_copy = memalign(length, 4);
|
||||
if (data_copy == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Failed to allocate space on default heap");
|
||||
} else {
|
||||
memcpy(data_copy, &input[0], length);
|
||||
}
|
||||
this->buffer = data_copy;
|
||||
break;
|
||||
}
|
||||
loadReader();
|
||||
}
|
||||
|
||||
std::optional<PluginData> PluginData::createFromExistingData(const void* buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length) {
|
||||
std::optional<PluginData> PluginData::createFromExistingData(const void *buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <malloc.h>
|
||||
@@ -32,11 +33,12 @@ enum eMemoryTypes {
|
||||
|
||||
class PluginData {
|
||||
public:
|
||||
const std::optional<elfio*>& getReader() const {
|
||||
const std::optional<elfio *> &getReader() const {
|
||||
return reader;
|
||||
}
|
||||
|
||||
~PluginData() {
|
||||
if(nReader != NULL) {
|
||||
if (nReader != NULL) {
|
||||
delete nReader;
|
||||
nReader = NULL;
|
||||
}
|
||||
@@ -44,25 +46,30 @@ public:
|
||||
|
||||
|
||||
void freeMemory();
|
||||
|
||||
private:
|
||||
PluginData() {
|
||||
}
|
||||
|
||||
PluginData(std::vector<uint8_t> buffer);
|
||||
|
||||
PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
|
||||
|
||||
|
||||
void loadReader();
|
||||
|
||||
static std::optional<PluginData> createFromExistingData(const void* buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length);
|
||||
static std::optional<PluginData> createFromExistingData(const void *buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length);
|
||||
|
||||
std::optional<elfio*> reader;
|
||||
elfio* nReader = NULL;
|
||||
void* buffer;
|
||||
std::optional<elfio *> reader;
|
||||
elfio *nReader = NULL;
|
||||
void *buffer;
|
||||
MEMHeapHandle heapHandle;
|
||||
eMemoryTypes memoryType;
|
||||
size_t length;
|
||||
|
||||
friend class PluginDataFactory;
|
||||
|
||||
friend class PluginContainer;
|
||||
|
||||
friend class PluginContainerPersistence;
|
||||
};
|
||||
|
||||
@@ -24,53 +24,53 @@
|
||||
#include "utils/StringTools.h"
|
||||
|
||||
|
||||
std::vector<PluginData> PluginDataFactory::loadDir(const std::string & path, MEMHeapHandle heapHandle) {
|
||||
std::vector<PluginData> PluginDataFactory::loadDir(const std::string &path, MEMHeapHandle heapHandle) {
|
||||
std::vector<PluginData> result;
|
||||
struct dirent *dp;
|
||||
DIR *dfd = NULL;
|
||||
|
||||
if(path.empty()) {
|
||||
if (path.empty()) {
|
||||
DEBUG_FUNCTION_LINE("Path was empty\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((dfd = opendir(path.c_str())) == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Couldn't open dir %s\n",path.c_str());
|
||||
DEBUG_FUNCTION_LINE("Couldn't open dir %s\n", path.c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
while ((dp = readdir(dfd)) != NULL) {
|
||||
struct stat stbuf ;
|
||||
std::string full_file_path = StringTools::strfmt("%s/%s",path.c_str(),dp->d_name);
|
||||
struct stat stbuf;
|
||||
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\n",full_file_path.c_str()) ;
|
||||
if (stat(full_file_path.c_str(), &stbuf) == -1) {
|
||||
DEBUG_FUNCTION_LINE("Unable to stat file: %s\n", full_file_path.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ( stbuf.st_mode & S_IFMT ) == S_IFDIR ) { // Skip directories
|
||||
if ((stbuf.st_mode & S_IFMT) == S_IFDIR) { // Skip directories
|
||||
continue;
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Found file: %s\n",full_file_path.c_str()) ;
|
||||
DEBUG_FUNCTION_LINE("Found file: %s\n", full_file_path.c_str());
|
||||
auto pluginData = load(full_file_path, heapHandle);
|
||||
if(pluginData) {
|
||||
if (pluginData) {
|
||||
result.push_back(pluginData.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(dfd != NULL) {
|
||||
if (dfd != NULL) {
|
||||
closedir(dfd);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::optional<PluginData> PluginDataFactory::load(const std::string & filename, MEMHeapHandle heapHandle) {
|
||||
std::optional<PluginData> PluginDataFactory::load(const std::string &filename, MEMHeapHandle heapHandle) {
|
||||
// open the file:
|
||||
DEBUG_FUNCTION_LINE();
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
DEBUG_FUNCTION_LINE();
|
||||
if(!file.is_open()){
|
||||
if (!file.is_open()) {
|
||||
DEBUG_FUNCTION_LINE("Failed to open %s", filename.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -102,8 +102,8 @@ std::optional<PluginData> PluginDataFactory::load(const std::string & filename,
|
||||
return load(vBuffer, heapHandle);
|
||||
}
|
||||
|
||||
std::optional<PluginData> PluginDataFactory::load(std::vector<uint8_t>& buffer, MEMHeapHandle heapHandle) {
|
||||
if(buffer.empty()){
|
||||
std::optional<PluginData> PluginDataFactory::load(std::vector<uint8_t> &buffer, MEMHeapHandle heapHandle) {
|
||||
if (buffer.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
|
||||
class PluginDataFactory {
|
||||
public:
|
||||
static std::vector<PluginData> loadDir(const std::string & path, MEMHeapHandle heapHandle);
|
||||
static std::optional<PluginData> load(const std::string & path, MEMHeapHandle heapHandle);
|
||||
static std::optional<PluginData> load(std::vector<uint8_t>& buffer, MEMHeapHandle heapHandle);
|
||||
static std::vector<PluginData> loadDir(const std::string &path, MEMHeapHandle heapHandle);
|
||||
|
||||
static std::optional<PluginData> load(const std::string &path, MEMHeapHandle heapHandle);
|
||||
|
||||
static std::optional<PluginData> load(std::vector<uint8_t> &buffer, MEMHeapHandle heapHandle);
|
||||
};
|
||||
|
||||
@@ -29,17 +29,17 @@
|
||||
|
||||
class PluginInformation {
|
||||
public:
|
||||
PluginInformation(){
|
||||
PluginInformation() {
|
||||
}
|
||||
|
||||
virtual ~PluginInformation() {
|
||||
}
|
||||
|
||||
void addHookData(const HookData& hook_data) {
|
||||
void addHookData(const HookData &hook_data) {
|
||||
hook_data_list.push_back(hook_data);
|
||||
}
|
||||
|
||||
const std::vector<HookData>& getHookDataList() const {
|
||||
const std::vector<HookData> &getHookDataList() const {
|
||||
return hook_data_list;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
function_data_list.push_back(function_data);
|
||||
}
|
||||
|
||||
const std::vector<FunctionData>& getFunctionDataList() const {
|
||||
const std::vector<FunctionData> &getFunctionDataList() const {
|
||||
return function_data_list;
|
||||
}
|
||||
|
||||
@@ -55,20 +55,20 @@ public:
|
||||
relocation_data_list.push_back(relocation_data);
|
||||
}
|
||||
|
||||
const std::vector<RelocationData>& getRelocationDataList() const {
|
||||
const std::vector<RelocationData> &getRelocationDataList() const {
|
||||
return relocation_data_list;
|
||||
}
|
||||
|
||||
void addSectionInfo(const SectionInfo& sectionInfo) {
|
||||
void addSectionInfo(const SectionInfo §ionInfo) {
|
||||
section_info_list[sectionInfo.getName()] = sectionInfo;
|
||||
}
|
||||
|
||||
const std::map<std::string, SectionInfo>& getSectionInfoList() const {
|
||||
const std::map<std::string, SectionInfo> &getSectionInfoList() const {
|
||||
return section_info_list;
|
||||
}
|
||||
|
||||
std::optional<SectionInfo> getSectionInfo(const std::string& sectionName) const {
|
||||
if(getSectionInfoList().count(sectionName) > 0) {
|
||||
std::optional<SectionInfo> getSectionInfo(const std::string §ionName) const {
|
||||
if (getSectionInfoList().count(sectionName) > 0) {
|
||||
return section_info_list.at(sectionName);
|
||||
}
|
||||
return std::nullopt;
|
||||
@@ -91,9 +91,10 @@ private:
|
||||
|
||||
uint8_t trampolinId = 0;
|
||||
|
||||
void* allocatedTextMemoryAddress = 0;
|
||||
void* allocatedDataMemoryAddress = 0;
|
||||
void *allocatedTextMemoryAddress = 0;
|
||||
void *allocatedDataMemoryAddress = 0;
|
||||
|
||||
friend class PluginInformationFactory;
|
||||
|
||||
friend class PluginContainerPersistence;
|
||||
};
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
std::optional<PluginInformation> PluginInformationFactory::load(const PluginData & pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t * trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
|
||||
std::optional<PluginInformation> PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
|
||||
auto readerOpt = pluginData.getReader();
|
||||
if(!readerOpt) {
|
||||
if (!readerOpt) {
|
||||
DEBUG_FUNCTION_LINE("Can't find or process ELF file");
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -50,8 +50,8 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
uint32_t text_size = 0;
|
||||
uint32_t data_size = 0;
|
||||
|
||||
for(uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader->sections[i];
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader->sections[i];
|
||||
if (psec->get_type() == 0x80000002) {
|
||||
continue;
|
||||
}
|
||||
@@ -59,35 +59,35 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
if((address >= 0x02000000) && address < 0x10000000) {
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
text_size += sectionSize;
|
||||
} else if((address >= 0x10000000) && address < 0xC0000000) {
|
||||
} else if ((address >= 0x10000000) && address < 0xC0000000) {
|
||||
data_size += sectionSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void * text_data = MEMAllocFromExpHeapEx(heapHandle, text_size, 0x1000);
|
||||
void *text_data = MEMAllocFromExpHeapEx(heapHandle, text_size, 0x1000);
|
||||
|
||||
if(text_data == NULL) {
|
||||
if (text_data == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Failed to alloc memory for the .text section (%d bytes)\n", text_size);
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", text_size/1024);
|
||||
void * data_data = MEMAllocFromExpHeapEx(heapHandle, data_size, 0x1000);
|
||||
if(data_data == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", text_size / 1024);
|
||||
void *data_data = MEMAllocFromExpHeapEx(heapHandle, data_size, 0x1000);
|
||||
if (data_data == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Failed to alloc memory for the .data section (%d bytes)\n", data_size);
|
||||
|
||||
MEMFreeToExpHeap(heapHandle, text_data);
|
||||
return std::nullopt;
|
||||
}
|
||||
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", data_size/1024);
|
||||
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", data_size / 1024);
|
||||
|
||||
uint32_t entrypoint = (uint32_t)text_data + (uint32_t) reader->get_entry() - 0x02000000;
|
||||
uint32_t entrypoint = (uint32_t) text_data + (uint32_t) reader->get_entry() - 0x02000000;
|
||||
|
||||
for(uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader->sections[i];
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader->sections[i];
|
||||
if (psec->get_type() == 0x80000002) {
|
||||
continue;
|
||||
}
|
||||
@@ -97,15 +97,15 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
|
||||
uint32_t destination = address;
|
||||
if((address >= 0x02000000) && address < 0x10000000) {
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
destination += (uint32_t) text_data;
|
||||
destination -= 0x02000000;
|
||||
destinations[psec->get_index()] = (uint8_t *) text_data;
|
||||
} else if((address >= 0x10000000) && address < 0xC0000000) {
|
||||
} else if ((address >= 0x10000000) && address < 0xC0000000) {
|
||||
destination += (uint32_t) data_data;
|
||||
destination -= 0x10000000;
|
||||
destinations[psec->get_index()] = (uint8_t *) data_data;
|
||||
} else if(address >= 0xC0000000) {
|
||||
} else if (address >= 0xC0000000) {
|
||||
destination += (uint32_t) data_data;
|
||||
destination -= 0xC0000000;
|
||||
//destinations[psec->get_index()] = (uint8_t *) data_data;
|
||||
@@ -118,14 +118,14 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const char* p = psec->get_data();
|
||||
const char *p = psec->get_data();
|
||||
|
||||
if(psec->get_type() == SHT_NOBITS) {
|
||||
if (psec->get_type() == SHT_NOBITS) {
|
||||
DEBUG_FUNCTION_LINE("memset section %s %08X to 0 (%d bytes)", psec->get_name().c_str(), destination, sectionSize);
|
||||
memset((void*) destination, 0, sectionSize);
|
||||
} else if(psec->get_type() == SHT_PROGBITS) {
|
||||
memset((void *) destination, 0, sectionSize);
|
||||
} else if (psec->get_type() == SHT_PROGBITS) {
|
||||
DEBUG_FUNCTION_LINE("Copy section %s %08X -> %08X (%d bytes)", psec->get_name().c_str(), p, destination, sectionSize);
|
||||
memcpy((void*) destination, p, sectionSize);
|
||||
memcpy((void *) destination, p, sectionSize);
|
||||
}
|
||||
|
||||
pluginInfo.addSectionInfo(SectionInfo(psec->get_name(), destination, sectionSize));
|
||||
@@ -133,15 +133,15 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
|
||||
totalSize += sectionSize;
|
||||
|
||||
DCFlushRange((void*)destination, sectionSize);
|
||||
ICInvalidateRange((void*)destination, sectionSize);
|
||||
DCFlushRange((void *) destination, sectionSize);
|
||||
ICInvalidateRange((void *) destination, sectionSize);
|
||||
}
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader->sections[i];
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader->sections[i];
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
DEBUG_FUNCTION_LINE("Linking (%d)... %s at %08X",i,psec->get_name().c_str(), destinations[psec->get_index()]);
|
||||
DEBUG_FUNCTION_LINE("Linking (%d)... %s at %08X", i, psec->get_name().c_str(), destinations[psec->get_index()]);
|
||||
|
||||
if (!linkSection(pluginData, psec->get_index(), (uint32_t) destinations[psec->get_index()], (uint32_t) text_data, (uint32_t) data_data, trampolin_data, trampolin_data_length, trampolinId)) {
|
||||
DEBUG_FUNCTION_LINE("elfLink failed");
|
||||
@@ -154,14 +154,14 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
}
|
||||
std::vector<RelocationData> relocationData = getImportRelocationData(pluginData, destinations);
|
||||
|
||||
for (auto const& reloc : relocationData) {
|
||||
for (auto const &reloc : relocationData) {
|
||||
pluginInfo.addRelocationData(reloc);
|
||||
}
|
||||
|
||||
DCFlushRange((void*)text_data, text_size);
|
||||
ICInvalidateRange((void*)text_data, text_size);
|
||||
DCFlushRange((void*)data_data, data_size);
|
||||
ICInvalidateRange((void*)data_data, data_size);
|
||||
DCFlushRange((void *) text_data, text_size);
|
||||
ICInvalidateRange((void *) text_data, text_size);
|
||||
DCFlushRange((void *) data_data, data_size);
|
||||
ICInvalidateRange((void *) data_data, data_size);
|
||||
|
||||
free(destinations);
|
||||
|
||||
@@ -170,28 +170,30 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
DEBUG_FUNCTION_LINE("Saved entrypoint as %08X", entrypoint);
|
||||
|
||||
std::optional<SectionInfo> secInfo = pluginInfo.getSectionInfo(".wups.hooks");
|
||||
if(secInfo && secInfo->getSize() > 0) {
|
||||
if (secInfo && secInfo->getSize() > 0) {
|
||||
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t);
|
||||
wups_loader_hook_t * entries = (wups_loader_hook_t *) secInfo->getAddress();
|
||||
if(entries != NULL) {
|
||||
for(size_t j=0; j<entries_count; j++) {
|
||||
wups_loader_hook_t * hook = &entries[j];
|
||||
DEBUG_FUNCTION_LINE("Saving hook of plugin Type: %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/,hook->type,(void*) hook->target);
|
||||
HookData hook_data((void *) hook->target,hook->type);
|
||||
wups_loader_hook_t *entries = (wups_loader_hook_t *) secInfo->getAddress();
|
||||
if (entries != NULL) {
|
||||
for (size_t j = 0; j < entries_count; j++) {
|
||||
wups_loader_hook_t *hook = &entries[j];
|
||||
DEBUG_FUNCTION_LINE("Saving hook of plugin Type: %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, (void *) hook->target);
|
||||
HookData hook_data((void *) hook->target, hook->type);
|
||||
pluginInfo.addHookData(hook_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
secInfo = pluginInfo.getSectionInfo(".wups.load");
|
||||
if(secInfo && secInfo->getSize() > 0) {
|
||||
if (secInfo && secInfo->getSize() > 0) {
|
||||
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_entry_t);
|
||||
wups_loader_entry_t * entries = (wups_loader_entry_t *) secInfo->getAddress();
|
||||
if(entries != NULL) {
|
||||
for(size_t j=0; j<entries_count; j++) {
|
||||
wups_loader_entry_t * cur_function = &entries[j];
|
||||
DEBUG_FUNCTION_LINE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X",cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,cur_function->_function.physical_address,cur_function->_function.virtual_address, cur_function->_function.library,cur_function->_function.target, (void *) cur_function->_function.call_addr);
|
||||
FunctionData function_data((void *) cur_function->_function.physical_address,(void *) cur_function->_function.virtual_address, cur_function->_function.name, cur_function->_function.library, (void *) cur_function->_function.target, (void *) cur_function->_function.call_addr);
|
||||
wups_loader_entry_t *entries = (wups_loader_entry_t *) secInfo->getAddress();
|
||||
if (entries != NULL) {
|
||||
for (size_t j = 0; j < entries_count; j++) {
|
||||
wups_loader_entry_t *cur_function = &entries[j];
|
||||
DEBUG_FUNCTION_LINE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X", cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,
|
||||
cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target, (void *) cur_function->_function.call_addr);
|
||||
FunctionData function_data((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name, cur_function->_function.library,
|
||||
(void *) cur_function->_function.target, (void *) cur_function->_function.call_addr);
|
||||
pluginInfo.addFunctionData(function_data);
|
||||
}
|
||||
}
|
||||
@@ -204,45 +206,45 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
return pluginInfo;
|
||||
}
|
||||
|
||||
std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(const PluginData &pluginData, uint8_t ** destinations) {
|
||||
std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(const PluginData &pluginData, uint8_t **destinations) {
|
||||
auto readerOpt = pluginData.getReader();
|
||||
|
||||
std::vector<RelocationData> result;
|
||||
if(!readerOpt) {
|
||||
if (!readerOpt) {
|
||||
return result;
|
||||
}
|
||||
auto reader = readerOpt.value();
|
||||
std::map<uint32_t,std::string> infoMap;
|
||||
std::map<uint32_t, std::string> infoMap;
|
||||
|
||||
uint32_t sec_num = reader->sections.size();
|
||||
|
||||
for ( uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader->sections[i];
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader->sections[i];
|
||||
if (psec->get_type() == 0x80000002) {
|
||||
infoMap[i] = psec->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader->sections[i];
|
||||
if(psec->get_type() == SHT_RELA || psec->get_type() == SHT_REL) {
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s",psec->get_name().c_str());
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader->sections[i];
|
||||
if (psec->get_type() == SHT_RELA || psec->get_type() == SHT_REL) {
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s", psec->get_name().c_str());
|
||||
relocation_section_accessor rel(*reader, psec);
|
||||
for ( uint32_t j = 0; j < (uint32_t) rel.get_entries_num(); ++j ) {
|
||||
Elf64_Addr offset;
|
||||
Elf_Word type;
|
||||
Elf_Sxword addend;
|
||||
std::string sym_name;
|
||||
Elf64_Addr sym_value;
|
||||
Elf_Half sym_section_index;
|
||||
for (uint32_t j = 0; j < (uint32_t) rel.get_entries_num(); ++j) {
|
||||
Elf64_Addr offset;
|
||||
Elf_Word type;
|
||||
Elf_Sxword addend;
|
||||
std::string sym_name;
|
||||
Elf64_Addr sym_value;
|
||||
Elf_Half sym_section_index;
|
||||
|
||||
if(!rel.get_entry(j, offset, sym_value, sym_name, type, addend, 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");
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t adjusted_sym_value = (uint32_t) sym_value;
|
||||
if(adjusted_sym_value < 0xC0000000) {
|
||||
if (adjusted_sym_value < 0xC0000000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -254,7 +256,7 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
std::string rplName = "";
|
||||
std::string rawSectionName = infoMap[sym_section_index];
|
||||
|
||||
if(rawSectionName.size() < fimport.size()) {
|
||||
if (rawSectionName.size() < fimport.size()) {
|
||||
DEBUG_FUNCTION_LINE("Section name was shorter than expected, skipping this relocation");
|
||||
continue;
|
||||
} else if (std::equal(fimport.begin(), fimport.end(), rawSectionName.begin())) {
|
||||
@@ -271,75 +273,77 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
|
||||
uint32_t section_index = psec->get_info();
|
||||
|
||||
result.push_back(RelocationData(type, offset - 0x02000000, addend, (void*)(destinations[section_index]), sym_name, rplInfo));
|
||||
result.push_back(RelocationData(type, offset - 0x02000000, addend, (void *) (destinations[section_index]), sym_name, rplInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool PluginInformationFactory::linkSection(const PluginData& pluginData, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t * trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
|
||||
|
||||
bool PluginInformationFactory::linkSection(const PluginData &pluginData, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
uint8_t trampolinId) {
|
||||
auto readerOpt = pluginData.getReader();
|
||||
if(!readerOpt) {
|
||||
if (!readerOpt) {
|
||||
return false;
|
||||
}
|
||||
auto reader = readerOpt.value();
|
||||
uint32_t sec_num = reader->sections.size();
|
||||
|
||||
for (uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader->sections[i];
|
||||
if(psec->get_info() == section_index) {
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s",psec->get_name().c_str());
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader->sections[i];
|
||||
if (psec->get_info() == section_index) {
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s", psec->get_name().c_str());
|
||||
relocation_section_accessor rel(*reader, psec);
|
||||
for ( uint32_t j = 0; j < (uint32_t) rel.get_entries_num(); ++j ) {
|
||||
Elf64_Addr offset;
|
||||
Elf_Word type;
|
||||
Elf_Sxword addend;
|
||||
std::string sym_name;
|
||||
Elf64_Addr sym_value;
|
||||
Elf_Half sym_section_index;
|
||||
for (uint32_t j = 0; j < (uint32_t) rel.get_entries_num(); ++j) {
|
||||
Elf64_Addr offset;
|
||||
Elf_Word type;
|
||||
Elf_Sxword addend;
|
||||
std::string sym_name;
|
||||
Elf64_Addr sym_value;
|
||||
Elf_Half sym_section_index;
|
||||
|
||||
if(!rel.get_entry(j, offset, sym_value, sym_name, type, addend, 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");
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t adjusted_sym_value = (uint32_t) sym_value;
|
||||
if((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) {
|
||||
if ((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) {
|
||||
adjusted_sym_value -= 0x02000000;
|
||||
adjusted_sym_value += base_text;
|
||||
} else if((adjusted_sym_value >= 0x10000000) && adjusted_sym_value < 0xC0000000) {
|
||||
} else if ((adjusted_sym_value >= 0x10000000) && adjusted_sym_value < 0xC0000000) {
|
||||
adjusted_sym_value -= 0x10000000;
|
||||
adjusted_sym_value += base_data;
|
||||
} else if(adjusted_sym_value >= 0xC0000000) {
|
||||
} else if (adjusted_sym_value >= 0xC0000000) {
|
||||
//DEBUG_FUNCTION_LINE("Skip imports");
|
||||
// Skip imports
|
||||
continue;
|
||||
} else if(adjusted_sym_value == 0x0) {
|
||||
} else if (adjusted_sym_value == 0x0) {
|
||||
//
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Unhandled case %08X",adjusted_sym_value);
|
||||
DEBUG_FUNCTION_LINE("Unhandled case %08X", adjusted_sym_value);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t adjusted_offset = (uint32_t) offset;
|
||||
if((offset >= 0x02000000) && offset < 0x10000000) {
|
||||
if ((offset >= 0x02000000) && offset < 0x10000000) {
|
||||
adjusted_offset -= 0x02000000;
|
||||
} else if((adjusted_offset >= 0x10000000) && adjusted_offset < 0xC0000000) {
|
||||
} else if ((adjusted_offset >= 0x10000000) && adjusted_offset < 0xC0000000) {
|
||||
adjusted_offset -= 0x10000000;
|
||||
} else if(adjusted_offset >= 0xC0000000) {
|
||||
} else if (adjusted_offset >= 0xC0000000) {
|
||||
adjusted_offset -= 0xC0000000;
|
||||
}
|
||||
|
||||
if(sym_section_index == SHN_ABS) {
|
||||
if (sym_section_index == SHN_ABS) {
|
||||
//
|
||||
} else if(sym_section_index > SHN_LORESERVE) {
|
||||
} else if (sym_section_index > SHN_LORESERVE) {
|
||||
DEBUG_FUNCTION_LINE("NOT IMPLEMENTED: %04X", sym_section_index);
|
||||
return false;
|
||||
}
|
||||
if(false) {
|
||||
if (false) {
|
||||
DEBUG_FUNCTION_LINE("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, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED, trampolinId)) {
|
||||
if (!ElfUtils::elfLinkOne(type, adjusted_offset, addend, destination, adjusted_sym_value, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED, trampolinId)) {
|
||||
DEBUG_FUNCTION_LINE("Link failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,10 @@
|
||||
|
||||
class PluginInformationFactory {
|
||||
public:
|
||||
static std::optional<PluginInformation> load(const PluginData & pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t * trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
static bool linkSection(const PluginData & pluginData, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t * trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
static std::vector<RelocationData> getImportRelocationData(const PluginData & pluginData, uint8_t ** destinations);
|
||||
static std::optional<PluginInformation> load(const PluginData &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
|
||||
static bool
|
||||
linkSection(const PluginData &pluginData, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
|
||||
static std::vector<RelocationData> getImportRelocationData(const PluginData &pluginData, uint8_t **destinations);
|
||||
};
|
||||
|
||||
@@ -54,27 +54,27 @@ private:
|
||||
PluginMetaInformation() {
|
||||
}
|
||||
|
||||
void setName(const std::string& name) {
|
||||
void setName(const std::string &name) {
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
void setAuthor(const std::string& author) {
|
||||
void setAuthor(const std::string &author) {
|
||||
this->author = author;
|
||||
}
|
||||
|
||||
void setVersion(const std::string& version) {
|
||||
void setVersion(const std::string &version) {
|
||||
this->version = version;
|
||||
}
|
||||
|
||||
void setLicense(const std::string& license) {
|
||||
void setLicense(const std::string &license) {
|
||||
this->license = license;
|
||||
}
|
||||
|
||||
void setBuildTimestamp(const std::string& buildtimestamp) {
|
||||
void setBuildTimestamp(const std::string &buildtimestamp) {
|
||||
this->buildtimestamp = buildtimestamp;
|
||||
}
|
||||
|
||||
void setDescription(const std::string& description) {
|
||||
void setDescription(const std::string &description) {
|
||||
this->description = description;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ private:
|
||||
size_t size;
|
||||
|
||||
friend class PluginMetaInformationFactory;
|
||||
|
||||
friend class PluginContainerPersistence;
|
||||
|
||||
friend class PluginContainer;
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData& pluginData) {
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData) {
|
||||
auto readerOpt = pluginData.getReader();
|
||||
|
||||
// Load ELF data
|
||||
@@ -45,53 +45,53 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
|
||||
|
||||
DEBUG_FUNCTION_LINE("%d number of sections", sec_num);
|
||||
|
||||
for(uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader->sections[i];
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader->sections[i];
|
||||
|
||||
// Calculate total size:
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
if((address >= 0x02000000) && address < 0x10000000) {
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
pluginSize += sectionSize;
|
||||
} else if((address >= 0x10000000) && address < 0xC0000000) {
|
||||
} else if ((address >= 0x10000000) && address < 0xC0000000) {
|
||||
pluginSize += sectionSize;
|
||||
}
|
||||
}
|
||||
|
||||
// Get meta information and check WUPS version:
|
||||
if (psec->get_name().compare(".wups.meta") == 0) {
|
||||
const void * sectionData = psec->get_data();
|
||||
const void *sectionData = psec->get_data();
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
|
||||
char * curEntry = (char *) sectionData;
|
||||
while((uint32_t) curEntry < (uint32_t) sectionData + sectionSize) {
|
||||
char *curEntry = (char *) sectionData;
|
||||
while ((uint32_t) curEntry < (uint32_t) sectionData + sectionSize) {
|
||||
if (*curEntry == '\0') {
|
||||
curEntry++;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto firstFound = std::string(curEntry).find_first_of("=");
|
||||
if(firstFound != std::string::npos) {
|
||||
if (firstFound != std::string::npos) {
|
||||
curEntry[firstFound] = '\0';
|
||||
std::string key(curEntry);
|
||||
std::string value(curEntry + firstFound + 1);
|
||||
|
||||
if(key.compare("name") == 0) {
|
||||
if (key.compare("name") == 0) {
|
||||
DEBUG_FUNCTION_LINE("Name = %s", value.c_str());
|
||||
pluginInfo.setName(value);
|
||||
} else if(key.compare("author") == 0) {
|
||||
} else if (key.compare("author") == 0) {
|
||||
pluginInfo.setAuthor(value);
|
||||
} else if(key.compare("version") == 0) {
|
||||
} else if (key.compare("version") == 0) {
|
||||
pluginInfo.setVersion(value);
|
||||
} else if(key.compare("license") == 0) {
|
||||
} else if (key.compare("license") == 0) {
|
||||
pluginInfo.setLicense(value);
|
||||
} else if(key.compare("buildtimestamp") == 0) {
|
||||
} else if (key.compare("buildtimestamp") == 0) {
|
||||
pluginInfo.setBuildTimestamp(value);
|
||||
} else if(key.compare("description") == 0) {
|
||||
} else if (key.compare("description") == 0) {
|
||||
pluginInfo.setDescription(value);
|
||||
} else if(key.compare("wups") == 0) {
|
||||
if(value.compare("0.2") != 0) {
|
||||
} else if (key.compare("wups") == 0) {
|
||||
if (value.compare("0.2") != 0) {
|
||||
DEBUG_FUNCTION_LINE("Warning: Ignoring plugin - Unsupported WUPS version: %s.\n", value);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -25,5 +25,5 @@
|
||||
|
||||
class PluginMetaInformationFactory {
|
||||
public:
|
||||
static std::optional<PluginMetaInformation> loadPlugin(const PluginData& pluginData);
|
||||
static std::optional<PluginMetaInformation> loadPlugin(const PluginData &pluginData);
|
||||
};
|
||||
|
||||
@@ -23,48 +23,48 @@
|
||||
class RelocationData {
|
||||
|
||||
public:
|
||||
RelocationData(const char type, size_t offset, int32_t addend, void *destination, std::string name, ImportRPLInformation rplInfo):
|
||||
type(type),
|
||||
offset(offset),
|
||||
addend(addend),
|
||||
destination(destination),
|
||||
name(name),
|
||||
rplInfo(rplInfo) {
|
||||
RelocationData(const char type, size_t offset, int32_t addend, void *destination, std::string name, ImportRPLInformation rplInfo) :
|
||||
type(type),
|
||||
offset(offset),
|
||||
addend(addend),
|
||||
destination(destination),
|
||||
name(name),
|
||||
rplInfo(rplInfo) {
|
||||
}
|
||||
|
||||
RelocationData(const RelocationData &o2):
|
||||
type(o2.type),
|
||||
offset(o2.offset),
|
||||
addend(o2.addend),
|
||||
destination(o2.destination),
|
||||
name(o2.name),
|
||||
rplInfo(o2.rplInfo) {
|
||||
RelocationData(const RelocationData &o2) :
|
||||
type(o2.type),
|
||||
offset(o2.offset),
|
||||
addend(o2.addend),
|
||||
destination(o2.destination),
|
||||
name(o2.name),
|
||||
rplInfo(o2.rplInfo) {
|
||||
}
|
||||
|
||||
virtual ~RelocationData() {
|
||||
}
|
||||
|
||||
const char getType() const{
|
||||
const char getType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
const size_t getOffset() const{
|
||||
const size_t getOffset() const {
|
||||
return offset;
|
||||
}
|
||||
|
||||
const int32_t getAddend() const{
|
||||
const int32_t getAddend() const {
|
||||
return addend;
|
||||
}
|
||||
|
||||
const void * getDestination() const{
|
||||
const void *getDestination() const {
|
||||
return destination;
|
||||
}
|
||||
|
||||
const std::string& getName() const{
|
||||
const std::string &getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
const ImportRPLInformation& getImportRPLInformation() const{
|
||||
const ImportRPLInformation &getImportRPLInformation() const {
|
||||
return rplInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,19 +22,19 @@
|
||||
class SectionInfo {
|
||||
|
||||
public:
|
||||
SectionInfo(std::string name, uint32_t address, uint32_t sectionSize):
|
||||
name(name),
|
||||
address(address),
|
||||
sectionSize(sectionSize) {
|
||||
SectionInfo(std::string name, uint32_t address, uint32_t sectionSize) :
|
||||
name(name),
|
||||
address(address),
|
||||
sectionSize(sectionSize) {
|
||||
}
|
||||
|
||||
SectionInfo(){
|
||||
SectionInfo() {
|
||||
}
|
||||
|
||||
SectionInfo(const SectionInfo &o2):
|
||||
name(o2.name),
|
||||
address(o2.address),
|
||||
sectionSize(o2.sectionSize) {
|
||||
SectionInfo(const SectionInfo &o2) :
|
||||
name(o2.name),
|
||||
address(o2.address),
|
||||
sectionSize(o2.sectionSize) {
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
const std::string& getName() const {
|
||||
const std::string &getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user