Format the code via clang-format

This commit is contained in:
Maschell 2022-02-04 21:44:03 +01:00
parent 66e5d5b9f3
commit 00dec53199
61 changed files with 528 additions and 427 deletions

67
.clang-format Normal file
View File

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

View File

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

View File

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

View File

@ -1,3 +1,5 @@
[![CI-Release](https://github.com/wiiu-env/WUMSLoader/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/WUMSLoader/actions/workflows/ci.yml)
# Wii U Module System Loader
This is a payload that should be run with [EnvironmentLoader](https://github.com/wiiu-env/EnvironmentLoader).
@ -29,6 +31,9 @@ docker run -it --rm -v ${PWD}:/project wumsloader-builder make
docker run -it --rm -v ${PWD}:/project wumsloader-builder make clean
```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source ./relocator/src -i`
## Credits
- maschell

View File

@ -9,7 +9,7 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
return nullptr;
}
dyn_linking_function_t *result = nullptr;
for (auto &function: data->functions) {
for (auto &function : data->functions) {
dyn_linking_function_t *curEntry = &function;
if (strlen(curEntry->functionName) == 0) {
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
@ -41,7 +41,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return nullptr;
}
dyn_linking_import_t *result = nullptr;
for (auto &import: data->imports) {
for (auto &import : data->imports) {
dyn_linking_import_t *curEntry = &import;
if (strlen(curEntry->importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {

View File

@ -1,10 +1,10 @@
#pragma once
#include <wums.h>
#include "../../source/module/RelocationData.h"
#include "utils/logger.h"
#include <string>
#include <vector>
#include "../../source/module/RelocationData.h"
#include <wums.h>
class DynamicLinkingHelper {
public:

View File

@ -1,7 +1,7 @@
#include <coreinit/cache.h>
#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,
@ -94,13 +94,13 @@ 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\n");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampoline[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", 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\n", value, target, (target - (uint32_t) &(freeSlot->trampoline[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampoline[0])));
return false;
}
@ -117,7 +117,7 @@ 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]);
auto symbolValue = (uint32_t) & (freeSlot->trampoline[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
}

View File

@ -15,8 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "../../source/module/RelocationData.h"
#include "../../source/module/HookData.h"
#include "../../source/module/RelocationData.h"
#include <vector>
#pragma once
@ -75,6 +76,7 @@ public:
}
bool relocationsDone = false;
private:
std::vector<std::shared_ptr<RelocationData>> relocation_data_list;
std::vector<std::shared_ptr<HookData>> hook_data_list;

View File

@ -29,14 +29,14 @@ std::vector<std::shared_ptr<ModuleDataMinimal>> ModuleDataPersistence::loadModul
moduleData->setSkipInitFini(module_data->skipInitFini);
moduleData->setExportName(module_data->module_export_name);
for (auto &hook_entry: module_data->hook_entries) {
for (auto &hook_entry : module_data->hook_entries) {
if (hook_entry.target == 0) {
continue;
}
moduleData->addHookData(std::make_shared<HookData>(static_cast<wums_hook_type_t>(hook_entry.type), reinterpret_cast<const void *>(hook_entry.target)));
}
for (auto &linking_entry: module_data->linking_entries) {
for (auto &linking_entry : module_data->linking_entries) {
if (linking_entry.destination == nullptr) {
break;
}

View File

@ -1,8 +1,8 @@
#pragma once
#include <wums.h>
#include <vector>
#include "ModuleDataMinimal.h"
#include <vector>
#include <wums.h>
class ModuleDataPersistence {
public:

View File

@ -1,19 +1,19 @@
#include <vector>
#include <string>
#include <cstdint>
#include <coreinit/dynload.h>
#include <coreinit/cache.h>
#include <map>
#include <algorithm>
#include <coreinit/memexpheap.h>
#include "utils/logger.h"
#include "utils/memory.h"
#include "../../source/module/RelocationData.h"
#include "ModuleDataPersistence.h"
#include "ElfUtils.h"
#include "utils/dynamic.h"
#include "ModuleDataPersistence.h"
#include "globals.h"
#include "hooks.h"
#include "utils/dynamic.h"
#include "utils/logger.h"
#include "utils/memory.h"
#include <algorithm>
#include <coreinit/cache.h>
#include <coreinit/dynload.h>
#include <coreinit/memexpheap.h>
#include <cstdint>
#include <map>
#include <string>
#include <vector>
MEMHeapHandle gHeapHandle __attribute__((section(".data"))) = nullptr;
uint8_t gFunctionsPatched __attribute__((section(".data"))) = 0;
@ -45,12 +45,12 @@ extern "C" int _start(int argc, char **argv) {
DEBUG_FUNCTION_LINE_VERBOSE("Call real one\n");
log_deinit();
return ((int (*)(int, char **)) (*(unsigned int *) 0x1005E040))(argc, argv);
return ((int (*)(int, char **))(*(unsigned int *) 0x1005E040))(argc, argv);
}
bool doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampoline_entry_t *tramp_data, uint32_t tramp_length, bool skipAllocReplacement) {
std::map<std::string, OSDynLoad_Module> moduleCache;
for (auto const &curReloc: relocData) {
for (auto const &curReloc : relocData) {
std::string functionName = curReloc->getName();
std::string rplName = curReloc->getImportRPLInformation()->getName();
uint32_t functionAddress = 0;
@ -115,7 +115,7 @@ bool doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, reloc
bool ResolveRelocations(std::vector<std::shared_ptr<ModuleDataMinimal>> &loadedModules, bool skipMemoryMappingModule) {
bool wasSuccessful = true;
for (auto &curModule: loadedModules) {
for (auto &curModule : loadedModules) {
DEBUG_FUNCTION_LINE_VERBOSE("Let's do the relocations for %s\n", curModule->getExportName().c_str());
if (wasSuccessful) {
auto relocData = curModule->getRelocationDataList();
@ -132,7 +132,6 @@ bool ResolveRelocations(std::vector<std::shared_ptr<ModuleDataMinimal>> &loadedM
curModule->relocationsDone = false;
}
curModule->relocationsDone = true;
}
}
DCFlushRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE);
@ -149,7 +148,7 @@ extern "C" void doStart(int argc, char **argv) {
auto loadedModules = OrderModulesByDependencies(loadedModulesUnordered);
bool applicationEndHookLoaded = false;
for (auto &curModule: loadedModules) {
for (auto &curModule : loadedModules) {
if (curModule->getExportName() == "homebrew_applicationendshook") {
DEBUG_FUNCTION_LINE_VERBOSE("We have ApplicationEndsHook Module!\n");
applicationEndHookLoaded = true;
@ -158,8 +157,8 @@ extern "C" void doStart(int argc, char **argv) {
}
// Make sure WUMS_HOOK_APPLICATION_ENDS and WUMS_HOOK_FINI_WUT are called
for (auto &curModule: loadedModules) {
for (auto &curHook: curModule->getHookDataList()) {
for (auto &curModule : loadedModules) {
for (auto &curHook : curModule->getHookDataList()) {
if (curHook->getType() == WUMS_HOOK_APPLICATION_ENDS || curHook->getType() == WUMS_HOOK_FINI_WUT_DEVOPTAB) {
if (!applicationEndHookLoaded) {
OSFatal_printf("%s requires module homebrew_applicationendshook", curModule->getExportName().c_str());
@ -175,7 +174,7 @@ extern "C" void doStart(int argc, char **argv) {
DEBUG_FUNCTION_LINE_VERBOSE("Resolve relocations without replacing alloc functions\n");
ResolveRelocations(loadedModules, true);
for (auto &curModule: loadedModules) {
for (auto &curModule : loadedModules) {
if (curModule->isInitBeforeRelocationDoneHook()) {
CallInitHooksForModule(curModule);
}
@ -184,7 +183,7 @@ extern "C" void doStart(int argc, char **argv) {
DEBUG_FUNCTION_LINE_VERBOSE("Call Relocations done hook\n");
CallHook(loadedModules, WUMS_HOOK_RELOCATIONS_DONE);
for (auto &curModule: loadedModules) {
for (auto &curModule : loadedModules) {
if (!curModule->isInitBeforeRelocationDoneHook()) {
CallInitHooksForModule(curModule);
}
@ -200,7 +199,7 @@ extern "C" void doStart(int argc, char **argv) {
CallHook(loadedModules, WUMS_HOOK_INIT_WUT_STDCPP);
CallHook(loadedModules, WUMS_HOOK_INIT_WUT_DEVOPTAB);
CallHook(loadedModules, WUMS_HOOK_INIT_WUT_SOCKETS);
for (auto &curModule: loadedModules) {
for (auto &curModule : loadedModules) {
CallHook(curModule, WUMS_HOOK_INIT_WRAPPER, !curModule->isSkipInitFini());
}
CallHook(loadedModules, WUMS_HOOK_APPLICATION_STARTS);
@ -230,7 +229,7 @@ std::vector<std::shared_ptr<ModuleDataMinimal>> OrderModulesByDependencies(const
while (true) {
bool canBreak = true;
bool weDidSomething = false;
for (auto const &curModule: loadedModules) {
for (auto const &curModule : loadedModules) {
if (std::find(loadedModulesEntrypoints.begin(), loadedModulesEntrypoints.end(), curModule->getEntrypoint()) != loadedModulesEntrypoints.end()) {
// DEBUG_FUNCTION_LINE("%s [%08X] is already loaded\n", curModule->getExportName().c_str(), curModule->getEntrypoint());
continue;
@ -238,7 +237,7 @@ std::vector<std::shared_ptr<ModuleDataMinimal>> OrderModulesByDependencies(const
canBreak = false;
DEBUG_FUNCTION_LINE_VERBOSE("Check if we can load %s\n", curModule->getExportName().c_str());
std::vector<std::string> importsFromOtherModules;
for (const auto &curReloc: curModule->getRelocationDataList()) {
for (const auto &curReloc : curModule->getRelocationDataList()) {
std::string curRPL = curReloc->getImportRPLInformation()->getName();
if (curRPL.rfind("homebrew", 0) == 0) {
if (std::find(importsFromOtherModules.begin(), importsFromOtherModules.end(), curRPL) != importsFromOtherModules.end()) {
@ -250,7 +249,7 @@ std::vector<std::shared_ptr<ModuleDataMinimal>> OrderModulesByDependencies(const
}
}
bool canLoad = true;
for (auto &curImportRPL: importsFromOtherModules) {
for (auto &curImportRPL : importsFromOtherModules) {
if (std::find(loadedModulesExportNames.begin(), loadedModulesExportNames.end(), curImportRPL) != loadedModulesExportNames.end()) {
} else {

View File

@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include "../../source/globals.h"
#include <cstdint>
extern uint32_t MemoryMappingEffectiveToPhysicalPTR;
extern uint32_t MemoryMappingPhysicalToEffectivePTR;

View File

@ -1,8 +1,8 @@
#include <wums.h>
#include "hooks.h"
#include "globals.h"
#include <wums.h>
static const char **hook_names = (const char *[]) {
static const char **hook_names = (const char *[]){
"WUMS_HOOK_INIT_WUT_MALLOC",
"WUMS_HOOK_FINI_WUT_MALLOC",
"WUMS_HOOK_INIT_WUT_NEWLIB",
@ -21,8 +21,7 @@ static const char **hook_names = (const char *[]) {
"WUMS_HOOK_APPLICATION_STARTS",
"WUMS_HOOK_APPLICATION_ENDS",
"WUMS_HOOK_RELOCATIONS_DONE",
"WUMS_HOOK_APPLICATION_REQUESTS_EXIT"
};
"WUMS_HOOK_APPLICATION_REQUESTS_EXIT"};
void CallHook(const std::vector<std::shared_ptr<ModuleDataMinimal>> &modules, wums_hook_type_t type, bool condition) {
if (condition) {
@ -32,7 +31,7 @@ void CallHook(const std::vector<std::shared_ptr<ModuleDataMinimal>> &modules, wu
void CallHook(const std::vector<std::shared_ptr<ModuleDataMinimal>> &modules, wums_hook_type_t type) {
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] for all modules\n", hook_names[type], type);
for (auto &curModule: modules) {
for (auto &curModule : modules) {
CallHook(curModule, type);
}
}
@ -49,7 +48,7 @@ void CallHook(const std::shared_ptr<ModuleDataMinimal> &module, wums_hook_type_t
return;
}
for (auto &curHook: module->getHookDataList()) {
for (auto &curHook : module->getHookDataList()) {
auto func_ptr = (uint32_t) curHook->getTarget();
if (func_ptr == 0) {
DEBUG_FUNCTION_LINE("Hook ptr was NULL\n");
@ -70,17 +69,16 @@ void CallHook(const std::shared_ptr<ModuleDataMinimal> &module, wums_hook_type_t
type == WUMS_HOOK_INIT_WUT_SOCKETS ||
type == WUMS_HOOK_FINI_WUT_SOCKETS ||
type == WUMS_HOOK_INIT_WRAPPER ||
type == WUMS_HOOK_FINI_WRAPPER
)) {
type == WUMS_HOOK_FINI_WRAPPER)) {
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] %d for %s: %08X\n", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget());
((void (*)()) ((uint32_t *) func_ptr))();
((void (*)())((uint32_t *) func_ptr))();
break;
} else if (type == WUMS_HOOK_INIT ||
type == WUMS_HOOK_RELOCATIONS_DONE) {
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] %d for %s: %08X\n", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget());
wums_app_init_args_t args;
args.module_information = gModuleData;
((void (*)(wums_app_init_args_t *)) ((uint32_t *) func_ptr))(&args);
((void (*)(wums_app_init_args_t *))((uint32_t *) func_ptr))(&args);
} else {
DEBUG_FUNCTION_LINE("#########################################\n");
DEBUG_FUNCTION_LINE("#########HOOK NOT IMPLEMENTED %d#########\n", type);

View File

@ -1,8 +1,8 @@
#pragma once
#include <wums.h>
#include <vector>
#include "ModuleDataMinimal.h"
#include <vector>
#include <wums.h>
void CallHook(const std::vector<std::shared_ptr<ModuleDataMinimal>> &modules, wums_hook_type_t type, bool condition);

View File

@ -1,7 +1,7 @@
#include <coreinit/dynload.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#define IMPORT(name) void* addr_##name
#define IMPORT(name) void *addr_##name
#define IMPORT_BEGIN(lib)
#define IMPORT_END()
@ -11,8 +11,14 @@
#undef IMPORT_BEGIN
#undef IMPORT_END
#define IMPORT(name) do{if(OSDynLoad_FindExport(handle, 0, #name, &addr_##name) < 0)OSFatal("Function " # name " is NULL");} while(0)
#define IMPORT_BEGIN(lib) do{if(OSDynLoad_IsModuleLoaded(#lib ".rpl", &handle) != OS_DYNLOAD_OK) OSFatal(#lib ".rpl is not loaded");} while(0)
#define IMPORT(name) \
do { \
if (OSDynLoad_FindExport(handle, 0, #name, &addr_##name) < 0) OSFatal("Function " #name " is NULL"); \
} while (0)
#define IMPORT_BEGIN(lib) \
do { \
if (OSDynLoad_IsModuleLoaded(#lib ".rpl", &handle) != OS_DYNLOAD_OK) OSFatal(#lib ".rpl is not loaded"); \
} while (0)
#define IMPORT_END()
@ -23,5 +29,4 @@ void InitFunctionPointers(void) {
addr_OSDynLoad_IsModuleLoaded = (void *) 0x0102A59C; // 0200e19c - 0xFE3C00
#include "imports.h"
}

View File

@ -1,12 +1,12 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "logger.h"
#include <coreinit/debug.h>
#include <coreinit/systeminfo.h>
#include <coreinit/thread.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int log_socket __attribute__((section(".data"))) = -1;
static struct sockaddr_in connect_addr __attribute__((section(".data")));
@ -139,4 +139,3 @@ void log_printf(const char *format, ...) {
}
va_end(va);
}

View File

@ -20,16 +20,19 @@ void OSFatal_printf(const char *format, ...);
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...) \
do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
do { \
log_printf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...)do { \
log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) \
do { \
log_printf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#ifdef __cplusplus

View File

@ -14,14 +14,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <coreinit/memexpheap.h>
#include <coreinit/memdefaultheap.h>
#include <coreinit/memorymap.h>
#include "logger.h"
#include <coreinit/cache.h>
#include <coreinit/memdefaultheap.h>
#include <coreinit/memexpheap.h>
#include <coreinit/memorymap.h>
#include <errno.h>
#include <malloc.h>
#include <string.h>
#include <errno.h>
#include "logger.h"
extern MEMHeapHandle gHeapHandle;
@ -57,9 +57,9 @@ void MemoryFree(void *ptr) {
}
}
uint32_t MEMAlloc __attribute__((__section__ (".data"))) = (uint32_t) MemoryAlloc;
uint32_t MEMAllocEx __attribute__((__section__ (".data"))) = (uint32_t) MemoryAllocEx;
uint32_t MEMFree __attribute__((__section__ (".data"))) = (uint32_t) MemoryFree;
uint32_t MEMAlloc __attribute__((__section__(".data"))) = (uint32_t) MemoryAlloc;
uint32_t MEMAllocEx __attribute__((__section__(".data"))) = (uint32_t) MemoryAllocEx;
uint32_t MEMFree __attribute__((__section__(".data"))) = (uint32_t) MemoryFree;
//!-------------------------------------------------------------------------------------------
//! reent versions
@ -113,12 +113,10 @@ struct mallinfo _mallinfo_r(struct _reent *r) {
return info;
}
void
_malloc_stats_r(struct _reent *r) {
void _malloc_stats_r(struct _reent *r) {
}
int
_mallopt_r(struct _reent *r, int param, int value) {
int _mallopt_r(struct _reent *r, int param, int value) {
return 0;
}
@ -137,7 +135,6 @@ _pvalloc_r(struct _reent *r, size_t size) {
return MemoryAllocEx((size + (OS_PAGE_SIZE - 1)) & ~(OS_PAGE_SIZE - 1), OS_PAGE_SIZE);
}
int
_malloc_trim_r(struct _reent *r, size_t pad) {
int _malloc_trim_r(struct _reent *r, size_t pad) {
return 0;
}

View File

@ -1,13 +1,13 @@
#include <coreinit/debug.h>
#include "utils/logger.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/memdefaultheap.h>
#include <whb/sdcard.h>
#include <whb/file.h>
#include <whb/log.h>
#include "utils/logger.h"
#include <whb/sdcard.h>
#include "elfio/elfio.hpp"
#include "ElfUtils.h"
#include "elfio/elfio.hpp"
int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *sizeOut) {
char path[256];
@ -31,7 +31,7 @@ int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *si
goto exit;
}
exit:
exit:
WHBUnmountSdCard();
return result;
}
@ -199,12 +199,12 @@ 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\n");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampoline[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", 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\n", value, target, (target - (uint32_t) &(freeSlot->trampoline[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampoline[0])));
return false;
}
@ -221,7 +221,7 @@ 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]);
auto symbolValue = (uint32_t) & (freeSlot->trampoline[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <fs/CFile.hpp>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
CFile::CFile() {
iFd = -1;
@ -171,5 +171,3 @@ int32_t CFile::fwrite(const char *format, ...) {
return result;
}

View File

@ -1,10 +1,10 @@
#ifndef CFILE_HPP_
#define CFILE_HPP_
#include <stdio.h>
#include <string>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <wut_types.h>

View File

@ -24,14 +24,14 @@
* DirList Class
* for WiiXplorer 2010
***************************************************************************/
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <strings.h>
#include <algorithm>
#include <sys/stat.h>
#include <sys/dirent.h>
#include <sys/stat.h>
#include <fs/DirList.h>
#include <utils/StringTools.h>

View File

@ -27,8 +27,8 @@
#ifndef ___DIRLIST_H_
#define ___DIRLIST_H_
#include <vector>
#include <string>
#include <vector>
#include <wut_types.h>
typedef struct {
@ -97,6 +97,7 @@ public:
Dirs = 0x02,
CheckSubfolders = 0x08,
};
protected:
// Internal parser
BOOL InternalLoadPath(std::string &path);

View File

@ -1,6 +1,6 @@
#include "kernel.h"
#include "relocator_elf.h"
#include "ElfUtils.h"
#include "relocator_elf.h"
#include <coreinit/cache.h>
#include <coreinit/memorymap.h>
@ -37,8 +37,8 @@ void KernelWriteU32(uint32_t addr, uint32_t value) {
}
/* Write a 32-bit word with kernel permissions */
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) {
asm volatile (
void __attribute__((noinline)) kern_write(void *addr, uint32_t value) {
asm volatile(
"li 3,1\n"
"li 4,0\n"
"mr 5,%1\n"
@ -54,6 +54,5 @@ void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) {
:
: "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12"
);
"11", "12");
}

View File

@ -14,4 +14,4 @@ void SetupRelocator();
void KernelWriteU32(uint32_t addr, uint32_t value);
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value);
void __attribute__((noinline)) kern_write(void *addr, uint32_t value);

View File

@ -1,15 +1,15 @@
#include <cstring>
#include <elfio/elfio.hpp>
#include <sysapp/launch.h>
#include <nn/act/client_cpp.h>
#include <sysapp/launch.h>
#include "fs/DirList.h"
#include "module/ModuleDataPersistence.h"
#include "module/ModuleDataFactory.h"
#include "ElfUtils.h"
#include "kernel.h"
#include "fs/DirList.h"
#include "globals.h"
#include "kernel.h"
#include "module/ModuleDataFactory.h"
#include "module/ModuleDataPersistence.h"
extern "C" uint32_t textStart();
extern "C" void __fini();

View File

@ -1,9 +1,9 @@
#include "DynamicLinkingHelper.h"
#include "utils/logger.h"
#include <coreinit/dynload.h>
#include <cstdio>
#include <cstring>
#include <vector>
#include <coreinit/dynload.h>
#include "utils/logger.h"
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
if (data == nullptr) {
@ -13,7 +13,7 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
return nullptr;
}
dyn_linking_function_t *result = nullptr;
for (auto &function: data->functions) {
for (auto &function : data->functions) {
dyn_linking_function_t *curEntry = &function;
if (strlen(curEntry->functionName) == 0) {
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
@ -45,7 +45,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return nullptr;
}
dyn_linking_import_t *result = nullptr;
for (auto &import: data->imports) {
for (auto &import : data->imports) {
dyn_linking_import_t *curEntry = &import;
if (strlen(curEntry->importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {

View File

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

View File

@ -1,5 +1,6 @@
#pragma once
#include <string>
#include <wums.h>
class ExportData {

View File

@ -24,8 +24,7 @@ class FunctionSymbolData {
public:
FunctionSymbolData(const FunctionSymbolData &o2) = default;
FunctionSymbolData(const char *name, void *address, uint32_t size) :
name(name),
FunctionSymbolData(const char *name, void *address, uint32_t size) : name(name),
address(address),
size(size) {
}

View File

@ -17,10 +17,11 @@
#pragma once
#include <string>
#include <optional>
#include <utility>
#include "utils/logger.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
class ImportRPLInformation {

View File

@ -3,7 +3,7 @@
std::string ModuleData::toString() const {
std::string res = StringTools::strfmt("Entrypoint %08X, bss: %08X (%d), bss: %08X (%d)\n", getEntrypoint(), getBSSAddr(), getBSSSize(), getSBSSAddr(), getSBSSSize());
for (auto const &reloc: relocation_data_list) {
for (auto const &reloc : relocation_data_list) {
res += reloc->toString();
}
return res;

View File

@ -17,15 +17,15 @@
#pragma once
#include <string>
#include <vector>
#include <map>
#include <set>
#include "ExportData.h"
#include "FunctionSymbolData.h"
#include "HookData.h"
#include "RelocationData.h"
#include "SectionInfo.h"
#include "ExportData.h"
#include "HookData.h"
#include "FunctionSymbolData.h"
#include <map>
#include <set>
#include <string>
#include <vector>
struct FunctionSymbolDataComparator {
bool operator()(const std::shared_ptr<FunctionSymbolData> &lhs,
@ -164,6 +164,7 @@ public:
}
bool relocationsDone = false;
private:
std::vector<std::shared_ptr<RelocationData>> relocation_data_list;
std::vector<std::shared_ptr<ExportData>> export_data_list;

View File

@ -15,15 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <string>
#include <vector>
#include <map>
#include <coreinit/cache.h>
#include <wums.h>
#include "ModuleDataFactory.h"
#include "utils/utils.h"
#include "ElfUtils.h"
#include "FunctionSymbolData.h"
#include "utils/utils.h"
#include <coreinit/cache.h>
#include <map>
#include <string>
#include <vector>
#include <wums.h>
using namespace ELFIO;
@ -133,7 +133,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
}
auto relocationData = getImportRelocationData(reader, destinations);
for (auto const &reloc: relocationData) {
for (auto const &reloc : relocationData) {
moduleData->addRelocationData(reloc);
}
@ -144,7 +144,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wums_entry_t *exp = &entries[j];
DEBUG_FUNCTION_LINE("Saving export of type %08X, name %s, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, exp->type, exp->name, (void *) exp->address);
DEBUG_FUNCTION_LINE("Saving export of type %08X, name %s, target: %08X" /*,pluginData.getPluginInformation()->getName().c_str()*/, exp->type, exp->name, (void *) exp->address);
auto exportData = std::make_shared<ExportData>(exp->type, exp->name, exp->address);
moduleData->addExportData(exportData);
}
@ -158,7 +158,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
if (hooks != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wums_hook_t *hook = &hooks[j];
DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, hook->target);
DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %08X" /*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, hook->target);
auto hookData = std::make_shared<HookData>(hook->type, hook->target);
moduleData->addHookData(hookData);
}

View File

@ -17,12 +17,12 @@
#pragma once
#include <string>
#include <vector>
#include <map>
#include <wums.h>
#include "ModuleData.h"
#include "elfio/elfio.hpp"
#include <map>
#include <string>
#include <vector>
#include <wums.h>
class ModuleDataFactory {
public:

View File

@ -1,6 +1,6 @@
#include <coreinit/cache.h>
#include "ModuleDataPersistence.h"
#include "DynamicLinkingHelper.h"
#include <coreinit/cache.h>
bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformation, const std::shared_ptr<ModuleData> &module) {
int32_t module_count = moduleInformation->number_used_modules;
@ -15,7 +15,7 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
DEBUG_FUNCTION_LINE("Saving relocation data for module at %08X", module->getEntrypoint());
// Relocation
auto relocationData = module->getRelocationDataList();
for (auto const &reloc: relocationData) {
for (auto const &reloc : relocationData) {
if (!DynamicLinkingHelper::addRelocationEntry(&(moduleInformation->linking_data), module_data->linking_entries,
DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) {
DEBUG_FUNCTION_LINE("Failed to add relocation entry\n");
@ -24,9 +24,9 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
}
auto exportData = module->getExportDataList();
for (auto const &curExport: exportData) {
for (auto const &curExport : exportData) {
bool found = false;
for (auto &export_entry: module_data->export_entries) {
for (auto &export_entry : module_data->export_entries) {
if (export_entry.address == 0) {
export_entry.type = curExport->getType();
export_entry.name[0] = '\0';
@ -43,9 +43,9 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
}
auto hookData = module->getHookDataList();
for (auto const &curHook: hookData) {
for (auto const &curHook : hookData) {
bool found = false;
for (auto &hook_entry: module_data->hook_entries) {
for (auto &hook_entry : module_data->hook_entries) {
if (hook_entry.target == 0) {
hook_entry.type = curHook->getType();
hook_entry.target = (uint32_t) curHook->getTarget();
@ -67,7 +67,7 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
module_data->function_symbol_entries = ptr;
uint32_t sym_offset = 0;
for (auto &curFuncSym: module->getFunctionSymbolDataList()) {
for (auto &curFuncSym : module->getFunctionSymbolDataList()) {
if (moduleInformation->number_used_function_symbols >= FUNCTION_SYMBOL_LIST_LENGTH) {
DEBUG_FUNCTION_LINE("Function symbol list is full");
break;
@ -130,7 +130,7 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
moduleData->setSkipInitFini(module_data->skipInitFini);
moduleData->setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook);
for (auto &export_entrie: module_data->export_entries) {
for (auto &export_entrie : module_data->export_entries) {
export_data_t *export_entry = &export_entrie;
if (export_entry->address == 0) {
continue;
@ -139,7 +139,7 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
moduleData->addExportData(exportData);
}
for (auto &hook_entry: module_data->hook_entries) {
for (auto &hook_entry : module_data->hook_entries) {
if (hook_entry.target == 0) {
continue;
}
@ -147,7 +147,7 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
moduleData->addHookData(hookData);
}
for (auto &linking_entry: module_data->linking_entries) {
for (auto &linking_entry : module_data->linking_entries) {
if (linking_entry.destination == nullptr) {
break;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <wums.h>
#include "ModuleData.h"
#include <wums.h>
class ModuleDataPersistence {
public:

View File

@ -17,10 +17,10 @@
#pragma once
#include <string>
#include <memory>
#include <utility>
#include "ImportRPLInformation.h"
#include <memory>
#include <string>
#include <utility>
class RelocationData {

View File

@ -23,16 +23,14 @@
class SectionInfo {
public:
SectionInfo(std::string name, uint32_t address, uint32_t sectionSize) :
name(std::move(name)),
SectionInfo(std::string name, uint32_t address, uint32_t sectionSize) : name(std::move(name)),
address(address),
sectionSize(sectionSize) {
}
SectionInfo() = default;
SectionInfo(const SectionInfo &o2) :
name(o2.name),
SectionInfo(const SectionInfo &o2) : name(o2.name),
address(o2.address),
sectionSize(o2.sectionSize) {
}

View File

@ -23,17 +23,16 @@
*
* for WiiXplorer 2010
***************************************************************************/
#include <vector>
#include <string>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <string>
#include <strings.h>
#include <wut_types.h>
#include <stdio.h>
#include <utils/StringTools.h>
#include <vector>
#include <wchar.h>
#include <wut_types.h>
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {

View File

@ -26,8 +26,8 @@
#ifndef __STRING_TOOLS_H
#define __STRING_TOOLS_H
#include <vector>
#include <string>
#include <vector>
#include <wut_types.h>
class StringTools {
@ -62,4 +62,3 @@ public:
};
#endif /* __STRING_TOOLS_H */

View File

@ -1,8 +1,8 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;

View File

@ -1,7 +1,7 @@
#pragma once
#include <whb/log.h>
#include <string.h>
#include <whb/log.h>
#ifdef __cplusplus
extern "C" {
@ -14,12 +14,14 @@ extern "C" {
#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
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus
}
#endif

View File

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

View File

@ -9,26 +9,27 @@ extern "C" {
#define LIMIT(x, min, max) \
({ \
typeof( x ) _x = x; \
typeof( min ) _min = min; \
typeof( max ) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
})
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)
// 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);