First iteration of the WUPS-Backend as a .rpx/module for the SetupPayload

- Function replacements are not implemented yet
- Serveral features like the config menu are missing

Still WIP
This commit is contained in:
Maschell
2020-04-29 18:02:36 +02:00
parent a83d11379e
commit 2705a91c13
188 changed files with 7644 additions and 27184 deletions

View File

@@ -0,0 +1,61 @@
/****************************************************************************
* Copyright (C) 2018 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define DYN_LINK_FUNCTION_NAME_LENGTH 351
#define DYN_LINK_IMPORT_NAME_LENGTH 50
#define DYN_LINK_FUNCTION_LIST_LENGTH 500
#define DYN_LINK_IMPORT_LIST_LENGTH 50
#define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
typedef struct _dyn_linking_function_t {
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH+1];
void * address;
} dyn_linking_function_t;
typedef struct _dyn_linking_import_t {
char importName[DYN_LINK_IMPORT_NAME_LENGTH+1];
bool isData = false;
} dyn_linking_import_t;
typedef struct _dyn_linking_relocation_entry_t {
dyn_linking_function_t* functionEntry = NULL;
dyn_linking_import_t* importEntry = NULL;
void * destination = NULL;
char type;
size_t offset;
int32_t addend;
} dyn_linking_relocation_entry_t;
typedef struct _dyn_linking_relocation_data_t {
dyn_linking_function_t functions[DYN_LINK_FUNCTION_LIST_LENGTH];
dyn_linking_import_t imports[DYN_LINK_IMPORT_LIST_LENGTH];
} dyn_linking_relocation_data_t;
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,58 @@
/****************************************************************************
* Copyright (C) 2018-2019 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once
#include <stdint.h>
#include <stddef.h>
#include "dynamic_linking_defines.h"
#include "relocation_defines.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAXIMUM_MODULE_PATH_NAME_LENGTH 256
#define MAXIMUM_MODULE_NAME_LENGTH 51
#define DYN_LINK_RELOCATION_LIST_LENGTH 500
struct module_information_single_t {
char path[MAXIMUM_MODULE_PATH_NAME_LENGTH] = ""; // Path where the module is stored
dyn_linking_relocation_entry_t linking_entries[DYN_LINK_RELOCATION_LIST_LENGTH];
int32_t priority; // Priority of this module
uint32_t bssAddr;
uint32_t bssSize;
uint32_t sbssAddr;
uint32_t sbssSize;
uint32_t entrypoint;
uint32_t startAddress;
uint32_t endAddress;
};
#define MAXIMUM_MODULES 8
struct module_information_t {
int32_t number_used_modules = 0; // Number of used function. Maximum is MAXIMUM_MODULES
dyn_linking_relocation_data_t linking_data;
relocation_trampolin_entry_t trampolines[DYN_LINK_TRAMPOLIN_LIST_LENGTH];
module_information_single_t module_data[MAXIMUM_MODULES];
};
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,95 @@
/****************************************************************************
* Copyright (C) 2018-2019 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once
#include <stdint.h>
#include <stddef.h>
#include "dynamic_linking_defines.h"
#include "relocation_defines.h"
#include "replacement_defines.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAXIMUM_PLUGIN_SECTION_LENGTH 10
#define MAXIMUM_PLUGIN_SECTION_NAME_LENGTH 20
#define MAXIMUM_PLUGIN_PATH_NAME_LENGTH 256
#define MAXIMUM_PLUGIN_NAME_LENGTH 51
#define MAXIMUM_PLUGIN_DESCRIPTION_LENGTH 255
#define MAXIMUM_PLUGIN_META_FIELD_LENGTH 51
#define DYN_LINK_RELOCATION_LIST_LENGTH 500
#define MAXIMUM_HOOKS_PER_PLUGIN 25
#define MAXIMUM_FUNCTION_PER_PLUGIN 100
struct plugin_section_info_t {
char name[MAXIMUM_PLUGIN_SECTION_NAME_LENGTH] = "";
uint32_t addr;
uint32_t size;
};
struct plugin_meta_info_t {
char name[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
char author[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
char version[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
char license[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
char buildTimestamp[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
char descripion[MAXIMUM_PLUGIN_DESCRIPTION_LENGTH] = "";
uint32_t size;
};
struct plugin_info_t {
dyn_linking_relocation_entry_t linking_entries[DYN_LINK_RELOCATION_LIST_LENGTH];
plugin_section_info_t sectionInfos[MAXIMUM_PLUGIN_SECTION_LENGTH];
uint32_t number_used_functions; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN
replacement_data_function_t functions[MAXIMUM_FUNCTION_PER_PLUGIN]; // Replacement information for each function.
uint32_t number_used_hooks; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN
replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_PLUGIN]; // Replacement information for each function.
uint8_t trampolinId;
};
struct plugin_data_t {
char * buffer = NULL;
size_t bufferLength = 0;
int memoryType = 0;
int heapHandle = 0;
};
struct plugin_information_single_t {
plugin_meta_info_t meta;
plugin_info_t info;
plugin_data_t data;
int32_t priority; // Priority of this plugin
};
#define MAXIMUM_PLUGINS 32
struct plugin_information_t {
int32_t number_used_plugins = 0; // Number of used plugins. Maximum is MAXIMUM_PLUGINS
plugin_information_single_t plugin_data[MAXIMUM_PLUGINS];
relocation_trampolin_entry_t trampolines[DYN_LINK_TRAMPOLIN_LIST_LENGTH];
dyn_linking_relocation_data_t linking_data; // RPL and function name list
};
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,20 @@
#pragma once
#include <stdint.h>
typedef enum RelocationTrampolinStatus{
RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3,
} RelocationTrampolinStatus;
typedef enum RelocationType{
RELOC_TYPE_FIXED = 0,
RELOC_TYPE_IMPORT = 1
} RelocationType;
typedef struct relocation_trampolin_entry_t {
uint32_t id;
uint32_t trampolin[4];
RelocationTrampolinStatus status = RELOC_TRAMP_FREE;
} relocation_trampolin_entry_t;

View File

@@ -0,0 +1,25 @@
#pragma once
#include <stdint.h>
#include <wups.h>
#define FUNCTION_PATCHER_METHOD_STORE_SIZE 13
#define MAXIMUM_FUNCTION_NAME_LENGTH 83
struct replacement_data_function_t {
uint32_t physicalAddr; /* [needs to be filled] */
uint32_t virtualAddr; /* [needs to be filled] */
uint32_t replaceAddr; /* [needs to be filled] Address of our replacement function */
uint32_t replaceCall; /* [needs to be filled] Address to access the real_function */
wups_loader_library_type_t library; /* [needs to be filled] rpl where the function we want to replace is. */
char function_name[MAXIMUM_FUNCTION_NAME_LENGTH]; /* [needs to be filled] name of the function we want to replace */
uint32_t realAddr; /* [will be filled] Address of the real function we want to replace. */
volatile uint32_t replace_data [FUNCTION_PATCHER_METHOD_STORE_SIZE]; /* [will be filled] Space for us to store some jump instructions */
uint32_t restoreInstruction; /* [will be filled] Copy of the instruction we replaced to jump to our code. */
uint8_t functionType; /* [will be filled] */
uint8_t alreadyPatched; /* [will be filled] */
};
struct replacement_data_hook_t {
void * func_pointer = NULL; /* [will be filled] */
wups_loader_hook_type_t type; /* [will be filled] */
};