diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..56cc685 --- /dev/null +++ b/.clang-format @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2bd293b..8028296 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/ci_non_master.yml b/.github/workflows/ci_non_master.yml deleted file mode 100644 index ecd2722..0000000 --- a/.github/workflows/ci_non_master.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0413d45..19c3b14 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 diff --git a/README.md b/README.md index 7a94b70..69a79d0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/source/PluginManagement.cpp b/source/PluginManagement.cpp index e4b3d85..89da3c8 100644 --- a/source/PluginManagement.cpp +++ b/source/PluginManagement.cpp @@ -1,23 +1,23 @@ -#include #include #include #include +#include #include #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> &relocData, relocation_trampoline_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolineID) { std::map 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::vectorgetImportRPLInformation()->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> &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> &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> PluginManagement::loadPlugins(const std::vector> &pluginList, MEMHeapHandle heapHandle, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length) { std::vector> 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> &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> &pl } return plugins; } - diff --git a/source/PluginManagement.h b/source/PluginManagement.h index 009fc48..bce621f 100644 --- a/source/PluginManagement.h +++ b/source/PluginManagement.h @@ -1,11 +1,12 @@ #pragma once +#include "plugin/PluginContainer.h" #include +#include #include class PluginManagement { public: - static void doRelocations(const std::vector> &plugins, relocation_trampoline_entry_t *trampData, uint32_t tramp_size); static void memsetBSS(const std::vector> &plugins); diff --git a/source/common/plugin_defines.h b/source/common/plugin_defines.h index 7f3a06e..c108993 100644 --- a/source/common/plugin_defines.h +++ b/source/common/plugin_defines.h @@ -17,8 +17,8 @@ #pragma once -#include #include +#include #include #include #include @@ -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 diff --git a/source/config/WUPSConfig.h b/source/config/WUPSConfig.h index efedbfc..b767f4b 100644 --- a/source/config/WUPSConfig.h +++ b/source/config/WUPSConfig.h @@ -17,12 +17,12 @@ #pragma once -#include -#include -#include -#include #include "WUPSConfigCategory.h" #include "utils/logger.h" +#include +#include +#include +#include class WUPSConfig { public: @@ -31,7 +31,7 @@ public: } ~WUPSConfig() { - for (auto &element: categories) { + for (auto &element : categories) { delete element; } } diff --git a/source/config/WUPSConfigCategory.h b/source/config/WUPSConfigCategory.h index 5ea910d..14fb958 100644 --- a/source/config/WUPSConfigCategory.h +++ b/source/config/WUPSConfigCategory.h @@ -17,10 +17,10 @@ #pragma once +#include "WUPSConfigItem.h" #include #include #include -#include "WUPSConfigItem.h" class WUPSConfigCategory { public: @@ -29,7 +29,7 @@ public: } ~WUPSConfigCategory() { - for (auto &element: items) { + for (auto &element : items) { delete element; } } diff --git a/source/config/WUPSConfigCategoryExport.cpp b/source/config/WUPSConfigCategoryExport.cpp index cc0bb12..30bf2c6 100644 --- a/source/config/WUPSConfigCategoryExport.cpp +++ b/source/config/WUPSConfigCategoryExport.cpp @@ -1,7 +1,7 @@ +#include "../utils/logger.h" +#include "WUPSConfigCategory.h" #include #include -#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(handle); - auto *item = reinterpret_cast(item_Handle); + auto *item = reinterpret_cast(item_Handle); if (category->addItem(item)) { return 0; } diff --git a/source/config/WUPSConfigExport.cpp b/source/config/WUPSConfigExport.cpp index 5ace22e..841be45 100644 --- a/source/config/WUPSConfigExport.cpp +++ b/source/config/WUPSConfigExport.cpp @@ -1,7 +1,7 @@ +#include "../utils/logger.h" +#include "WUPSConfig.h" #include #include -#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(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(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(handle); - auto res = config->addCategory(reinterpret_cast(category)); + auto res = config->addCategory(reinterpret_cast(category)); if (res == nullptr) { return -1; } diff --git a/source/config/WUPSConfigItem.h b/source/config/WUPSConfigItem.h index cf00925..0e4f735 100644 --- a/source/config/WUPSConfigItem.h +++ b/source/config/WUPSConfigItem.h @@ -20,9 +20,9 @@ #include #include -#include #include "utils/StringTools.h" #include "utils/logger.h" +#include 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(); } diff --git a/source/config/WUPSConfigItemExport.cpp b/source/config/WUPSConfigItemExport.cpp index b1f2968..a1098c9 100644 --- a/source/config/WUPSConfigItemExport.cpp +++ b/source/config/WUPSConfigItemExport.cpp @@ -1,6 +1,6 @@ +#include "WUPSConfigItem.h" #include #include -#include "WUPSConfigItem.h" typedef uint32_t WUPSConfigItemHandle; diff --git a/source/elfio/elf_types.hpp b/source/elfio/elf_types.hpp index 63d025a..9a20040 100644 --- a/source/elfio/elf_types.hpp +++ b/source/elfio/elf_types.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio.hpp b/source/elfio/elfio.hpp index 2a0174e..1d691b1 100644 --- a/source/elfio/elfio.hpp +++ b/source/elfio/elfio.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_dump.hpp b/source/elfio/elfio_dump.hpp index 4ace665..015cff2 100644 --- a/source/elfio/elfio_dump.hpp +++ b/source/elfio/elfio_dump.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_dynamic.hpp b/source/elfio/elfio_dynamic.hpp index 42f2680..36de384 100644 --- a/source/elfio/elfio_dynamic.hpp +++ b/source/elfio/elfio_dynamic.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_header.hpp b/source/elfio/elfio_header.hpp index 6f8da02..e7b9a24 100644 --- a/source/elfio/elfio_header.hpp +++ b/source/elfio/elfio_header.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_note.hpp b/source/elfio/elfio_note.hpp index 8619c73..fbfc51c 100644 --- a/source/elfio/elfio_note.hpp +++ b/source/elfio/elfio_note.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_relocation.hpp b/source/elfio/elfio_relocation.hpp index 4a3fab0..641031a 100644 --- a/source/elfio/elfio_relocation.hpp +++ b/source/elfio/elfio_relocation.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_section.hpp b/source/elfio/elfio_section.hpp index ed3b908..52d3102 100644 --- a/source/elfio/elfio_section.hpp +++ b/source/elfio/elfio_section.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_segment.hpp b/source/elfio/elfio_segment.hpp index e906f3e..fa370fb 100644 --- a/source/elfio/elfio_segment.hpp +++ b/source/elfio/elfio_segment.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_strings.hpp b/source/elfio/elfio_strings.hpp index 552f000..5fc9bb1 100644 --- a/source/elfio/elfio_strings.hpp +++ b/source/elfio/elfio_strings.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_symbols.hpp b/source/elfio/elfio_symbols.hpp index d18756a..6205bd2 100644 --- a/source/elfio/elfio_symbols.hpp +++ b/source/elfio/elfio_symbols.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/elfio/elfio_utils.hpp b/source/elfio/elfio_utils.hpp index 2baf5a7..e567d41 100644 --- a/source/elfio/elfio_utils.hpp +++ b/source/elfio/elfio_utils.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/source/fs/CFile.cpp b/source/fs/CFile.cpp index 006bde9..ad0f902 100644 --- a/source/fs/CFile.cpp +++ b/source/fs/CFile.cpp @@ -1,14 +1,14 @@ #include #include -#include #include +#include 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; } - - diff --git a/source/fs/CFile.hpp b/source/fs/CFile.hpp index 2f638ed..c225322 100644 --- a/source/fs/CFile.hpp +++ b/source/fs/CFile.hpp @@ -1,9 +1,9 @@ #pragma once #include -#include #include #include +#include #include #include diff --git a/source/fs/DirList.cpp b/source/fs/DirList.cpp index d48ce2d..048d120 100644 --- a/source/fs/DirList.cpp +++ b/source/fs/DirList.cpp @@ -24,22 +24,22 @@ * DirList Class * for WiiXplorer 2010 ***************************************************************************/ +#include #include #include #include #include #include -#include -#include #include +#include #include #include 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) { diff --git a/source/fs/DirList.h b/source/fs/DirList.h index 8c3eba6..3cc62e1 100644 --- a/source/fs/DirList.h +++ b/source/fs/DirList.h @@ -27,8 +27,8 @@ #ifndef ___DIRLIST_H_ #define ___DIRLIST_H_ -#include #include +#include #include 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); diff --git a/source/fs/FSUtils.cpp b/source/fs/FSUtils.cpp index 58d2805..52fc4c1 100644 --- a/source/fs/FSUtils.cpp +++ b/source/fs/FSUtils.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include -#include #include "fs/FSUtils.h" #include "fs/CFile.hpp" #include "utils/logger.h" +#include +#include +#include +#include +#include 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; } - diff --git a/source/globals.cpp b/source/globals.cpp index cd35bd0..fd1a1b2 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -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{}; diff --git a/source/globals.h b/source/globals.h index 7a0db3a..1e93226 100644 --- a/source/globals.h +++ b/source/globals.h @@ -2,8 +2,8 @@ #include -#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 \ No newline at end of file +#define NUMBER_OF_TRAMPS 1024 \ No newline at end of file diff --git a/source/hooks.cpp b/source/hooks.cpp index 930a700..930620d 100644 --- a/source/hooks.cpp +++ b/source/hooks.cpp @@ -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); diff --git a/source/hooks.h b/source/hooks.h index 3d00b48..69b72d0 100644 --- a/source/hooks.h +++ b/source/hooks.h @@ -1,7 +1,7 @@ #pragma once -#include #include "common/plugin_defines.h" +#include void CallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type); diff --git a/source/main.cpp b/source/main.cpp index 6b07d69..04a9b34 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,18 +1,18 @@ -#include -#include -#include -#include -#include -#include -#include -#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 +#include +#include +#include +#include +#include +#include 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(&custom_memalign)); - auto *customMEMAllocFromDefaultHeapEx = (void *(*)(uint32_t, int)) *custom_memalign; + dyn_res = OSDynLoad_FindExport(module, true, "MEMAllocFromMappedMemoryEx", reinterpret_cast(&custom_memalign)); + auto *customMEMAllocFromDefaultHeapEx = (void *(*) (uint32_t, int) ) * custom_memalign; if (dyn_res != OS_DYNLOAD_OK) { return nullptr; diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index 438bcfc..d86eac4 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -1,16 +1,16 @@ #include "hooks_patcher_static.h" -#include -#include -#include -#include #include +#include +#include +#include +#include -#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 §ionInfo: plugin->info.sectionInfos) { + for (auto §ionInfo : 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 §ionInfo: plugin->info.sectionInfos) { + for (auto §ionInfo : 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); } diff --git a/source/plugin/DynamicLinkingHelper.cpp b/source/plugin/DynamicLinkingHelper.cpp index d97557b..8001aa4 100644 --- a/source/plugin/DynamicLinkingHelper.cpp +++ b/source/plugin/DynamicLinkingHelper.cpp @@ -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); diff --git a/source/plugin/DynamicLinkingHelper.h b/source/plugin/DynamicLinkingHelper.h index f5feec0..20c9c8f 100644 --- a/source/plugin/DynamicLinkingHelper.h +++ b/source/plugin/DynamicLinkingHelper.h @@ -1,10 +1,10 @@ #pragma once -#include +#include "RelocationData.h" +#include #include #include -#include -#include "RelocationData.h" +#include class DynamicLinkingHelper { public: diff --git a/source/plugin/FunctionData.h b/source/plugin/FunctionData.h index 90b1fb8..87c57dd 100644 --- a/source/plugin/FunctionData.h +++ b/source/plugin/FunctionData.h @@ -16,22 +16,22 @@ ****************************************************************************/ #pragma once -#include -#include #include +#include +#include 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; }; - diff --git a/source/plugin/FunctionSymbolData.h b/source/plugin/FunctionSymbolData.h index 676a341..f846ed9 100644 --- a/source/plugin/FunctionSymbolData.h +++ b/source/plugin/FunctionSymbolData.h @@ -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; diff --git a/source/plugin/HookData.h b/source/plugin/HookData.h index 599b580..a9d3286 100644 --- a/source/plugin/HookData.h +++ b/source/plugin/HookData.h @@ -17,15 +17,15 @@ #pragma once -#include #include +#include 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; diff --git a/source/plugin/ImportRPLInformation.h b/source/plugin/ImportRPLInformation.h index eac26d5..09d6896 100644 --- a/source/plugin/ImportRPLInformation.h +++ b/source/plugin/ImportRPLInformation.h @@ -17,15 +17,15 @@ #pragma once +#include "../utils/logger.h" #include #include -#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; } diff --git a/source/plugin/PluginContainer.h b/source/plugin/PluginContainer.h index b7936b0..9381d86 100644 --- a/source/plugin/PluginContainer.h +++ b/source/plugin/PluginContainer.h @@ -17,17 +17,17 @@ #pragma once -#include #include "PluginData.h" -#include "PluginMetaInformation.h" #include "PluginInformation.h" +#include "PluginMetaInformation.h" +#include 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; diff --git a/source/plugin/PluginContainerPersistence.cpp b/source/plugin/PluginContainerPersistence.cpp index 1b97043..cf8008d 100644 --- a/source/plugin/PluginContainerPersistence.cpp +++ b/source/plugin/PluginContainerPersistence.cpp @@ -2,12 +2,12 @@ #include +#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 &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> 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> 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> 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((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library, + auto func = std::make_shared((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> 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(symbol_name, (void *) symbol_data->address, symbol_data->size); + auto funSymbolData = std::make_shared(symbol_name, (void *) symbol_data->address, symbol_data->size); curPluginInformation->addFunctionSymbolData(funSymbolData); } diff --git a/source/plugin/PluginData.cpp b/source/plugin/PluginData.cpp index c6bf04d..fd8c3cd 100644 --- a/source/plugin/PluginData.cpp +++ b/source/plugin/PluginData.cpp @@ -1,14 +1,14 @@ #include "PluginData.h" -#include -#include #include "../utils/logger.h" +#include +#include 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 &buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) { } -PluginData::PluginData(const std::vector &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) : - heapHandle(heapHandle), - memoryType(memoryType), - length(input.size()) { +PluginData::PluginData(const std::vector &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) : heapHandle(heapHandle), + memoryType(memoryType), + length(input.size()) { void *data_copy = nullptr; switch (memoryType) { default: diff --git a/source/plugin/PluginData.h b/source/plugin/PluginData.h index 0ce371b..052db31 100644 --- a/source/plugin/PluginData.h +++ b/source/plugin/PluginData.h @@ -17,10 +17,10 @@ #pragma once +#include +#include #include #include -#include -#include #include "../elfio/elfio.hpp" diff --git a/source/plugin/PluginDataFactory.cpp b/source/plugin/PluginDataFactory.cpp index 8b50efb..4c9b96f 100644 --- a/source/plugin/PluginDataFactory.cpp +++ b/source/plugin/PluginDataFactory.cpp @@ -14,13 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include -#include #include "PluginDataFactory.h" -#include "../utils/logger.h" #include "../utils/StringTools.h" +#include "../utils/logger.h" +#include +#include +#include +#include std::vector> PluginDataFactory::loadDir(const std::string &path, MEMHeapHandle heapHandle) { @@ -39,7 +39,7 @@ std::vector> 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) { diff --git a/source/plugin/PluginDataFactory.h b/source/plugin/PluginDataFactory.h index 46b6237..25b137e 100644 --- a/source/plugin/PluginDataFactory.h +++ b/source/plugin/PluginDataFactory.h @@ -17,11 +17,12 @@ #pragma once +#include "PluginData.h" +#include +#include #include #include #include -#include -#include "PluginData.h" class PluginDataFactory { public: diff --git a/source/plugin/PluginDataPersistence.cpp b/source/plugin/PluginDataPersistence.cpp index 369a2de..ab20d61 100644 --- a/source/plugin/PluginDataPersistence.cpp +++ b/source/plugin/PluginDataPersistence.cpp @@ -1,15 +1,15 @@ -#include -#include "../common/plugin_defines.h" #include "PluginDataPersistence.h" +#include "../common/plugin_defines.h" +#include bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, const std::shared_ptr &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 PluginDataPersistence::load(plugin_data_t *pluginDataStruct) { auto pluginData = std::make_shared(); - 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; diff --git a/source/plugin/PluginDataPersistence.h b/source/plugin/PluginDataPersistence.h index 6cc054c..deac7f0 100644 --- a/source/plugin/PluginDataPersistence.h +++ b/source/plugin/PluginDataPersistence.h @@ -1,6 +1,8 @@ #pragma once +#include "../common/plugin_defines.h" #include "PluginData.h" +#include class PluginDataPersistence { diff --git a/source/plugin/PluginInformation.cpp b/source/plugin/PluginInformation.cpp index cbb92ec..7365f16 100644 --- a/source/plugin/PluginInformation.cpp +++ b/source/plugin/PluginInformation.cpp @@ -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; } \ No newline at end of file diff --git a/source/plugin/PluginInformation.h b/source/plugin/PluginInformation.h index 0827224..f4f9495 100644 --- a/source/plugin/PluginInformation.h +++ b/source/plugin/PluginInformation.h @@ -17,18 +17,18 @@ #pragma once -#include -#include -#include -#include -#include -#include +#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 +#include +#include +#include +#include +#include struct FunctionSymbolDataComparator { bool operator()(const std::shared_ptr &lhs, diff --git a/source/plugin/PluginInformationFactory.cpp b/source/plugin/PluginInformationFactory.cpp index 4ba9d08..67174c5 100644 --- a/source/plugin/PluginInformationFactory.cpp +++ b/source/plugin/PluginInformationFactory.cpp @@ -15,17 +15,17 @@ * along with this program. If not, see . ****************************************************************************/ +#include "PluginInformationFactory.h" +#include "../utils/ElfUtils.h" +#include "../utils/utils.h" +#include "PluginData.h" +#include +#include +#include #include #include #include -#include -#include -#include #include -#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, ME auto pluginInfo = std::make_shared(); - 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, 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, 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, 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, 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((void *) hook->target, hook->type); pluginInfo->addHookData(hook_data); } @@ -187,12 +187,12 @@ PluginInformationFactory::load(const std::shared_ptr &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((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, 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> 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; diff --git a/source/plugin/PluginInformationFactory.h b/source/plugin/PluginInformationFactory.h index 3c658fd..5693244 100644 --- a/source/plugin/PluginInformationFactory.h +++ b/source/plugin/PluginInformationFactory.h @@ -17,15 +17,15 @@ #pragma once +#include "../elfio/elfio.hpp" +#include "PluginContainer.h" +#include "PluginInformation.h" +#include +#include #include #include #include -#include -#include #include -#include "PluginInformation.h" -#include "PluginContainer.h" -#include "../elfio/elfio.hpp" class PluginInformationFactory { public: diff --git a/source/plugin/PluginMetaInformation.cpp b/source/plugin/PluginMetaInformation.cpp index 8f55b84..0380624 100644 --- a/source/plugin/PluginMetaInformation.cpp +++ b/source/plugin/PluginMetaInformation.cpp @@ -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; } \ No newline at end of file diff --git a/source/plugin/PluginMetaInformationFactory.cpp b/source/plugin/PluginMetaInformationFactory.cpp index 5d0d327..83098b4 100644 --- a/source/plugin/PluginMetaInformationFactory.cpp +++ b/source/plugin/PluginMetaInformationFactory.cpp @@ -15,12 +15,12 @@ * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include -#include -#include "../utils/StringTools.h" #include "PluginMetaInformationFactory.h" +#include "../utils/StringTools.h" +#include +#include +#include +#include using namespace ELFIO; @@ -69,7 +69,7 @@ std::optional> 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> 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) { diff --git a/source/plugin/PluginMetaInformationFactory.h b/source/plugin/PluginMetaInformationFactory.h index c39491f..22d3adf 100644 --- a/source/plugin/PluginMetaInformationFactory.h +++ b/source/plugin/PluginMetaInformationFactory.h @@ -17,12 +17,12 @@ #pragma once +#include "PluginData.h" +#include "PluginMetaInformation.h" +#include #include #include -#include #include -#include "PluginMetaInformation.h" -#include "PluginData.h" class PluginMetaInformationFactory { public: diff --git a/source/plugin/RelocationData.h b/source/plugin/RelocationData.h index f3fad0e..c283658 100644 --- a/source/plugin/RelocationData.h +++ b/source/plugin/RelocationData.h @@ -17,20 +17,20 @@ #pragma once +#include "ImportRPLInformation.h" +#include #include #include -#include "ImportRPLInformation.h" class RelocationData { public: - RelocationData(const char type, size_t offset, int32_t addend, void *destination, std::string &name, std::shared_ptr 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 rplInfo) : type(type), + offset(offset), + addend(addend), + destination(destination), + name(name), + rplInfo(std::move(rplInfo)) { } RelocationData(const RelocationData &o2) = default; diff --git a/source/plugin/SectionInfo.h b/source/plugin/SectionInfo.h index b8c4a13..e837f94 100644 --- a/source/plugin/SectionInfo.h +++ b/source/plugin/SectionInfo.h @@ -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; diff --git a/source/utils/ConfigUtils.cpp b/source/utils/ConfigUtils.cpp index 1e26ba5..f95bc51 100644 --- a/source/utils/ConfigUtils.cpp +++ b/source/utils/ConfigUtils.cpp @@ -1,26 +1,26 @@ #include "ConfigUtils.h" -#include "logger.h" #include "../config/WUPSConfig.h" #include "../globals.h" #include "DrawUtils.h" +#include "logger.h" +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#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(((WUPSConfigHandle (*)()) ((uint32_t *) hook_data->func_pointer))()); + auto *cur_config = reinterpret_cast(((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(storedTVBuffer.mode), diff --git a/source/utils/DrawUtils.cpp b/source/utils/DrawUtils.cpp index 928125d..89bbe07 100644 --- a/source/utils/DrawUtils.cpp +++ b/source/utils/DrawUtils.cpp @@ -2,31 +2,31 @@ #include #include -#include #include +#include #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); diff --git a/source/utils/DrawUtils.h b/source/utils/DrawUtils.h index af88e3c..36befd2 100644 --- a/source/utils/DrawUtils.h +++ b/source/utils/DrawUtils.h @@ -3,7 +3,7 @@ #include // visible screen sizes -#define SCREEN_WIDTH 854 +#define SCREEN_WIDTH 854 #define SCREEN_HEIGHT 480 union Color { diff --git a/source/utils/ElfUtils.cpp b/source/utils/ElfUtils.cpp index dfcf3b3..62792d1 100644 --- a/source/utils/ElfUtils.cpp +++ b/source/utils/ElfUtils.cpp @@ -1,8 +1,8 @@ -#include #include +#include -#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(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(value) - static_cast(target); + auto symbolValue = (uint32_t) & (freeSlot->trampoline[0]); + value = symbolValue + addend; + distance = static_cast(value) - static_cast(target); } } diff --git a/source/utils/ElfUtils.h b/source/utils/ElfUtils.h index cb85d14..0a1f532 100644 --- a/source/utils/ElfUtils.h +++ b/source/utils/ElfUtils.h @@ -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 } diff --git a/source/utils/StorageUtils.cpp b/source/utils/StorageUtils.cpp index b603a47..18ed01f 100644 --- a/source/utils/StorageUtils.cpp +++ b/source/utils/StorageUtils.cpp @@ -1,40 +1,40 @@ #include "StorageUtils.h" #include -#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().size() + 1; - item->data = malloc(size); + item->type = WUPS_STORAGE_TYPE_STRING; + uint32_t size = it.value().get().size() + 1; + item->data = malloc(size); item->data_size = size; strcpy((char *) item->data, it.value().get().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(); } 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()); diff --git a/source/utils/StringTools.cpp b/source/utils/StringTools.cpp index 5482205..b8a3dec 100644 --- a/source/utils/StringTools.cpp +++ b/source/utils/StringTools.cpp @@ -23,14 +23,14 @@ * * for WiiXplorer 2010 ***************************************************************************/ -#include -#include #include +#include #include #include -#include -#include +#include #include +#include +#include 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); diff --git a/source/utils/StringTools.h b/source/utils/StringTools.h index 07b7e42..1a30df9 100644 --- a/source/utils/StringTools.h +++ b/source/utils/StringTools.h @@ -26,8 +26,8 @@ #ifndef __STRING_TOOLS_H #define __STRING_TOOLS_H -#include #include +#include #include 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 */ - diff --git a/source/utils/exports.cpp b/source/utils/exports.cpp index e9b9f76..9748aaa 100644 --- a/source/utils/exports.cpp +++ b/source/utils/exports.cpp @@ -1,15 +1,15 @@ -#include -#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 #include -void fillPluginInformation(plugin_information *out, const std::shared_ptr &metaInformation) { +static void fillPluginInformation(plugin_information *out, const std::shared_ptr &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 { diff --git a/source/utils/exports.h b/source/utils/exports.h index 8a6331a..51bc25a 100644 --- a/source/utils/exports.h +++ b/source/utils/exports.h @@ -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); diff --git a/source/utils/json.hpp b/source/utils/json.hpp index 608fb06..5adab44 100644 --- a/source/utils/json.hpp +++ b/source/utils/json.hpp @@ -1,3 +1,4 @@ +// clang-format off /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ diff --git a/source/utils/logger.c b/source/utils/logger.c index 0411db7..f700806 100644 --- a/source/utils/logger.c +++ b/source/utils/logger.c @@ -1,19 +1,19 @@ #ifdef DEBUG #include -#include #include #include +#include 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 } diff --git a/source/utils/logger.h b/source/utils/logger.h index 6ff5ae2..061d52e 100644 --- a/source/utils/logger.h +++ b/source/utils/logger.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #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 - diff --git a/source/utils/utils.c b/source/utils/utils.c index 9947850..5c4e503 100644 --- a/source/utils/utils.c +++ b/source/utils/utils.c @@ -1,11 +1,11 @@ -#include -#include +#include "utils/logger.h" +#include #include #include #include -#include +#include +#include #include -#include "utils/logger.h" // https://gist.github.com/ccbrown/9722406 void dumpHex(const void *data, size_t size) { diff --git a/source/utils/utils.h b/source/utils/utils.h index a502522..2890779 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -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);