Format the code via clang-format

This commit is contained in:
Maschell 2022-02-04 16:25:44 +01:00
parent c21f9d8567
commit 2547c7edca
75 changed files with 637 additions and 554 deletions

67
.clang-format Normal file
View File

@ -0,0 +1,67 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -6,8 +6,16 @@ on:
- master
jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary
@ -26,7 +34,7 @@ jobs:
id: get_repository_name
run: |
echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV
echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV
echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV
- uses: actions/download-artifact@master
with:
name: binary

View File

@ -1,16 +0,0 @@
name: Build binary
on:
push:
branches-ignore:
- master
jobs:
build-binary:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: build binary
run: |
docker build . -t builder
docker run --rm -v ${PWD}:/project builder make

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request]
jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary

View File

@ -1,4 +1,6 @@
# Wii U Plugin Loader Backend
[![CI-Release](https://github.com/wiiu-env/WiiUPluginLoaderBackend/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/WiiUPluginLoaderBackend/actions/workflows/ci.yml)
# Wii U Plugin Loader Backend
This is the Backend for the [WiiUPluginSystem](https://github.com/Maschell/WiiUPluginSystem). Check out the readme for more information about the Plugin System.
## Usage
@ -46,6 +48,10 @@ docker run -it --rm -v ${PWD}:/project wiiupluginloaderbackend-builder make
docker run -it --rm -v ${PWD}:/project wiiupluginloaderbackend-builder make clean
```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`
# Credits
- Maschell
- orboditilt

View File

@ -1,23 +1,23 @@
#include <memory.h>
#include <coreinit/cache.h>
#include <coreinit/dynload.h>
#include <coreinit/memdefaultheap.h>
#include <memory.h>
#include <memory>
#include "patcher/hooks_patcher_static.h"
#include "plugin/PluginContainer.h"
#include "plugin/PluginMetaInformationFactory.h"
#include "plugin/PluginInformationFactory.h"
#include "plugin/PluginMetaInformationFactory.h"
#include "utils/ElfUtils.h"
#include "PluginManagement.h"
#include "hooks.h"
#include "globals.h"
#include "hooks.h"
#include "utils/ElfUtils.h"
bool PluginManagement::doRelocation(const std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampoline_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolineID) {
std::map<std::string, OSDynLoad_Module> moduleHandleCache;
for (auto const &cur: relocData) {
uint32_t functionAddress = 0;
for (auto const &cur : relocData) {
uint32_t functionAddress = 0;
const std::string &functionName = cur->getName();
if (functionName == "MEMAllocFromDefaultHeap") {
@ -35,8 +35,8 @@ bool PluginManagement::doRelocation(const std::vector<std::shared_ptr<Relocation
}
if (functionAddress == 0) {
std::string rplName = cur->getImportRPLInformation()->getName();
int32_t isData = cur->getImportRPLInformation()->isData();
std::string rplName = cur->getImportRPLInformation()->getName();
int32_t isData = cur->getImportRPLInformation()->isData();
OSDynLoad_Module rplHandle = nullptr;
if (moduleHandleCache.count(rplName) > 0) {
rplHandle = moduleHandleCache[rplName];
@ -66,7 +66,7 @@ bool PluginManagement::doRelocation(const std::vector<std::shared_ptr<Relocation
void PluginManagement::doRelocations(const std::vector<std::shared_ptr<PluginContainer>> &plugins, relocation_trampoline_entry_t *trampData, uint32_t tramp_size) {
for (auto &pluginContainer: plugins) {
for (auto &pluginContainer : plugins) {
DEBUG_FUNCTION_LINE_VERBOSE("Doing relocations for plugin: %s", pluginContainer->getMetaInformation()->getName().c_str());
if (!PluginManagement::doRelocation(pluginContainer->getPluginInformation()->getRelocationDataList(), trampData, tramp_size, pluginContainer->getPluginInformation()->getTrampolineId())) {
@ -76,7 +76,7 @@ void PluginManagement::doRelocations(const std::vector<std::shared_ptr<PluginCon
}
void PluginManagement::memsetBSS(const std::vector<std::shared_ptr<PluginContainer>> &plugins) {
for (auto &pluginContainer: plugins) {
for (auto &pluginContainer : plugins) {
auto sbssSection = pluginContainer->getPluginInformation()->getSectionInfo(".sbss");
if (sbssSection) {
DEBUG_FUNCTION_LINE_VERBOSE("memset .sbss %08X (%d)", sbssSection.value()->getAddress(), sbssSection.value()->getSize());
@ -128,7 +128,7 @@ void PluginManagement::unloadPlugins(plugin_information_t *pluginInformation, ME
DEBUG_FUNCTION_LINE("Failed to free memory from plugin");
DEBUG_FUNCTION_LINE("########################");
}
plugin->data.buffer = nullptr;
plugin->data.buffer = nullptr;
plugin->data.bufferLength = 0;
} else {
DEBUG_FUNCTION_LINE("Plugin has no copy of elf saved in memory, can't free it");
@ -146,7 +146,7 @@ void PluginManagement::unloadPlugins(plugin_information_t *pluginInformation, ME
for (uint32_t i = 0; i < gTrampolineDataSize; i++) {
auto trampoline = &(gTrampolineData[i]);
if (trampoline->id == plugin->info.trampolineId) {
trampoline->id = 0;
trampoline->id = 0;
trampoline->status = RELOC_TRAMP_FREE;
}
}
@ -192,7 +192,7 @@ std::vector<std::shared_ptr<PluginContainer>>
PluginManagement::loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pluginList, MEMHeapHandle heapHandle, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length) {
std::vector<std::shared_ptr<PluginContainer>> plugins;
for (auto &pluginData: pluginList) {
for (auto &pluginData : pluginList) {
DEBUG_FUNCTION_LINE_VERBOSE("Load meta information");
auto metaInfo = PluginMetaInformationFactory::loadPlugin(pluginData);
if (metaInfo) {
@ -205,7 +205,7 @@ PluginManagement::loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pl
}
}
uint32_t trampolineID = 0;
for (auto &pluginContainer: plugins) {
for (auto &pluginContainer : plugins) {
auto info = PluginInformationFactory::load(pluginContainer->getPluginData(), heapHandle, trampoline_data, trampoline_data_length, trampolineID++);
if (!info) {
DEBUG_FUNCTION_LINE("Failed to load Plugin %s", pluginContainer->getMetaInformation()->getName().c_str());
@ -215,4 +215,3 @@ PluginManagement::loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pl
}
return plugins;
}

View File

@ -1,11 +1,12 @@
#pragma once
#include "plugin/PluginContainer.h"
#include <common/plugin_defines.h>
#include <memory>
#include <vector>
class PluginManagement {
public:
static void doRelocations(const std::vector<std::shared_ptr<PluginContainer>> &plugins, relocation_trampoline_entry_t *trampData, uint32_t tramp_size);
static void memsetBSS(const std::vector<std::shared_ptr<PluginContainer>> &plugins);

View File

@ -17,8 +17,8 @@
#pragma once
#include <cstdint>
#include <cstddef>
#include <cstdint>
#include <wums/defines/dynamic_linking_defines.h>
#include <wums/defines/export_defines.h>
#include <wums/defines/relocation_defines.h>
@ -30,18 +30,18 @@
extern "C" {
#endif
#define MAXIMUM_PLUGIN_SECTION_LENGTH 10
#define MAXIMUM_PLUGIN_SECTION_NAME_LENGTH 20
#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 100
#define MAXIMUM_PLUGIN_META_FIELD_LENGTH 51
#define MAXIMUM_PLUGIN_PATH_NAME_LENGTH 256
#define MAXIMUM_PLUGIN_NAME_LENGTH 51
#define MAXIMUM_PLUGIN_DESCRIPTION_LENGTH 100
#define MAXIMUM_PLUGIN_META_FIELD_LENGTH 51
#define PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH 1000
#define PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH 1000
#define MAXIMUM_HOOKS_PER_PLUGIN 25
#define MAXIMUM_FUNCTION_PER_PLUGIN 100
#define MAXIMUM_HOOKS_PER_PLUGIN 25
#define MAXIMUM_FUNCTION_PER_PLUGIN 100
struct plugin_section_info_t {
char name[MAXIMUM_PLUGIN_SECTION_NAME_LENGTH] = "";
@ -50,68 +50,68 @@ struct plugin_section_info_t {
};
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] = "";
char storageId[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
uint32_t size{};
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] = "";
char storageId[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
uint32_t size{};
};
struct replacement_data_hook_t {
void * func_pointer = nullptr; /* [will be filled] */
wups_loader_hook_type_t type{}; /* [will be filled] */
void *func_pointer = nullptr; /* [will be filled] */
wups_loader_hook_type_t type{}; /* [will be filled] */
};
struct plugin_function_symbol_data_t {
char* name;
void* address;
char *name;
void *address;
uint32_t size;
};
struct plugin_info_t {
dyn_linking_relocation_entry_t linking_entries[PLUGIN_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
function_replacement_data_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 trampolineId{};
plugin_function_symbol_data_t * function_symbol_data = nullptr;
uint32_t number_function_symbol_data = 0;
void * allocatedTextMemoryAddress = nullptr;
void * allocatedDataMemoryAddress = nullptr;
void * allocatedFuncSymStringTableAddress = nullptr;
dyn_linking_relocation_entry_t linking_entries[PLUGIN_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
function_replacement_data_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 trampolineId{};
plugin_function_symbol_data_t *function_symbol_data = nullptr;
uint32_t number_function_symbol_data = 0;
void *allocatedTextMemoryAddress = nullptr;
void *allocatedDataMemoryAddress = nullptr;
void *allocatedFuncSymStringTableAddress = nullptr;
};
struct plugin_data_t {
char * buffer = nullptr;
size_t bufferLength = 0;
int memoryType = 0;
int heapHandle = 0;
char *buffer = nullptr;
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
plugin_meta_info_t meta;
plugin_info_t info;
plugin_data_t data;
int32_t priority{}; // Priority of this plugin
};
#define MAXIMUM_PLUGINS 32
#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];
dyn_linking_relocation_data_t linking_data{}; // RPL and function name list
int32_t number_used_plugins = 0; // Number of used plugins. Maximum is MAXIMUM_PLUGINS
plugin_information_single_t plugin_data[MAXIMUM_PLUGINS];
dyn_linking_relocation_data_t linking_data{}; // RPL and function name list
};
struct plugin_information_on_reload_t {
int32_t number_used_plugins = 0; // Number of used plugins. Maximum is MAXIMUM_PLUGINS
plugin_data_t plugin_data[MAXIMUM_PLUGINS];
bool loadOnReload = false;
int32_t number_used_plugins = 0; // Number of used plugins. Maximum is MAXIMUM_PLUGINS
plugin_data_t plugin_data[MAXIMUM_PLUGINS];
bool loadOnReload = false;
};
#ifdef __cplusplus

View File

@ -17,12 +17,12 @@
#pragma once
#include <string>
#include <vector>
#include <optional>
#include <wups/config.h>
#include "WUPSConfigCategory.h"
#include "utils/logger.h"
#include <optional>
#include <string>
#include <vector>
#include <wups/config.h>
class WUPSConfig {
public:
@ -31,7 +31,7 @@ public:
}
~WUPSConfig() {
for (auto &element: categories) {
for (auto &element : categories) {
delete element;
}
}

View File

@ -17,10 +17,10 @@
#pragma once
#include "WUPSConfigItem.h"
#include <string>
#include <vector>
#include <wups/config.h>
#include "WUPSConfigItem.h"
class WUPSConfigCategory {
public:
@ -29,7 +29,7 @@ public:
}
~WUPSConfigCategory() {
for (auto &element: items) {
for (auto &element : items) {
delete element;
}
}

View File

@ -1,7 +1,7 @@
#include "../utils/logger.h"
#include "WUPSConfigCategory.h"
#include <wums.h>
#include <wups/config.h>
#include "WUPSConfigCategory.h"
#include "../utils/logger.h"
int32_t WUPSConfigCategory_Create(WUPSConfigCategoryHandle *out, const char *name) {
if (name == nullptr || out == nullptr) {
@ -39,7 +39,7 @@ int32_t WUPSConfigCategory_AddItem(WUPSConfigCategoryHandle handle, WUPSConfigIt
return -1;
}
auto *category = reinterpret_cast<WUPSConfigCategory *>(handle);
auto *item = reinterpret_cast<WUPSConfigItem *>(item_Handle);
auto *item = reinterpret_cast<WUPSConfigItem *>(item_Handle);
if (category->addItem(item)) {
return 0;
}

View File

@ -1,7 +1,7 @@
#include "../utils/logger.h"
#include "WUPSConfig.h"
#include <wums.h>
#include <wups/config.h>
#include "WUPSConfig.h"
#include "../utils/logger.h"
int32_t WUPSConfig_Create(WUPSConfigHandle *out, const char *name) {
if (name == nullptr || out == nullptr) {
@ -40,7 +40,7 @@ int32_t WUPSConfig_AddCategoryByName(WUPSConfigHandle handle, const char *catego
return -1;
}
auto *config = reinterpret_cast<WUPSConfig *>(handle);
auto res = config->addCategory(std::string(categoryName));
auto res = config->addCategory(std::string(categoryName));
if (res.has_value()) {
if (out != nullptr) {
*out = reinterpret_cast<WUPSConfigCategoryHandle>(res.value());
@ -54,7 +54,7 @@ int32_t WUPSConfig_AddCategoryByName(WUPSConfigHandle handle, const char *catego
int32_t WUPSConfig_AddCategory(WUPSConfigHandle handle, WUPSConfigCategoryHandle category) {
auto *config = reinterpret_cast<WUPSConfig *>(handle);
auto res = config->addCategory(reinterpret_cast<WUPSConfigCategory *>(category));
auto res = config->addCategory(reinterpret_cast<WUPSConfigCategory *>(category));
if (res == nullptr) {
return -1;
}

View File

@ -20,9 +20,9 @@
#include <string>
#include <vector>
#include <wups/config.h>
#include "utils/StringTools.h"
#include "utils/logger.h"
#include <wups/config.h>
class WUPSConfigItem {
public:
@ -154,10 +154,10 @@ public:
}
WUPSConfigItem(const std::string &_configID, const std::string &_displayName, WUPSConfigCallbacks_t callbacks, void *_context) {
this->configID = _configID;
this->displayName = _displayName;
this->context = _context;
this->callbacks = callbacks;
this->configID = _configID;
this->displayName = _displayName;
this->context = _context;
this->callbacks = callbacks;
this->defaultValue = getCurrentValueDisplay();
}

View File

@ -1,6 +1,6 @@
#include "WUPSConfigItem.h"
#include <wums.h>
#include <wups/config.h>
#include "WUPSConfigItem.h"
typedef uint32_t WUPSConfigItemHandle;

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,14 +1,14 @@
#include <cstdarg>
#include <cstdio>
#include <strings.h>
#include <fs/CFile.hpp>
#include <strings.h>
CFile::CFile() {
iFd = -1;
iFd = -1;
mem_file = nullptr;
filesize = 0;
pos = 0;
pos = 0;
}
CFile::CFile(const std::string &filepath, eOpenTypes mode) {
@ -34,7 +34,7 @@ int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
switch (mode) {
default:
case ReadOnly: // file must exist
case ReadOnly: // file must exist
openMode = O_RDONLY;
break;
case WriteOnly: // file will be created / zerod
@ -76,10 +76,10 @@ void CFile::close() {
if (iFd >= 0)
::close(iFd);
iFd = -1;
iFd = -1;
mem_file = nullptr;
filesize = 0;
pos = 0;
pos = 0;
}
int32_t CFile::read(uint8_t *ptr, size_t size) {
@ -126,7 +126,7 @@ int32_t CFile::write(const uint8_t *ptr, size_t size) {
}
int32_t CFile::seek(long int offset, int32_t origin) {
int32_t ret = 0;
int32_t ret = 0;
int64_t newPos = pos;
if (origin == SEEK_SET) {
@ -157,7 +157,7 @@ int32_t CFile::seek(long int offset, int32_t origin) {
int32_t CFile::fwrite(const char *format, ...) {
char tmp[512];
tmp[0] = 0;
tmp[0] = 0;
int32_t result = -1;
va_list va;
@ -170,5 +170,3 @@ int32_t CFile::fwrite(const char *format, ...) {
return result;
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <cstdio>
#include <string>
#include <cstring>
#include <fcntl.h>
#include <string>
#include <unistd.h>
#include <wut_types.h>

View File

@ -24,22 +24,22 @@
* DirList Class
* for WiiXplorer 2010
***************************************************************************/
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <strings.h>
#include <algorithm>
#include <sys/stat.h>
#include <sys/dirent.h>
#include <sys/stat.h>
#include <fs/DirList.h>
#include <utils/StringTools.h>
DirList::DirList() {
Flags = 0;
Flags = 0;
Filter = 0;
Depth = 0;
Depth = 0;
}
DirList::DirList(const std::string &path, const char *filter, uint32_t flags, uint32_t maxDepth) {
@ -55,9 +55,9 @@ BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t f
if (folder.empty())
return false;
Flags = flags;
Flags = flags;
Filter = filter;
Depth = maxDepth;
Depth = maxDepth;
std::string folderpath(folder);
uint32_t length = folderpath.size();
@ -82,14 +82,14 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
return false;
struct dirent *dirent = nullptr;
DIR *dir = nullptr;
DIR *dir = nullptr;
dir = opendir(folderpath.c_str());
if (dir == nullptr)
return false;
while ((dirent = readdir(dir)) != 0) {
BOOL isDir = dirent->d_type & DT_DIR;
BOOL isDir = dirent->d_type & DT_DIR;
const char *filename = dirent->d_name;
if (isDir) {

View File

@ -27,8 +27,8 @@
#ifndef ___DIRLIST_H_
#define ___DIRLIST_H_
#include <vector>
#include <string>
#include <vector>
#include <wut_types.h>
typedef struct {
@ -93,10 +93,11 @@ public:
//! Enum for search/filter flags
enum {
Files = 0x01,
Dirs = 0x02,
Files = 0x01,
Dirs = 0x02,
CheckSubfolders = 0x08,
};
protected:
// Internal parser
BOOL InternalLoadPath(std::string &path);

View File

@ -1,11 +1,11 @@
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "fs/FSUtils.h"
#include "fs/CFile.hpp"
#include "utils/logger.h"
#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input
@ -27,8 +27,8 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
}
uint32_t blocksize = 0x4000;
uint32_t done = 0;
int32_t readBytes = 0;
uint32_t done = 0;
int32_t readBytes = 0;
while (done < filesize) {
if (done + blocksize > filesize) {
@ -139,4 +139,3 @@ int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size)
file.close();
return written;
}

View File

@ -1,15 +1,15 @@
#include "globals.h"
MEMHeapHandle gPluginDataHeap __attribute__((section(".data"))) = nullptr;
MEMHeapHandle gPluginInformationHeap __attribute__((section(".data"))) = nullptr;
MEMHeapHandle gPluginDataHeap __attribute__((section(".data"))) = nullptr;
MEMHeapHandle gPluginInformationHeap __attribute__((section(".data"))) = nullptr;
plugin_information_t *gPluginInformation __attribute__((section(".data"))) = nullptr;
plugin_information_on_reload_t gLinkOnReload __attribute__((section(".data")));
module_information_t *gModuleData __attribute__((section(".data"))) = nullptr;
module_information_t *gModuleData __attribute__((section(".data"))) = nullptr;
relocation_trampoline_entry_t *gTrampolineData __attribute__((section(".data"))) = nullptr;
uint32_t gPluginDataHeapSize = 0;
uint32_t gPluginDataHeapSize = 0;
uint32_t gPluginInformationHeapSize = 0;
uint32_t gTrampolineDataSize = 0;
uint32_t gTrampolineDataSize = 0;
StoredBuffer storedTVBuffer{};
StoredBuffer storedDRCBuffer{};

View File

@ -2,8 +2,8 @@
#include <wums.h>
#include "plugin/PluginContainer.h"
#include "common/plugin_defines.h"
#include "plugin/PluginContainer.h"
#include "utils/ConfigUtils.h"
extern plugin_information_t *gPluginInformation;
@ -19,4 +19,4 @@ extern StoredBuffer storedTVBuffer;
extern StoredBuffer storedDRCBuffer;
#define PLUGIN_DATA_HEAP_SIZE (8 * 1024 * 1024)
#define NUMBER_OF_TRAMPS 1024
#define NUMBER_OF_TRAMPS 1024

View File

@ -1,6 +1,6 @@
#include "hooks.h"
#include "utils/logger.h"
#include "utils/StorageUtils.h"
#include "utils/logger.h"
void CallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type) {
CallHookEx(pluginInformation, hook_type, -1);
@ -20,7 +20,7 @@ bool HasHookCallHook(plugin_information_t *pluginInformation, wups_loader_hook_t
return false;
}
static const char **hook_names = (const char *[]) {
static const char **hook_names = (const char *[]){
"WUPS_LOADER_HOOK_INIT_WUT_MALLOC",
"WUPS_LOADER_HOOK_FINI_WUT_MALLOC",
"WUPS_LOADER_HOOK_INIT_WUT_NEWLIB",
@ -87,15 +87,14 @@ void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t
hook_type == WUPS_LOADER_HOOK_GET_CONFIG ||
hook_type == WUPS_LOADER_HOOK_CONFIG_CLOSED ||
hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND ||
hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND
) {
((void (*)()) ((uint32_t *) func_ptr))();
hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND) {
((void (*)())((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_STORAGE) {
wups_loader_init_storage_args_t args;
args.open_storage_ptr = &StorageUtils::OpenStorage;
args.open_storage_ptr = &StorageUtils::OpenStorage;
args.close_storage_ptr = &StorageUtils::CloseStorage;
args.plugin_id = plugin_data->meta.storageId;
((void (*)(wups_loader_init_storage_args_t)) ((uint32_t *) func_ptr))(args);
args.plugin_id = plugin_data->meta.storageId;
((void (*)(wups_loader_init_storage_args_t))((uint32_t *) func_ptr))(args);
} else {
DEBUG_FUNCTION_LINE("######################################");
DEBUG_FUNCTION_LINE("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type);

View File

@ -1,7 +1,7 @@
#pragma once
#include <wups.h>
#include "common/plugin_defines.h"
#include <wups.h>
void CallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type);

View File

@ -1,18 +1,18 @@
#include <wums.h>
#include <coreinit/debug.h>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <coreinit/dynload.h>
#include <coreinit/memdefaultheap.h>
#include <memory>
#include "plugin/PluginContainer.h"
#include "globals.h"
#include "plugin/PluginDataFactory.h"
#include "plugin/PluginDataPersistence.h"
#include "plugin/PluginContainerPersistence.h"
#include "PluginManagement.h"
#include "globals.h"
#include "hooks.h"
#include "patcher/hooks_patcher_static.h"
#include "plugin/PluginContainer.h"
#include "plugin/PluginContainerPersistence.h"
#include "plugin/PluginDataFactory.h"
#include "plugin/PluginDataPersistence.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/ios.h>
#include <coreinit/memdefaultheap.h>
#include <memory>
#include <wums.h>
WUMS_MODULE_EXPORT_NAME("homebrew_wupsbackend");
@ -104,10 +104,10 @@ WUMS_APPLICATION_STARTS() {
void *pluginHeapMemory = allocOnCustomHeap(0x1000, PLUGIN_DATA_HEAP_SIZE);
if (pluginHeapMemory == nullptr) {
DEBUG_FUNCTION_LINE("Use plugins information heap as fallback");
gPluginDataHeap = gPluginInformationHeap;
gPluginDataHeap = gPluginInformationHeap;
gPluginDataHeapSize = gPluginInformationHeapSize;
} else {
gPluginDataHeap = MEMCreateExpHeapEx(pluginHeapMemory, PLUGIN_DATA_HEAP_SIZE, 0);
gPluginDataHeap = MEMCreateExpHeapEx(pluginHeapMemory, PLUGIN_DATA_HEAP_SIZE, 0);
gPluginDataHeapSize = PLUGIN_DATA_HEAP_SIZE;
}
@ -141,9 +141,9 @@ WUMS_APPLICATION_STARTS() {
DEBUG_FUNCTION_LINE("Loaded data for %d plugins.", pluginList.size());
auto plugins = PluginManagement::loadPlugins(pluginList, gPluginDataHeap, gTrampolineData, gTrampolineDataSize);
for (auto &pluginContainer: plugins) {
for (auto &pluginContainer : plugins) {
#ifdef DEBUG
for (const auto &kv: pluginContainer->getPluginInformation()->getSectionInfoList()) {
for (const auto &kv : pluginContainer->getPluginInformation()->getSectionInfoList()) {
DEBUG_FUNCTION_LINE_VERBOSE("%s = %s %08X %d", kv.first.c_str(), kv.second->getName().c_str(), kv.second->getAddress(), kv.second->getSize());
}
#endif
@ -165,8 +165,8 @@ WUMS_APPLICATION_STARTS() {
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
plugin_information_single_t *plugin = &(gPluginInformation->plugin_data[plugin_index]);
BOOL doDelete = true;
for (auto &pluginData: pluginDataList) {
BOOL doDelete = true;
for (auto &pluginData : pluginDataList) {
if (pluginData->buffer == plugin->data.buffer) {
doDelete = false;
break;
@ -186,7 +186,7 @@ WUMS_APPLICATION_STARTS() {
DEBUG_FUNCTION_LINE("Failed to free memory from plugin");
DEBUG_FUNCTION_LINE("########################");
}
plugin->data.buffer = nullptr;
plugin->data.buffer = nullptr;
plugin->data.bufferLength = 0;
} else {
DEBUG_FUNCTION_LINE("Plugin %s has no copy of elf saved in memory, can't free it", plugin->meta.name);
@ -198,14 +198,14 @@ WUMS_APPLICATION_STARTS() {
auto plugins = PluginManagement::loadPlugins(pluginDataList, gPluginDataHeap, gTrampolineData, gTrampolineDataSize);
for (auto &pluginContainer: plugins) {
for (auto &pluginContainer : plugins) {
DEBUG_FUNCTION_LINE("Stored information for plugin %s ; %s", pluginContainer->getMetaInformation()->getName().c_str(), pluginContainer->getMetaInformation()->getAuthor().c_str());
if (!PluginContainerPersistence::savePlugin(gPluginInformation, pluginContainer, gPluginDataHeap)) {
DEBUG_FUNCTION_LINE("Failed to save plugin");
}
}
gLinkOnReload.loadOnReload = false;
initNeeded = true;
initNeeded = true;
}
if (gPluginDataHeap != nullptr) {
@ -241,8 +241,8 @@ void *allocOnCustomHeap(int alignment, int size) {
return nullptr;
}
uint32_t *custom_memalign;
dyn_res = OSDynLoad_FindExport(module, true, "MEMAllocFromMappedMemoryEx", reinterpret_cast<void **>(&custom_memalign));
auto *customMEMAllocFromDefaultHeapEx = (void *(*)(uint32_t, int)) *custom_memalign;
dyn_res = OSDynLoad_FindExport(module, true, "MEMAllocFromMappedMemoryEx", reinterpret_cast<void **>(&custom_memalign));
auto *customMEMAllocFromDefaultHeapEx = (void *(*) (uint32_t, int) ) * custom_memalign;
if (dyn_res != OS_DYNLOAD_OK) {
return nullptr;

View File

@ -1,16 +1,16 @@
#include "hooks_patcher_static.h"
#include <wups.h>
#include <vpad/input.h>
#include <padscore/wpad.h>
#include <coreinit/messagequeue.h>
#include <coreinit/core.h>
#include <coreinit/messagequeue.h>
#include <padscore/wpad.h>
#include <vpad/input.h>
#include <wups.h>
#include "../utils/ConfigUtils.h"
#include "../globals.h"
#include "../hooks.h"
#include "../utils/ConfigUtils.h"
uint8_t vpadPressCooldown = 0xFF;
bool configMenuOpened = false;
uint8_t vpadPressCooldown = 0xFF;
bool configMenuOpened = false;
bool wantsToOpenConfigMenu = false;
DECL_FUNCTION(void, GX2SwapScanBuffers, void) {
@ -19,15 +19,15 @@ DECL_FUNCTION(void, GX2SwapScanBuffers, void) {
if (wantsToOpenConfigMenu && !configMenuOpened) {
configMenuOpened = true;
ConfigUtils::openConfigMenu();
configMenuOpened = false;
configMenuOpened = false;
wantsToOpenConfigMenu = false;
}
}
DECL_FUNCTION(void, GX2SetTVBuffer, void *buffer, uint32_t buffer_size, int32_t tv_render_mode, GX2SurfaceFormat format, GX2BufferingMode buffering_mode) {
storedTVBuffer.buffer = buffer;
storedTVBuffer.buffer_size = buffer_size;
storedTVBuffer.mode = tv_render_mode;
storedTVBuffer.buffer = buffer;
storedTVBuffer.buffer_size = buffer_size;
storedTVBuffer.mode = tv_render_mode;
storedTVBuffer.surface_format = format;
storedTVBuffer.buffering_mode = buffering_mode;
@ -35,9 +35,9 @@ DECL_FUNCTION(void, GX2SetTVBuffer, void *buffer, uint32_t buffer_size, int32_t
}
DECL_FUNCTION(void, GX2SetDRCBuffer, void *buffer, uint32_t buffer_size, uint32_t drc_mode, GX2SurfaceFormat surface_format, GX2BufferingMode buffering_mode) {
storedDRCBuffer.buffer = buffer;
storedDRCBuffer.buffer_size = buffer_size;
storedDRCBuffer.mode = drc_mode;
storedDRCBuffer.buffer = buffer;
storedDRCBuffer.buffer_size = buffer_size;
storedDRCBuffer.mode = drc_mode;
storedDRCBuffer.surface_format = surface_format;
storedDRCBuffer.buffering_mode = buffering_mode;
@ -75,7 +75,7 @@ DECL_FUNCTION(int32_t, VPADRead, int32_t chan, VPADStatus *buffer, uint32_t buff
if (result > 0 && (buffer[0].hold == (VPAD_BUTTON_L | VPAD_BUTTON_DOWN | VPAD_BUTTON_MINUS)) && vpadPressCooldown == 0 && !configMenuOpened) {
wantsToOpenConfigMenu = true;
vpadPressCooldown = 0x3C;
vpadPressCooldown = 0x3C;
}
if (vpadPressCooldown > 0) {
@ -103,11 +103,11 @@ DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) {
}
#define KiReport ((void (*)( const char*, ... ))0xfff0ad0c)
#define KiReport ((void (*)(const char *, ...)) 0xfff0ad0c)
#pragma GCC push_options
#pragma GCC optimize ("O0")
#pragma GCC optimize("O0")
DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol,
uint32_t addr,
@ -118,9 +118,9 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol,
uint32_t moduleNameBufferLength) {
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
plugin_information_single_t *plugin = &(gPluginInformation->plugin_data[plugin_index]);
plugin_section_info_t *section = nullptr;
plugin_section_info_t *section = nullptr;
for (auto &sectionInfo: plugin->info.sectionInfos) {
for (auto &sectionInfo : plugin->info.sectionInfos) {
if (sectionInfo.addr == 0 && sectionInfo.size == 0) {
break;
}
@ -139,7 +139,7 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol,
strncpy(moduleNameBuffer, plugin->meta.name, moduleNameBufferLength);
if (plugin->info.function_symbol_data != nullptr && plugin->info.number_function_symbol_data > 1) {
for (uint32_t i = 0; i < plugin->info.number_function_symbol_data - 1; i++) {
auto symbolData = &plugin->info.function_symbol_data[i];
auto symbolData = &plugin->info.function_symbol_data[i];
auto symbolDataNext = &plugin->info.function_symbol_data[i + 1];
if (i == plugin->info.number_function_symbol_data - 2 || (addr >= (uint32_t) symbolData->address && addr < (uint32_t) symbolDataNext->address)) {
strncpy(symbolNameBuffer, symbolData->name, moduleNameBufferLength);
@ -166,9 +166,9 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol,
DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t bufSize) {
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
plugin_information_single_t *plugin = &(gPluginInformation->plugin_data[plugin_index]);
plugin_section_info_t *section = nullptr;
plugin_section_info_t *section = nullptr;
for (auto &sectionInfo: plugin->info.sectionInfos) {
for (auto &sectionInfo : plugin->info.sectionInfos) {
if (sectionInfo.addr == 0 && sectionInfo.size == 0) {
break;
}
@ -184,7 +184,7 @@ DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t
continue;
}
auto pluginNameLen = strlen(plugin->meta.name);
auto pluginNameLen = strlen(plugin->meta.name);
int32_t spaceLeftInBuffer = (int32_t) bufSize - (int32_t) pluginNameLen - 1;
if (spaceLeftInBuffer < 0) {
spaceLeftInBuffer = 0;
@ -193,11 +193,11 @@ DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t
if (plugin->info.function_symbol_data != nullptr && plugin->info.number_function_symbol_data > 1) {
for (uint32_t i = 0; i < plugin->info.number_function_symbol_data - 1; i++) {
auto symbolData = &plugin->info.function_symbol_data[i];
auto symbolData = &plugin->info.function_symbol_data[i];
auto symbolDataNext = &plugin->info.function_symbol_data[i + 1];
if (i == plugin->info.number_function_symbol_data - 2 || (addr >= (uint32_t) symbolData->address && addr < (uint32_t) symbolDataNext->address)) {
if (spaceLeftInBuffer > 2) {
buffer[pluginNameLen] = '|';
buffer[pluginNameLen] = '|';
buffer[pluginNameLen + 1] = '\0';
strncpy(buffer + pluginNameLen + 1, symbolData->name, spaceLeftInBuffer - 1);
}

View File

@ -10,7 +10,7 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
return nullptr;
}
dyn_linking_function_t *result = nullptr;
for (auto &curEntry: data->functions) {
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.");
@ -41,7 +41,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return nullptr;
}
dyn_linking_import_t *result = nullptr;
for (auto &curEntry: data->imports) {
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.");
@ -49,7 +49,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
}
strncpy(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
curEntry.isData = isData;
result = &curEntry;
result = &curEntry;
break;
}
if (strncmp(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry.isData == isData)) {
@ -92,12 +92,12 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *lin
if (curEntry->functionEntry != nullptr) {
continue;
}
curEntry->type = type;
curEntry->offset = offset;
curEntry->addend = addend;
curEntry->destination = (void *) destination;
curEntry->type = type;
curEntry->offset = offset;
curEntry->addend = addend;
curEntry->destination = (void *) destination;
curEntry->functionEntry = functionName;
curEntry->importEntry = importInfo;
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);

View File

@ -1,10 +1,10 @@
#pragma once
#include <wums/defines/dynamic_linking_defines.h>
#include "RelocationData.h"
#include <memory>
#include <string>
#include <vector>
#include <memory>
#include "RelocationData.h"
#include <wums/defines/dynamic_linking_defines.h>
class DynamicLinkingHelper {
public:

View File

@ -16,22 +16,22 @@
****************************************************************************/
#pragma once
#include <wups.h>
#include <string>
#include <function_patcher/fpatching_defines.h>
#include <string>
#include <wups.h>
class FunctionData {
public:
FunctionData(void *paddress, void *vaddress, const std::string &name, function_replacement_library_type_t library, void *replaceAddr, void *replaceCall,
FunctionPatcherTargetProcess targetProcess) {
this->paddress = paddress;
this->vaddress = vaddress;
this->name = name;
this->library = library;
this->paddress = paddress;
this->vaddress = vaddress;
this->name = name;
this->library = library;
this->targetProcess = targetProcess;
this->replaceAddr = replaceAddr;
this->replaceCall = replaceCall;
this->replaceAddr = replaceAddr;
this->replaceCall = replaceCall;
}
~FunctionData() = default;
@ -73,4 +73,3 @@ private:
void *replaceAddr = nullptr;
void *replaceCall = nullptr;
};

View File

@ -24,14 +24,13 @@ class FunctionSymbolData {
public:
FunctionSymbolData(const FunctionSymbolData &o2) = default;
FunctionSymbolData(std::string &name, void *address, uint32_t size) :
name(name),
address(address),
size(size) {
FunctionSymbolData(std::string &name, void *address, uint32_t size) : name(name),
address(address),
size(size) {
}
bool operator<(const FunctionSymbolData &rhs) const {
return (uint32_t) address < (uint32_t) rhs.address; //assume that you compare the record based on a
return (uint32_t) address < (uint32_t) rhs.address; //assume that you compare the record based on a
}
virtual ~FunctionSymbolData() = default;

View File

@ -17,15 +17,15 @@
#pragma once
#include <wups.h>
#include <string>
#include <wups.h>
class HookData {
public:
HookData(void *function_pointer, wups_loader_hook_type_t type) {
this->function_pointer = function_pointer;
this->type = type;
this->type = type;
}
~HookData() = default;

View File

@ -17,15 +17,15 @@
#pragma once
#include "../utils/logger.h"
#include <string>
#include <utility>
#include "../utils/logger.h"
class ImportRPLInformation {
public:
explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = std::move(name);
this->name = std::move(name);
this->_isData = isData;
}

View File

@ -17,17 +17,17 @@
#pragma once
#include <memory>
#include "PluginData.h"
#include "PluginMetaInformation.h"
#include "PluginInformation.h"
#include "PluginMetaInformation.h"
#include <memory>
class PluginContainer {
public:
PluginContainer(const PluginContainer &other) {
this->pluginData = other.pluginData;
this->pluginData = other.pluginData;
this->pluginInformation = other.pluginInformation;
this->metaInformation = other.metaInformation;
this->metaInformation = other.metaInformation;
}
PluginContainer() = default;

View File

@ -2,12 +2,12 @@
#include <memory>
#include "DynamicLinkingHelper.h"
#include "PluginContainer.h"
#include "PluginInformationFactory.h"
#include "PluginMetaInformationFactory.h"
#include "PluginContainerPersistence.h"
#include "PluginDataPersistence.h"
#include "DynamicLinkingHelper.h"
#include "PluginInformationFactory.h"
#include "PluginMetaInformationFactory.h"
bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformation, const std::shared_ptr<PluginContainer> &plugin, MEMHeapHandle heapHandle) {
int32_t plugin_count = pluginInformation->number_used_plugins;
@ -25,7 +25,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
memset((void *) plugin_data, 0, sizeof(plugin_information_single_t));
const 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) {
DEBUG_FUNCTION_LINE("Warning: name will be truncated.");
@ -68,7 +68,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
// Relocation
auto relocationData = pluginInfo->getRelocationDataList();
for (auto &reloc: relocationData) {
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;
@ -76,7 +76,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
}
auto function_data_list = pluginInfo->getFunctionDataList();
auto hook_data_list = pluginInfo->getHookDataList();
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);
@ -94,7 +94,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
/* Store function replacement information */
uint32_t i = 0;
for (auto &curFunction: pluginInfo->getFunctionDataList()) {
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());
@ -105,12 +105,12 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
strncpy(function_data->function_name, curFunction->getName().c_str(), MAXIMUM_FUNCTION_NAME_LENGTH - 1);
function_data->VERSION = FUNCTION_REPLACEMENT_DATA_STRUCT_VERSION;
function_data->library = (function_replacement_library_type_t) curFunction->getLibrary();
function_data->replaceAddr = (uint32_t) curFunction->getReplaceAddress();
function_data->replaceCall = (uint32_t) curFunction->getReplaceCall();
function_data->physicalAddr = (uint32_t) curFunction->getPhysicalAddress();
function_data->virtualAddr = (uint32_t) curFunction->getVirtualAddress();
function_data->VERSION = FUNCTION_REPLACEMENT_DATA_STRUCT_VERSION;
function_data->library = (function_replacement_library_type_t) curFunction->getLibrary();
function_data->replaceAddr = (uint32_t) curFunction->getReplaceAddress();
function_data->replaceCall = (uint32_t) curFunction->getReplaceCall();
function_data->physicalAddr = (uint32_t) curFunction->getPhysicalAddress();
function_data->virtualAddr = (uint32_t) curFunction->getVirtualAddress();
function_data->targetProcess = curFunction->getTargetProcess();
plugin_data->info.number_used_functions++;
@ -118,27 +118,27 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
}
i = 0;
for (auto &curHook: pluginInfo->getHookDataList()) {
for (auto &curHook : pluginInfo->getHookDataList()) {
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[i];
DEBUG_FUNCTION_LINE_VERBOSE("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->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;
uint32_t slot = 0;
for (uint32_t j = 0; j < MAXIMUM_PLUGIN_SECTION_LENGTH; j++) {
auto *sectionInfo = &(plugin_data->info.sectionInfos[j]);
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
foundFreeSlot = true;
slot = j;
slot = j;
break;
}
}
@ -157,7 +157,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
return false;
}
}
plugin_data->info.trampolineId = pluginInfo->getTrampolineId();
plugin_data->info.trampolineId = pluginInfo->getTrampolineId();
plugin_data->info.allocatedTextMemoryAddress = pluginInfo->allocatedTextMemoryAddress;
plugin_data->info.allocatedDataMemoryAddress = pluginInfo->allocatedDataMemoryAddress;
@ -165,7 +165,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
if (entryCount > 0) {
// Saving SectionInfos
uint32_t funcSymStringLen = 1;
for (auto &curFuncSym: pluginInfo->getFunctionSymbolDataList()) {
for (auto &curFuncSym : pluginInfo->getFunctionSymbolDataList()) {
funcSymStringLen += curFuncSym->getName().length() + 1;
}
@ -186,25 +186,25 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
DEBUG_FUNCTION_LINE("Allocated %d for the function symbol data", entryCount * sizeof(plugin_function_symbol_data_t));
uint32_t curStringOffset = 0;
uint32_t curEntryIndex = 0;
for (auto &curFuncSym: pluginInfo->getFunctionSymbolDataList()) {
uint32_t curEntryIndex = 0;
for (auto &curFuncSym : pluginInfo->getFunctionSymbolDataList()) {
entryTable[curEntryIndex].address = curFuncSym->getAddress();
entryTable[curEntryIndex].name = &stringTable[curStringOffset];
entryTable[curEntryIndex].size = curFuncSym->getSize();
auto len = curFuncSym->getName().length() + 1;
entryTable[curEntryIndex].name = &stringTable[curStringOffset];
entryTable[curEntryIndex].size = curFuncSym->getSize();
auto len = curFuncSym->getName().length() + 1;
memcpy(stringTable + curStringOffset, curFuncSym->getName().c_str(), len);
curStringOffset += len;
curEntryIndex++;
}
plugin_data->info.allocatedFuncSymStringTableAddress = stringTable;
plugin_data->info.function_symbol_data = entryTable;
plugin_data->info.function_symbol_data = entryTable;
}
plugin_data->info.number_function_symbol_data = entryCount;
/* Copy plugin data */
auto pluginData = plugin->getPluginData();
auto pluginData = plugin->getPluginData();
auto plugin_data_data = &plugin_data->data;
PluginDataPersistence::save(plugin_data_data, pluginData);
@ -257,7 +257,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
curPluginInformation->allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress;
curPluginInformation->allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress;
for (auto &curItem: plugin_data->info.sectionInfos) {
for (auto &curItem : plugin_data->info.sectionInfos) {
plugin_section_info_t *sectionInfo = &curItem;
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
continue;
@ -281,7 +281,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
}
bool storageHasId = true;
for (auto const &value: curPluginInformation->getHookDataList()) {
for (auto const &value : curPluginInformation->getHookDataList()) {
if (value->getType() == WUPS_LOADER_HOOK_INIT_STORAGE &&
metaInformation->getStorageId().empty()) {
storageHasId = false;
@ -302,14 +302,14 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
for (uint32_t j = 0; j < functionReplaceCount; j++) {
function_replacement_data_t *entry = &(plugin_data->info.functions[j]);
auto func = std::make_shared<FunctionData>((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library,
auto func = std::make_shared<FunctionData>((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library,
(void *) entry->replaceAddr,
(void *) entry->replaceCall, entry->targetProcess);
curPluginInformation->addFunctionData(func);
}
/* load relocation data */
for (auto &linking_entry: plugin_data->info.linking_entries) {
for (auto &linking_entry : plugin_data->info.linking_entries) {
if (linking_entry.destination == nullptr) {
break;
}
@ -332,9 +332,9 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
/* load function symbol data */
for (uint32_t j = 0; j < plugin_data->info.number_function_symbol_data; j++) {
auto symbol_data = &plugin_data->info.function_symbol_data[j];
auto symbol_data = &plugin_data->info.function_symbol_data[j];
std::string symbol_name = symbol_data->name;
auto funSymbolData = std::make_shared<FunctionSymbolData>(symbol_name, (void *) symbol_data->address, symbol_data->size);
auto funSymbolData = std::make_shared<FunctionSymbolData>(symbol_name, (void *) symbol_data->address, symbol_data->size);
curPluginInformation->addFunctionSymbolData(funSymbolData);
}

View File

@ -1,14 +1,14 @@
#include "PluginData.h"
#include <utility>
#include <malloc.h>
#include "../utils/logger.h"
#include <malloc.h>
#include <utility>
PluginData::PluginData(const PluginData &obj) {
this->buffer = obj.buffer;
this->buffer = obj.buffer;
this->heapHandle = obj.heapHandle;
this->memoryType = obj.memoryType;
this->length = obj.length;
this->length = obj.length;
}
void PluginData::freeMemory() {
@ -34,10 +34,9 @@ void PluginData::freeMemory() {
PluginData::PluginData(const std::vector<uint8_t> &buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
}
PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
heapHandle(heapHandle),
memoryType(memoryType),
length(input.size()) {
PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) : heapHandle(heapHandle),
memoryType(memoryType),
length(input.size()) {
void *data_copy = nullptr;
switch (memoryType) {
default:

View File

@ -17,10 +17,10 @@
#pragma once
#include <coreinit/memexpheap.h>
#include <malloc.h>
#include <optional>
#include <vector>
#include <malloc.h>
#include <coreinit/memexpheap.h>
#include "../elfio/elfio.hpp"

View File

@ -14,13 +14,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <memory>
#include "PluginDataFactory.h"
#include "../utils/logger.h"
#include "../utils/StringTools.h"
#include "../utils/logger.h"
#include <dirent.h>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
std::vector<std::shared_ptr<PluginData>> PluginDataFactory::loadDir(const std::string &path, MEMHeapHandle heapHandle) {
@ -39,7 +39,7 @@ std::vector<std::shared_ptr<PluginData>> PluginDataFactory::loadDir(const std::s
}
while ((dp = readdir(dfd)) != nullptr) {
struct stat stbuf{};
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) {

View File

@ -17,11 +17,12 @@
#pragma once
#include "PluginData.h"
#include <coreinit/memexpheap.h>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <coreinit/memexpheap.h>
#include "PluginData.h"
class PluginDataFactory {
public:

View File

@ -1,15 +1,15 @@
#include <memory>
#include "../common/plugin_defines.h"
#include "PluginDataPersistence.h"
#include "../common/plugin_defines.h"
#include <memory>
bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, const std::shared_ptr<PluginData> &plugin) {
if (pluginDataStruct == nullptr) {
return false;
}
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->bufferLength = plugin->length;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
return true;
}
@ -17,18 +17,18 @@ bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, PluginData *pl
if (pluginDataStruct == nullptr) {
return false;
}
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->bufferLength = plugin->length;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
return true;
}
std::shared_ptr<PluginData> PluginDataPersistence::load(plugin_data_t *pluginDataStruct) {
auto pluginData = std::make_shared<PluginData>();
pluginData->buffer = pluginDataStruct->buffer;
pluginData->length = pluginDataStruct->bufferLength;
pluginData->buffer = pluginDataStruct->buffer;
pluginData->length = pluginDataStruct->bufferLength;
pluginData->memoryType = (eMemoryTypes) pluginDataStruct->memoryType;
pluginData->heapHandle = (MEMHeapHandle) pluginDataStruct->heapHandle;
return pluginData;

View File

@ -1,6 +1,8 @@
#pragma once
#include "../common/plugin_defines.h"
#include "PluginData.h"
#include <memory>
class PluginDataPersistence {

View File

@ -1,20 +1,20 @@
#include "PluginInformation.h"
PluginInformation::PluginInformation(const PluginInformation &other) {
for (const auto &i: other.hook_data_list) {
for (const auto &i : other.hook_data_list) {
hook_data_list.push_back(i);
}
for (const auto &i: other.function_data_list) {
for (const auto &i : other.function_data_list) {
function_data_list.push_back(i);
}
for (const auto &i: other.relocation_data_list) {
for (const auto &i : other.relocation_data_list) {
relocation_data_list.push_back(i);
}
for (const auto &i: other.symbol_data_list) {
for (const auto &i : other.symbol_data_list) {
symbol_data_list.insert(i);
}
section_info_list = other.section_info_list;
trampolineId = other.trampolineId;
section_info_list = other.section_info_list;
trampolineId = other.trampolineId;
allocatedTextMemoryAddress = other.allocatedTextMemoryAddress;
allocatedDataMemoryAddress = other.allocatedDataMemoryAddress;
}

View File

@ -17,18 +17,18 @@
#pragma once
#include <map>
#include <set>
#include <optional>
#include <string>
#include <vector>
#include <memory>
#include "FunctionData.h"
#include "FunctionSymbolData.h"
#include "HookData.h"
#include "PluginMetaInformation.h"
#include "RelocationData.h"
#include "HookData.h"
#include "FunctionData.h"
#include "SectionInfo.h"
#include "FunctionSymbolData.h"
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
struct FunctionSymbolDataComparator {
bool operator()(const std::shared_ptr<FunctionSymbolData> &lhs,

View File

@ -15,17 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "PluginInformationFactory.h"
#include "../utils/ElfUtils.h"
#include "../utils/utils.h"
#include "PluginData.h"
#include <coreinit/cache.h>
#include <coreinit/memexpheap.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <coreinit/cache.h>
#include <coreinit/memexpheap.h>
#include <wups.h>
#include "PluginData.h"
#include "PluginInformationFactory.h"
#include "../utils/utils.h"
#include "../utils/ElfUtils.h"
using namespace ELFIO;
@ -44,7 +44,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
auto pluginInfo = std::make_shared<PluginInformation>();
uint32_t sec_num = reader.sections.size();
uint32_t sec_num = reader.sections.size();
auto **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num);
uint32_t totalSize = 0;
@ -60,7 +60,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
auto address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
if ((address >= 0x02000000) && address < 0x10000000) {
text_size += sectionSize;
} else if ((address >= 0x10000000) && address < 0xC0000000) {
@ -95,7 +95,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
auto address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
uint32_t destination = address;
if ((address >= 0x02000000) && address < 0x10000000) {
@ -157,7 +157,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
}
auto relocationData = getImportRelocationData(reader, destinations);
for (auto const &reloc: relocationData) {
for (auto const &reloc : relocationData) {
pluginInfo->addRelocationData(reloc);
}
@ -173,11 +173,11 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
auto secInfo = pluginInfo->getSectionInfo(".wups.hooks");
if (secInfo && secInfo.value()->getSize() > 0) {
size_t entries_count = secInfo.value()->getSize() / sizeof(wups_loader_hook_t);
auto *entries = (wups_loader_hook_t *) secInfo.value()->getAddress();
auto *entries = (wups_loader_hook_t *) secInfo.value()->getAddress();
if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wups_loader_hook_t *hook = &entries[j];
DEBUG_FUNCTION_LINE_VERBOSE("Saving hook of plugin Type: %08X, target: %08X"/*,pluginData->getPluginInformation()->getName().c_str()*/, hook->type, (void *) hook->target);
DEBUG_FUNCTION_LINE_VERBOSE("Saving hook of plugin Type: %08X, target: %08X" /*,pluginData->getPluginInformation()->getName().c_str()*/, hook->type, (void *) hook->target);
auto hook_data = std::make_shared<HookData>((void *) hook->target, hook->type);
pluginInfo->addHookData(hook_data);
}
@ -187,12 +187,12 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
secInfo = pluginInfo->getSectionInfo(".wups.load");
if (secInfo && secInfo.value()->getSize() > 0) {
size_t entries_count = secInfo.value()->getSize() / sizeof(wups_loader_entry_t);
auto *entries = (wups_loader_entry_t *) secInfo.value()->getAddress();
auto *entries = (wups_loader_entry_t *) secInfo.value()->getAddress();
if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wups_loader_entry_t *cur_function = &entries[j];
DEBUG_FUNCTION_LINE_VERBOSE("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.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);
auto function_data = std::make_shared<FunctionData>((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name,
@ -214,17 +214,17 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
if (sym_no > 0) {
for (Elf_Half j = 0; j < sym_no; ++j) {
std::string name;
Elf64_Addr value = 0;
Elf_Xword size = 0;
unsigned char bind = 0;
unsigned char type = 0;
Elf_Half section = 0;
Elf64_Addr value = 0;
Elf_Xword size = 0;
unsigned char bind = 0;
unsigned char type = 0;
Elf_Half section = 0;
unsigned char other = 0;
if (symbols.get_symbol(j, name, value, size, bind, type, section, other)) {
if (type == STT_FUNC) { // We only care about functions.
auto sectionVal = reader.sections[section];
auto offsetVal = value - sectionVal->get_address();
auto offsetVal = value - sectionVal->get_address();
auto sectionOpt = pluginInfo->getSectionInfo(sectionVal->get_name());
if (!sectionOpt.has_value()) {
continue;
@ -299,7 +299,7 @@ std::vector<std::shared_ptr<RelocationData>> PluginInformationFactory::getImport
rplName = rawSectionName.substr(fimport.size());
} else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) {
rplName = rawSectionName.substr(dimport.size());
isData = true;
isData = true;
} else {
DEBUG_FUNCTION_LINE("invalid section name");
continue;

View File

@ -17,15 +17,15 @@
#pragma once
#include "../elfio/elfio.hpp"
#include "PluginContainer.h"
#include "PluginInformation.h"
#include <coreinit/memheap.h>
#include <map>
#include <optional>
#include <string>
#include <vector>
#include <map>
#include <coreinit/memheap.h>
#include <wums/defines/relocation_defines.h>
#include "PluginInformation.h"
#include "PluginContainer.h"
#include "../elfio/elfio.hpp"
class PluginInformationFactory {
public:

View File

@ -1,12 +1,12 @@
#include "PluginMetaInformation.h"
PluginMetaInformation::PluginMetaInformation(const PluginMetaInformation &other) {
this->name = other.name;
this->author = other.author;
this->version = other.version;
this->license = other.license;
this->name = other.name;
this->author = other.author;
this->version = other.version;
this->license = other.license;
this->buildtimestamp = other.buildtimestamp;
this->description = other.description;
this->size = other.size;
this->storageId = other.storageId;
this->description = other.description;
this->size = other.size;
this->storageId = other.storageId;
}

View File

@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <sys/types.h>
#include <dirent.h>
#include <whb/file.h>
#include <memory>
#include "../utils/StringTools.h"
#include "PluginMetaInformationFactory.h"
#include "../utils/StringTools.h"
#include <dirent.h>
#include <memory>
#include <sys/types.h>
#include <whb/file.h>
using namespace ELFIO;
@ -69,7 +69,7 @@ std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFacto
// 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();
auto address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
if ((address >= 0x02000000) && address < 0x10000000) {
pluginSize += sectionSize;
} else if ((address >= 0x10000000) && address < 0xC0000000) {
@ -80,7 +80,7 @@ std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFacto
// Get meta information and check WUPS version:
if (psec->get_name() == ".wups.meta") {
const void *sectionData = psec->get_data();
uint32_t sectionSize = psec->get_size();
uint32_t sectionSize = psec->get_size();
char *curEntry = (char *) sectionData;
while ((uint32_t) curEntry < (uint32_t) sectionData + sectionSize) {

View File

@ -17,12 +17,12 @@
#pragma once
#include "PluginData.h"
#include "PluginMetaInformation.h"
#include <memory>
#include <optional>
#include <string>
#include <memory>
#include <vector>
#include "PluginMetaInformation.h"
#include "PluginData.h"
class PluginMetaInformationFactory {
public:

View File

@ -17,20 +17,20 @@
#pragma once
#include "ImportRPLInformation.h"
#include <memory>
#include <string>
#include <utility>
#include "ImportRPLInformation.h"
class RelocationData {
public:
RelocationData(const char type, size_t offset, int32_t addend, void *destination, std::string &name, std::shared_ptr<ImportRPLInformation> rplInfo) :
type(type),
offset(offset),
addend(addend),
destination(destination),
name(name),
rplInfo(std::move(rplInfo)) {
RelocationData(const char type, size_t offset, int32_t addend, void *destination, std::string &name, std::shared_ptr<ImportRPLInformation> rplInfo) : type(type),
offset(offset),
addend(addend),
destination(destination),
name(name),
rplInfo(std::move(rplInfo)) {
}
RelocationData(const RelocationData &o2) = default;

View File

@ -22,10 +22,9 @@
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() = default;

View File

@ -1,26 +1,26 @@
#include "ConfigUtils.h"
#include "logger.h"
#include "../config/WUPSConfig.h"
#include "../globals.h"
#include "DrawUtils.h"
#include "logger.h"
#include <coreinit/screen.h>
#include <gx2/display.h>
#include <memory/mappedmemory.h>
#include <padscore/kpad.h>
#include <string>
#include <vector>
#include <coreinit/screen.h>
#include <memory/mappedmemory.h>
#include <vpad/input.h>
#include <padscore/kpad.h>
#include <gx2/display.h>
#define COLOR_BACKGROUND Color(238, 238, 238, 255)
#define COLOR_TEXT Color(51, 51, 51, 255)
#define COLOR_TEXT2 Color(72, 72, 72, 255)
#define COLOR_DISABLED Color(255, 0, 0, 255)
#define COLOR_BORDER Color(204, 204, 204, 255)
#define COLOR_BACKGROUND Color(238, 238, 238, 255)
#define COLOR_TEXT Color(51, 51, 51, 255)
#define COLOR_TEXT2 Color(72, 72, 72, 255)
#define COLOR_DISABLED Color(255, 0, 0, 255)
#define COLOR_BORDER Color(204, 204, 204, 255)
#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4FF)
#define COLOR_WHITE Color(0xFFFFFFFF)
#define COLOR_BLACK Color(0, 0, 0, 255)
#define COLOR_WHITE Color(0xFFFFFFFF)
#define COLOR_BLACK Color(0, 0, 0, 255)
struct ConfigDisplayItem {
WUPSConfig *config{};
@ -124,18 +124,18 @@ void ConfigUtils::displayMenu() {
continue;
}
ConfigDisplayItem cfg;
cfg.name = std::string(plugin_data->meta.name);
cfg.author = std::string(plugin_data->meta.author);
cfg.name = std::string(plugin_data->meta.name);
cfg.author = std::string(plugin_data->meta.author);
cfg.version = std::string(plugin_data->meta.version);
cfg.enabled = true;
for (uint32_t j = 0; j < plugin_data->info.number_used_hooks; j++) {
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[j];
if (hook_data->type == WUPS_LOADER_HOOK_GET_CONFIG/*WUPS_LOADER_HOOK_GET_CONFIG*/) {
if (hook_data->type == WUPS_LOADER_HOOK_GET_CONFIG /*WUPS_LOADER_HOOK_GET_CONFIG*/) {
if (hook_data->func_pointer == nullptr) {
break;
}
auto *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle (*)()) ((uint32_t *) hook_data->func_pointer))());
auto *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle(*)())((uint32_t *) hook_data->func_pointer))());
if (cur_config == nullptr) {
break;
}
@ -150,12 +150,12 @@ void ConfigUtils::displayMenu() {
return;
}
ConfigDisplayItem *currentConfig = nullptr;
ConfigDisplayItem *currentConfig = nullptr;
WUPSConfigCategory *currentCategory = nullptr;
uint32_t selectedBtn = 0;
uint32_t start = 0;
uint32_t end = MAX_BUTTONS_ON_SCREEN;
uint32_t start = 0;
uint32_t end = MAX_BUTTONS_ON_SCREEN;
if (configs.size() < MAX_BUTTONS_ON_SCREEN) {
end = configs.size();
}
@ -171,12 +171,12 @@ void ConfigUtils::displayMenu() {
while (true) {
buttonsTriggered = 0;
buttonsReleased = 0;
buttonsReleased = 0;
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error);
if (vpad_error == VPAD_READ_SUCCESS) {
buttonsTriggered = vpad_data.trigger;
buttonsReleased = vpad_data.release;
buttonsReleased = vpad_data.release;
}
for (int i = 0; i < 4; i++) {
@ -212,7 +212,7 @@ void ConfigUtils::displayMenu() {
}
if (buttonsTriggered & VPAD_BUTTON_X) {
configs[selectedBtn].enabled = !configs[selectedBtn].enabled;
redraw = true;
redraw = true;
} else if (buttonsTriggered & VPAD_BUTTON_A) {
currentConfig = &configs[selectedBtn];
if (currentConfig == nullptr) {
@ -220,8 +220,8 @@ void ConfigUtils::displayMenu() {
}
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
auto cats = currentConfig->config->getCategories();
if (cats.size() < MAX_BUTTONS_ON_SCREEN) {
@ -233,11 +233,11 @@ void ConfigUtils::displayMenu() {
}
if (selectedBtn >= end) {
end = selectedBtn + 1;
end = selectedBtn + 1;
start = end - MAX_BUTTONS_ON_SCREEN;
} else if (selectedBtn < start) {
start = selectedBtn;
end = start + MAX_BUTTONS_ON_SCREEN;
end = start + MAX_BUTTONS_ON_SCREEN;
}
if (redraw) {
@ -329,8 +329,8 @@ void ConfigUtils::displayMenu() {
}
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
auto items = currentCategory->getItems();
if (items.size() < MAX_BUTTONS_ON_SCREEN) {
@ -340,11 +340,11 @@ void ConfigUtils::displayMenu() {
redraw = true;
continue;
} else if (buttonsTriggered & VPAD_BUTTON_B) {
currentConfig = nullptr;
currentConfig = nullptr;
currentCategory = nullptr;
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
if (configs.size() < MAX_BUTTONS_ON_SCREEN) {
end = configs.size();
}
@ -353,11 +353,11 @@ void ConfigUtils::displayMenu() {
}
if (selectedBtn >= end) {
end = selectedBtn + 1;
end = selectedBtn + 1;
start = end - MAX_BUTTONS_ON_SCREEN;
} else if (selectedBtn < start) {
start = selectedBtn;
end = start + MAX_BUTTONS_ON_SCREEN;
end = start + MAX_BUTTONS_ON_SCREEN;
}
if (redraw) {
@ -434,10 +434,10 @@ void ConfigUtils::displayMenu() {
}
} else if (buttonsTriggered & VPAD_BUTTON_B) {
currentCategory = nullptr;
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
auto catSize = currentConfig->config->getCategories().size();
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
auto catSize = currentConfig->config->getCategories().size();
if (catSize < MAX_BUTTONS_ON_SCREEN) {
end = catSize;
}
@ -472,11 +472,11 @@ void ConfigUtils::displayMenu() {
}
if (selectedBtn >= end) {
end = selectedBtn + 1;
end = selectedBtn + 1;
start = end - MAX_BUTTONS_ON_SCREEN;
} else if (selectedBtn < start) {
start = selectedBtn;
end = start + MAX_BUTTONS_ON_SCREEN;
end = start + MAX_BUTTONS_ON_SCREEN;
}
if (redraw) {
@ -543,9 +543,9 @@ void ConfigUtils::displayMenu() {
}
}
for (const auto &element: configs) {
for (const auto &cat: element.config->getCategories()) {
for (const auto &item: cat->getItems()) {
for (const auto &element : configs) {
for (const auto &cat : element.config->getCategories()) {
for (const auto &item : cat->getItems()) {
if (item->isDirty()) {
item->callCallback();
}
@ -565,13 +565,13 @@ void ConfigUtils::displayMenu() {
if (hook_data->func_pointer == nullptr) {
break;
}
((void (*)()) ((uint32_t *) hook_data->func_pointer))();
((void (*)())((uint32_t *) hook_data->func_pointer))();
break;
}
}
}
for (const auto &element: configs) {
for (const auto &element : configs) {
DEBUG_FUNCTION_LINE("Delete %08X", element.config);
delete element.config;
}
@ -584,8 +584,8 @@ void ConfigUtils::openConfigMenu() {
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
void *screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100);
void *screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100);
void *screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100);
void *screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100);
bool skipScreen0Free = false;
bool skipScreen1Free = false;
@ -593,14 +593,14 @@ void ConfigUtils::openConfigMenu() {
if (!screenbuffer0 || !screenbuffer1) {
if (screenbuffer0 == nullptr) {
if (storedTVBuffer.buffer_size >= screen_buf0_size) {
screenbuffer0 = storedTVBuffer.buffer;
screenbuffer0 = storedTVBuffer.buffer;
skipScreen0Free = true;
DEBUG_FUNCTION_LINE("Use storedTVBuffer");
}
}
if (screenbuffer1 == nullptr) {
if (storedDRCBuffer.buffer_size >= screen_buf1_size) {
screenbuffer1 = storedDRCBuffer.buffer;
screenbuffer1 = storedDRCBuffer.buffer;
skipScreen1Free = true;
DEBUG_FUNCTION_LINE("Use storedDRCBuffer");
}
@ -637,7 +637,7 @@ void ConfigUtils::openConfigMenu() {
DrawUtils::deinitFont();
error_exit:
error_exit:
if (storedTVBuffer.buffer != nullptr) {
GX2SetTVBuffer(storedTVBuffer.buffer, storedTVBuffer.buffer_size, static_cast<GX2TVRenderMode>(storedTVBuffer.mode),

View File

@ -2,31 +2,31 @@
#include <coreinit/memory.h>
#include <coreinit/screen.h>
#include <png.h>
#include <ft2build.h>
#include <png.h>
#include FT_FREETYPE_H
// buffer width
#define TV_WIDTH 0x500
#define TV_WIDTH 0x500
#define DRC_WIDTH 0x380
bool DrawUtils::isBackBuffer;
uint8_t *DrawUtils::tvBuffer = nullptr;
uint32_t DrawUtils::tvSize = 0;
uint8_t *DrawUtils::tvBuffer = nullptr;
uint32_t DrawUtils::tvSize = 0;
uint8_t *DrawUtils::drcBuffer = nullptr;
uint32_t DrawUtils::drcSize = 0;
uint32_t DrawUtils::drcSize = 0;
// Don't put those into the clase or we have to include ft everywhere
static FT_Library ft_lib = nullptr;
static FT_Face ft_face = nullptr;
static FT_Face ft_face = nullptr;
static Color font_col(0xFFFFFFFF);
void DrawUtils::initBuffers(void *tvBuffer_, uint32_t tvSize_, void *drcBuffer_, uint32_t drcSize_) {
DrawUtils::tvBuffer = (uint8_t *) tvBuffer_;
DrawUtils::tvSize = tvSize_;
DrawUtils::tvBuffer = (uint8_t *) tvBuffer_;
DrawUtils::tvSize = tvSize_;
DrawUtils::drcBuffer = (uint8_t *) drcBuffer_;
DrawUtils::drcSize = drcSize_;
DrawUtils::drcSize = drcSize_;
}
void DrawUtils::beginDraw() {
@ -68,11 +68,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
i += drcSize / 2;
}
if (a == 0xFF) {
drcBuffer[i] = r;
drcBuffer[i] = r;
drcBuffer[i + 1] = g;
drcBuffer[i + 2] = b;
} else {
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity);
drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity);
}
@ -87,11 +87,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
i += tvSize / 2;
}
if (a == 0xFF) {
tvBuffer[i] = r;
tvBuffer[i] = r;
tvBuffer[i + 1] = g;
tvBuffer[i + 2] = b;
} else {
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity);
tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity);
}
@ -122,8 +122,8 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32
}
uint32_t dataPos = __builtin_bswap32(*(uint32_t *) &(data[0x0A]));
uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12]));
uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16]));
uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12]));
uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16]));
if (dataPos == 0) {
dataPos = 54;
@ -164,17 +164,17 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
png_read_info(png_ptr, info_ptr);
uint32_t width = 0;
uint32_t width = 0;
uint32_t height = 0;
int bitDepth = 0;
int colorType = -1;
int bitDepth = 0;
int colorType = -1;
uint32_t retval = png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, nullptr, nullptr, nullptr);
if (retval != 1) {
return;
}
uint32_t bytesPerRow = png_get_rowbytes(png_ptr, info_ptr);
auto *rowData = new uint8_t[bytesPerRow];
auto *rowData = new uint8_t[bytesPerRow];
for (uint32_t yy = y; yy < y + height; yy++) {
png_read_row(png_ptr, (png_bytep) rowData, nullptr);
@ -195,7 +195,7 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
}
void DrawUtils::initFont() {
void *font = nullptr;
void *font = nullptr;
uint32_t size = 0;
OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size);
@ -243,7 +243,8 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh
buffer[num] = 0;
} else {
wchar_t *tmp = buffer;
while ((*tmp++ = *string++));
while ((*tmp++ = *string++))
;
}
print(x, y, buffer, alignRight);
@ -252,7 +253,7 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh
void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight) {
FT_GlyphSlot slot = ft_face->glyph;
FT_Vector pen = {(int) x, (int) y};
FT_Vector pen = {(int) x, (int) y};
if (alignRight) {
pen.x -= getTextWidth(string);
@ -283,7 +284,8 @@ uint32_t DrawUtils::getTextWidth(const char *string) {
buffer[num] = 0;
} else {
wchar_t *tmp = buffer;
while ((*tmp++ = *string++));
while ((*tmp++ = *string++))
;
}
uint32_t width = getTextWidth(buffer);
@ -294,7 +296,7 @@ uint32_t DrawUtils::getTextWidth(const char *string) {
uint32_t DrawUtils::getTextWidth(const wchar_t *string) {
FT_GlyphSlot slot = ft_face->glyph;
uint32_t width = 0;
uint32_t width = 0;
for (; *string; string++) {
FT_Load_Glyph(ft_face, FT_Get_Char_Index(ft_face, *string), FT_LOAD_BITMAP_METRICS_ONLY);

View File

@ -3,7 +3,7 @@
#include <cstdint>
// visible screen sizes
#define SCREEN_WIDTH 854
#define SCREEN_WIDTH 854
#define SCREEN_HEIGHT 480
union Color {

View File

@ -1,8 +1,8 @@
#include <cstring>
#include <coreinit/cache.h>
#include <cstring>
#include "utils/logger.h"
#include "ElfUtils.h"
#include "utils/logger.h"
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
@ -12,7 +12,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
}
auto target = destination + offset;
auto value = symbol_addr + addend;
auto value = symbol_addr + addend;
auto relValue = value - static_cast<uint32_t>(target);
@ -96,19 +96,19 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
}
if (freeSlot == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampoline data list is full");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) &(freeSlot->trampoline[0]));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) & (freeSlot->trampoline[0]));
return false;
}
if (target - (uint32_t) &(freeSlot->trampoline[0]) > 0x1FFFFFC) {
if (target - (uint32_t) & (freeSlot->trampoline[0]) > 0x1FFFFFC) {
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) &(freeSlot->trampoline[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) & (freeSlot->trampoline[0])));
return false;
}
freeSlot->trampoline[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampoline[3] = 0x4E800420; // bctr
freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampoline[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
ICInvalidateRange((unsigned char *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
@ -122,9 +122,9 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
// Relocations for the imports may be overridden
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
}
auto symbolValue = (uint32_t) &(freeSlot->trampoline[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
auto symbolValue = (uint32_t) & (freeSlot->trampoline[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
}
}

View File

@ -11,33 +11,33 @@ int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *si
uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath);
uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fileSize);
#define R_PPC_NONE 0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR16_LO 4
#define R_PPC_ADDR16_HI 5
#define R_PPC_ADDR16_HA 6
#define R_PPC_REL24 10
#define R_PPC_REL14 11
#define R_PPC_DTPMOD32 68
#define R_PPC_DTPREL32 78
#define R_PPC_EMB_SDA21 109
#define R_PPC_EMB_RELSDA 116
#define R_PPC_DIAB_SDA21_LO 180
#define R_PPC_DIAB_SDA21_HI 181
#define R_PPC_DIAB_SDA21_HA 182
#define R_PPC_DIAB_RELSDA_LO 183
#define R_PPC_DIAB_RELSDA_HI 184
#define R_PPC_DIAB_RELSDA_HA 185
#define R_PPC_GHS_REL16_HA 251
#define R_PPC_GHS_REL16_HI 252
#define R_PPC_GHS_REL16_LO 253
#define R_PPC_NONE 0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR16_LO 4
#define R_PPC_ADDR16_HI 5
#define R_PPC_ADDR16_HA 6
#define R_PPC_REL24 10
#define R_PPC_REL14 11
#define R_PPC_DTPMOD32 68
#define R_PPC_DTPREL32 78
#define R_PPC_EMB_SDA21 109
#define R_PPC_EMB_RELSDA 116
#define R_PPC_DIAB_SDA21_LO 180
#define R_PPC_DIAB_SDA21_HI 181
#define R_PPC_DIAB_SDA21_HA 182
#define R_PPC_DIAB_RELSDA_LO 183
#define R_PPC_DIAB_RELSDA_HI 184
#define R_PPC_DIAB_RELSDA_HA 185
#define R_PPC_GHS_REL16_HA 251
#define R_PPC_GHS_REL16_HI 252
#define R_PPC_GHS_REL16_LO 253
// Masks for manipulating Power PC relocation targets
#define PPC_WORD32 0xFFFFFFFF
#define PPC_WORD30 0xFFFFFFFC
#define PPC_LOW24 0x03FFFFFC
#define PPC_LOW14 0x0020FFFC
#define PPC_HALF16 0xFFFF
#define PPC_WORD32 0xFFFFFFFF
#define PPC_WORD30 0xFFFFFFFC
#define PPC_LOW24 0x03FFFFFC
#define PPC_LOW14 0x0020FFFC
#define PPC_HALF16 0xFFFF
#ifdef __cplusplus
}

View File

@ -1,40 +1,40 @@
#include "StorageUtils.h"
#include <string>
#include "utils/logger.h"
#include "utils/json.hpp"
#include "fs/CFile.hpp"
#include "fs/FSUtils.h"
#include "utils/json.hpp"
#include "utils/logger.h"
static void processJson(wups_storage_item_t *items, nlohmann::json json) {
if (items == nullptr) {
return;
}
items->data = (wups_storage_item_t *) malloc(json.size() * sizeof(wups_storage_item_t));
items->data = (wups_storage_item_t *) malloc(json.size() * sizeof(wups_storage_item_t));
items->data_size = json.size();
uint32_t index = 0;
for (auto it = json.begin(); it != json.end(); ++it) {
wups_storage_item_t *item = &((wups_storage_item_t *) items->data)[index];
item->type = WUPS_STORAGE_TYPE_INVALID;
item->pending_delete = false;
item->data = nullptr;
item->key = nullptr;
item->type = WUPS_STORAGE_TYPE_INVALID;
item->pending_delete = false;
item->data = nullptr;
item->key = nullptr;
item->key = (char *) malloc(it.key().size() + 1);
strcpy(item->key, it.key().c_str());
if (it.value().is_string()) {
item->type = WUPS_STORAGE_TYPE_STRING;
uint32_t size = it.value().get<std::string>().size() + 1;
item->data = malloc(size);
item->type = WUPS_STORAGE_TYPE_STRING;
uint32_t size = it.value().get<std::string>().size() + 1;
item->data = malloc(size);
item->data_size = size;
strcpy((char *) item->data, it.value().get<std::string>().c_str());
} else if (it.value().is_number_integer()) {
item->type = WUPS_STORAGE_TYPE_INT;
item->data = malloc(sizeof(int32_t));
item->data_size = sizeof(int32_t);
item->type = WUPS_STORAGE_TYPE_INT;
item->data = malloc(sizeof(int32_t));
item->data_size = sizeof(int32_t);
*(int32_t *) item->data = it.value().get<int32_t>();
} else if (it.value().is_object()) {
if (it.value().size() > 0) {
@ -58,7 +58,7 @@ int StorageUtils::OpenStorage(const char *plugin_id, wups_storage_item_t *items)
nlohmann::json j;
CFile file(filePath, CFile::ReadOnly);
if (file.isOpen() && file.size() > 0) {
uint8_t *json_data = new uint8_t[file.size() + 1];
uint8_t *json_data = new uint8_t[file.size() + 1];
json_data[file.size()] = '\0';
file.read(json_data, file.size());
@ -113,7 +113,7 @@ int StorageUtils::CloseStorage(const char *plugin_id, wups_storage_item_t *items
}
std::string folderPath = "fs:/vol/external01/wiiu/plugins/config/";
std::string filePath = folderPath + plugin_id + ".json";
std::string filePath = folderPath + plugin_id + ".json";
FSUtils::CreateSubfolder(folderPath.c_str());

View File

@ -23,14 +23,14 @@
*
* for WiiXplorer 2010
***************************************************************************/
#include <vector>
#include <string>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <wut_types.h>
#include <cstdio>
#include <string>
#include <utils/StringTools.h>
#include <vector>
#include <wut_types.h>
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
@ -82,7 +82,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
static char tmp[512];
static wchar_t strWChar[512];
strWChar[0] = 0;
tmp[0] = 0;
tmp[0] = 0;
if (!format)
return (const wchar_t *) strWChar;
@ -95,7 +95,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
if ((vsprintf(tmp, format, va) >= 0)) {
int bt;
int32_t strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
if (bt > 0) {
strWChar[bt] = 0;
@ -109,13 +109,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
static char tmp[512];
tmp[0] = 0;
tmp[0] = 0;
int32_t result = 0;
va_list va;
va_start(va, format);
if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp;
str = tmp;
result = str.size();
}
va_end(va);

View File

@ -26,8 +26,8 @@
#ifndef __STRING_TOOLS_H
#define __STRING_TOOLS_H
#include <vector>
#include <string>
#include <vector>
#include <wut_types.h>
class StringTools {
@ -56,7 +56,7 @@ public:
if (!path)
return path;
const char *ptr = path;
const char *ptr = path;
const char *Filename = ptr;
while (*ptr != '\0') {
@ -86,4 +86,3 @@ public:
};
#endif /* __STRING_TOOLS_H */

View File

@ -1,15 +1,15 @@
#include <coreinit/cache.h>
#include "../plugin/PluginMetaInformationFactory.h"
#include "exports.h"
#include "../PluginManagement.h"
#include "../globals.h"
#include "../plugin/PluginContainer.h"
#include "../plugin/PluginContainerPersistence.h"
#include "../plugin/PluginDataFactory.h"
#include "../PluginManagement.h"
#include "../globals.h"
#include "../plugin/PluginDataPersistence.h"
#include "exports.h"
#include "../plugin/PluginMetaInformationFactory.h"
#include <coreinit/cache.h>
#include <wums.h>
void fillPluginInformation(plugin_information *out, const std::shared_ptr<PluginMetaInformation> &metaInformation) {
static void fillPluginInformation(plugin_information *out, const std::shared_ptr<PluginMetaInformation> &metaInformation) {
out->plugin_information_version = PLUGIN_INFORMATION_VERSION;
strncpy(out->author, metaInformation->getAuthor().c_str(), sizeof(out->author) - 1);
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), sizeof(out->buildTimestamp) - 1);
@ -26,7 +26,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
plugin_data_handle handle = plugin_data_handle_list[i];
auto *pluginData = (PluginData *) handle;
auto *pluginData = (PluginData *) handle;
PluginDataPersistence::save(&gLinkOnReload.plugin_data[gLinkOnReload.number_used_plugins], pluginData);
gLinkOnReload.number_used_plugins++;
@ -45,7 +45,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
extern "C" PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size) {
if (handle_list != nullptr && handle_list_size != 0) {
for (uint32_t i = 0; i < handle_list_size; i++) {
auto handle = handle_list[i];
auto handle = handle_list[i];
auto *pluginContainer = (PluginContainer *) handle;
delete pluginContainer;
}
@ -56,7 +56,7 @@ extern "C" PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_cont
extern "C" PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) {
if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
auto handle = plugin_data_handle_list[i];
auto handle = plugin_data_handle_list[i];
auto *pluginData = (PluginData *) handle;
delete pluginData;
}
@ -86,7 +86,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationIn
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
} else {
auto *pluginDataHandle = new PluginData(*pluginData.value());
*out = (uint32_t) pluginDataHandle;
*out = (uint32_t) pluginDataHandle;
}
return PLUGIN_BACKEND_API_ERROR_NONE;
@ -138,9 +138,9 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const
PluginBackendApiErrorType res = PLUGIN_BACKEND_API_ERROR_NONE;
if (plugin_container_handle_list != nullptr && buffer_size != 0) {
for (uint32_t i = 0; i < buffer_size; i++) {
auto handle = plugin_container_handle_list[i];
auto *container = (PluginContainer *) handle;
auto *pluginData = new PluginData(*container->getPluginData());
auto handle = plugin_container_handle_list[i];
auto *container = (PluginContainer *) handle;
auto *pluginData = new PluginData(*container->getPluginData());
plugin_data_list[i] = (uint32_t) pluginData;
}
} else {
@ -154,7 +154,7 @@ extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_contain
PluginBackendApiErrorType res = PLUGIN_BACKEND_API_ERROR_NONE;
if (plugin_container_handle_list != nullptr && buffer_size != 0) {
for (uint32_t i = 0; i < buffer_size; i++) {
auto handle = plugin_container_handle_list[i];
auto handle = plugin_container_handle_list[i];
auto *container = (PluginContainer *) handle;
plugin_information_list[i].plugin_information_version = PLUGIN_INFORMATION_VERSION;
@ -180,11 +180,11 @@ extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handl
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
}
*plugin_information_version = PLUGIN_INFORMATION_VERSION;
auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
uint32_t counter = 0;
for (auto &plugin: plugins) {
auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
uint32_t counter = 0;
for (auto &plugin : plugins) {
if (counter < buffer_size) {
auto *container = new PluginContainer(*plugin);
auto *container = new PluginContainer(*plugin);
io_handles[counter] = (uint32_t) container;
counter++;
} else {

View File

@ -7,8 +7,6 @@
extern "C" {
#endif
void fillPluginInformation(plugin_information *out, PluginMetaInformation *metaInformation);
PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size);
PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size);

View File

@ -1,3 +1,4 @@
// clang-format off
/*
__ _____ _____ _____
__| | __| | | | JSON for Modern C++

View File

@ -1,19 +1,19 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif // DEBUG
void initLogging() {
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <whb/log.h>
#include <string.h>
#include <whb/log.h>
#ifdef __cplusplus
extern "C" {
@ -9,26 +9,28 @@ extern "C" {
#ifdef DEBUG
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#else
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
#endif
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus
}
#endif

View File

@ -1,11 +1,11 @@
#include <string.h>
#include <stdlib.h>
#include "utils/logger.h"
#include <malloc.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <whb/log.h>
#include "utils/logger.h"
// https://gist.github.com/ccbrown/9722406
void dumpHex(const void *data, size_t size) {

View File

@ -7,28 +7,29 @@
extern "C" {
#endif
#define LIMIT(x, min, max) \
({ \
typeof( x ) _x = x; \
typeof( min ) _min = min; \
typeof( max ) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
})
#define LIMIT(x, min, max) \
({ \
typeof(x) _x = x; \
typeof(min) _min = min; \
typeof(max) _max = max; \
(((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \
: (_x)); \
})
#define DegToRad(a) ( (a) * 0.01745329252f )
#define RadToDeg(a) ( (a) * 57.29577951f )
#define DegToRad(a) ((a) *0.01745329252f)
#define RadToDeg(a) ((a) *57.29577951f)
#define ALIGN4(x) (((x) + 3) & ~3)
#define ALIGN32(x) (((x) + 31) & ~31)
#define ALIGN4(x) (((x) + 3) & ~3)
#define ALIGN32(x) (((x) + 31) & ~31)
// those work only in powers of 2
#define ROUNDDOWN(val, align) ((val) & ~(align-1))
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align)
#define ROUNDDOWN(val, align) ((val) & ~(align - 1))
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)
#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8)))
#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16)))
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
#define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8)))
#define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16)))
#define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32)))
//Needs to have log_init() called beforehand.
void dumpHex(const void *data, size_t size);