├── source ├── config.h ├── globals.cpp ├── globals.h ├── utils │ ├── logger.c │ └── logger.h ├── main.cpp ├── patches.h ├── config.cpp └── patches.cpp ├── .gitignore ├── Dockerfile ├── .github └── workflows │ └── build.yml ├── .clang-format ├── README.md ├── Makefile └── LICENSE /source/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | void readStorage(); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | build/ 3 | *.elf 4 | *.wps 5 | .idea/ 6 | -------------------------------------------------------------------------------- /source/globals.cpp: -------------------------------------------------------------------------------- 1 | bool gActivateMK8Patches = true; 2 | bool gActivateSplatoonPatches = true; -------------------------------------------------------------------------------- /source/globals.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern bool gActivateMK8Patches; 4 | extern bool gActivateSplatoonPatches; -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM wiiuenv/devkitppc:20230621 2 | 3 | COPY --from=wiiuenv/libkernel:20220904 /artifacts $DEVKITPRO 4 | COPY --from=wiiuenv/libfunctionpatcher:20230108 /artifacts $DEVKITPRO 5 | COPY --from=wiiuenv/wiiupluginsystem:20230225 /artifacts $DEVKITPRO 6 | 7 | WORKDIR project 8 | -------------------------------------------------------------------------------- /source/utils/logger.c: -------------------------------------------------------------------------------- 1 | #ifdef DEBUG 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | uint32_t moduleLogInit = false; 8 | uint32_t cafeLogInit = false; 9 | uint32_t udpLogInit = false; 10 | #endif // DEBUG 11 | 12 | void initLogging() { 13 | #ifdef DEBUG 14 | if (!(moduleLogInit = WHBLogModuleInit())) { 15 | cafeLogInit = WHBLogCafeInit(); 16 | udpLogInit = WHBLogUdpInit(); 17 | } 18 | #endif // DEBUG 19 | } 20 | 21 | void deinitLogging() { 22 | #ifdef DEBUG 23 | if (moduleLogInit) { 24 | WHBLogModuleDeinit(); 25 | moduleLogInit = false; 26 | } 27 | if (cafeLogInit) { 28 | WHBLogCafeDeinit(); 29 | cafeLogInit = false; 30 | } 31 | if (udpLogInit) { 32 | WHBLogUdpDeinit(); 33 | udpLogInit = false; 34 | } 35 | #endif // DEBUG 36 | } -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Format and build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | clang-format: 7 | runs-on: ubuntu-22.04 8 | steps: 9 | - uses: actions/checkout@v3 10 | - name: clang-format 11 | run: | 12 | docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source 13 | check-build-with-logging: 14 | runs-on: ubuntu-22.04 15 | needs: clang-format 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: build binary with logging 19 | run: | 20 | docker build . -t builder 21 | docker run --rm -v ${PWD}:/project builder make DEBUG=VERBOSE 22 | docker run --rm -v ${PWD}:/project builder make clean 23 | docker run --rm -v ${PWD}:/project builder make DEBUG=1 24 | build-binary: 25 | runs-on: ubuntu-22.04 26 | needs: clang-format 27 | steps: 28 | - uses: actions/checkout@v3 29 | - name: build binary 30 | run: | 31 | docker build . -t builder 32 | docker run --rm -v ${PWD}:/project builder make 33 | - uses: actions/upload-artifact@master 34 | with: 35 | name: binary 36 | path: "*.wps" -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # Generated from CLion C/C++ Code Style settings 2 | BasedOnStyle: LLVM 3 | AccessModifierOffset: -4 4 | AlignAfterOpenBracket: Align 5 | AlignConsecutiveAssignments: Consecutive 6 | AlignConsecutiveMacros: AcrossEmptyLinesAndComments 7 | AlignOperands: Align 8 | AllowAllArgumentsOnNextLine: false 9 | AllowAllConstructorInitializersOnNextLine: false 10 | AllowAllParametersOfDeclarationOnNextLine: false 11 | AllowShortBlocksOnASingleLine: Always 12 | AllowShortCaseLabelsOnASingleLine: false 13 | AllowShortFunctionsOnASingleLine: All 14 | AllowShortIfStatementsOnASingleLine: Always 15 | AllowShortLambdasOnASingleLine: All 16 | AllowShortLoopsOnASingleLine: true 17 | AlwaysBreakAfterReturnType: None 18 | AlwaysBreakTemplateDeclarations: Yes 19 | BreakBeforeBraces: Custom 20 | BraceWrapping: 21 | AfterCaseLabel: false 22 | AfterClass: false 23 | AfterControlStatement: Never 24 | AfterEnum: false 25 | AfterFunction: false 26 | AfterNamespace: false 27 | AfterUnion: false 28 | BeforeCatch: false 29 | BeforeElse: false 30 | IndentBraces: false 31 | SplitEmptyFunction: false 32 | SplitEmptyRecord: true 33 | BreakBeforeBinaryOperators: None 34 | BreakBeforeTernaryOperators: true 35 | BreakConstructorInitializers: BeforeColon 36 | BreakInheritanceList: BeforeColon 37 | ColumnLimit: 0 38 | CompactNamespaces: false 39 | ContinuationIndentWidth: 8 40 | IndentCaseLabels: true 41 | IndentPPDirectives: None 42 | IndentWidth: 4 43 | KeepEmptyLinesAtTheStartOfBlocks: true 44 | MaxEmptyLinesToKeep: 2 45 | NamespaceIndentation: All 46 | ObjCSpaceAfterProperty: false 47 | ObjCSpaceBeforeProtocolList: true 48 | PointerAlignment: Right 49 | ReflowComments: false 50 | SpaceAfterCStyleCast: true 51 | SpaceAfterLogicalNot: false 52 | SpaceAfterTemplateKeyword: false 53 | SpaceBeforeAssignmentOperators: true 54 | SpaceBeforeCpp11BracedList: false 55 | SpaceBeforeCtorInitializerColon: true 56 | SpaceBeforeInheritanceColon: true 57 | SpaceBeforeParens: ControlStatements 58 | SpaceBeforeRangeBasedForLoopColon: true 59 | SpaceInEmptyParentheses: false 60 | SpacesBeforeTrailingComments: 1 61 | SpacesInAngles: false 62 | SpacesInCStyleCastParentheses: false 63 | SpacesInContainerLiterals: false 64 | SpacesInParentheses: false 65 | SpacesInSquareBrackets: false 66 | TabWidth: 4 67 | UseTab: Never 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rce_patches 2 | This Aroma plugin provides fixes for games that have security and crashing issues that can be triggered in a multiplayer 3 | game. These patches are known to work on Nintendo Network as well as [Pretendo Network](https://pretendo.network). 4 | Anyone playing multiplayer in affected games should have these patches installed. 5 | 6 | The following fixes are provided: 7 | - Mario Kart 8 (All regions, v64) 8 | - [ENLBufferPwn](https://github.com/PabloMK7/ENLBufferPwn) fix 9 | - Identification token parsing RCE fix (exploit found by Kinnay) 10 | - ENL nullptr deref fix + OOB read 11 | 12 | - Splatoon (All regions, v272) 13 | - [ENLBufferPwn](https://github.com/PabloMK7/ENLBufferPwn) fix 14 | - ENL nullptr deref fix + OOB read 15 | 16 | ## Usage 17 | Go to the [latest release](https://github.com/PretendoNetwork/rce_patches/releases/latest) and download the `.wps` file. 18 | On your Wii U's SD card, place that file in `wiiu/environments/aroma/plugins`. Then reboot your console. 19 | 20 | You can press L+Down+Minus on Aroma to view a config menu - if the installation worked, you should see "rce_patches" 21 | listed in that menu. You're now safe to play online. 22 | 23 | If you need help with the installation, you can ask in the [Pretendo discord](https://invite.gg/pretendo), 24 | [Nintendo Homebrew](https://discord.gg/C29hYvh), or advanced users in the 25 | [Aroma discord](https://discord.com/invite/bZ2rep2). 26 | 27 | ## Building 28 | 29 | ### Build options 30 | Building via `make` only logs errors (via OSReport). To enable logging via the [LoggingModule](https://github.com/wiiu-env/LoggingModule) set `DEBUG` to `1` or `VERBOSE`. 31 | 32 | `make` Logs errors only (via OSReport). 33 | `make DEBUG=1` Enables information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule). 34 | `make DEBUG=VERBOSE` Enables verbose information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule). 35 | 36 | If the [LoggingModule](https://github.com/wiiu-env/LoggingModule) is not present, it'll fallback to UDP (Port 4405) and [CafeOS](https://github.com/wiiu-env/USBSerialLoggingModule) logging. 37 | 38 | ### Building using Docker 39 | 40 | It's possible to use a docker image for building. This way you don't need anything installed on your host system. 41 | 42 | ``` 43 | # Build docker image (only needed once) 44 | docker build . -t rcepatches-builder 45 | 46 | # make 47 | docker run -it --rm -v ${PWD}:/project rcepatches-builder make 48 | 49 | # make clean 50 | docker run -it --rm -v ${PWD}:/project rcepatches-builder make clean 51 | ``` 52 | 53 | ### Formatting code using Docker 54 | 55 | `docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i` 56 | 57 | ## Licensing 58 | To ensure everyone has access to every fix, these patches are under GPLv2. Unless you're a programmer at Nintendo, then 59 | you can have the patches for free ;) -------------------------------------------------------------------------------- /source/main.cpp: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include "globals.h" 3 | #include "patches.h" 4 | #include "utils/logger.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | WUPS_PLUGIN_NAME("rce_patches"); 11 | WUPS_PLUGIN_DESCRIPTION("Patches security issues in WiiU games that could be triggered remotely"); 12 | WUPS_PLUGIN_VERSION("v1.1-" DISTRO); 13 | WUPS_PLUGIN_AUTHOR("Rambo6Glaz, Maschell"); 14 | WUPS_PLUGIN_LICENSE(""); 15 | WUPS_USE_STORAGE("rce_patches"); // Unique id for the storage api 16 | 17 | std::vector mk8Patches; 18 | std::vector splatoonPatches; 19 | 20 | void RemovePatches(std::vector &patchHandles) { 21 | for (auto &patch : patchHandles) { 22 | if (FunctionPatcher_RemoveFunctionPatch(patch.handle) != FUNCTION_PATCHER_RESULT_SUCCESS) { 23 | DEBUG_FUNCTION_LINE_WARN("Failed to remove function patch %08X", patch.handle); 24 | } 25 | } 26 | patchHandles.clear(); 27 | } 28 | 29 | INITIALIZE_PLUGIN() { 30 | DEBUG_FUNCTION_LINE("Patch functions"); 31 | if (FunctionPatcher_InitLibrary() != FUNCTION_PATCHER_RESULT_SUCCESS) { 32 | OSFatal("rce_patches: FunctionPatcher_InitLibrary failed"); 33 | } 34 | readStorage(); 35 | } 36 | 37 | DEINITIALIZE_PLUGIN() { 38 | RemovePatches(mk8Patches); 39 | RemovePatches(splatoonPatches); 40 | } 41 | 42 | ON_APPLICATION_START() { 43 | initLogging(); 44 | 45 | if (!gActivateMK8Patches && !mk8Patches.empty()) { 46 | DEBUG_FUNCTION_LINE("Remove MK8 patches"); 47 | RemovePatches(mk8Patches); 48 | } else if (gActivateMK8Patches && mk8Patches.empty()) { 49 | DEBUG_FUNCTION_LINE("Add MK8 patches"); 50 | if (!MARIO_KART_8_AddPatches(mk8Patches)) { 51 | DEBUG_FUNCTION_LINE_ERR("Failed to add Mario Kart 8 patches"); 52 | RemovePatches(mk8Patches); 53 | } 54 | } 55 | 56 | if (!gActivateSplatoonPatches && !splatoonPatches.empty()) { 57 | DEBUG_FUNCTION_LINE("Remove Splatoon patches"); 58 | RemovePatches(splatoonPatches); 59 | } else if (gActivateSplatoonPatches && splatoonPatches.empty()) { 60 | DEBUG_FUNCTION_LINE("Add Splatoon patches"); 61 | if (!SPLATOON_AddPatches(splatoonPatches)) { 62 | DEBUG_FUNCTION_LINE_ERR("Failed to add Splatoon patches"); 63 | RemovePatches(splatoonPatches); 64 | } 65 | } 66 | 67 | for (auto &patch : mk8Patches) { 68 | bool isPatched = false; 69 | if (FunctionPatcher_IsFunctionPatched(patch.handle, &isPatched) == FUNCTION_PATCHER_RESULT_SUCCESS && isPatched) { 70 | DEBUG_FUNCTION_LINE("MK8: Function %s (handle: %08X) has been patched", patch.name.c_str(), patch.handle); 71 | } else { 72 | DEBUG_FUNCTION_LINE_ERR("MK8: Function %s (handle: %08X) has NOT been patched", patch.name.c_str(), patch.handle); 73 | } 74 | } 75 | for (auto &patch : splatoonPatches) { 76 | bool isPatched = false; 77 | if (FunctionPatcher_IsFunctionPatched(patch.handle, &isPatched) == FUNCTION_PATCHER_RESULT_SUCCESS && isPatched) { 78 | DEBUG_FUNCTION_LINE("Splatoon: Function %s (handle: %08X) has been patched", patch.name.c_str(), patch.handle); 79 | } else { 80 | DEBUG_FUNCTION_LINE_ERR("Splatoon: Function %s (handle: %08X) has NOT been patched", patch.name.c_str(), patch.handle); 81 | } 82 | } 83 | } 84 | 85 | ON_APPLICATION_ENDS() { 86 | deinitLogging(); 87 | } -------------------------------------------------------------------------------- /source/utils/logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define LOG_APP_TYPE "P" 12 | #define LOG_APP_NAME "rce_patches" 13 | 14 | #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) 15 | #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) 16 | 17 | #define LOG(LOG_FUNC, FMT, ARGS...) LOG_EX_DEFAULT(LOG_FUNC, "", "", FMT, ##ARGS) 18 | 19 | #define LOG_EX_DEFAULT(LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) LOG_EX(__FILENAME__, __FUNCTION__, __LINE__, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ##ARGS) 20 | 21 | #define LOG_EX(FILENAME, FUNCTION, LINE, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) \ 22 | do { \ 23 | LOG_FUNC("[(%s)%18s][%23s]%30s@L%04d: " LOG_LEVEL "" FMT "" LINE_END, LOG_APP_TYPE, LOG_APP_NAME, FILENAME, FUNCTION, LINE, ##ARGS); \ 24 | } while (0) 25 | 26 | #ifdef DEBUG 27 | 28 | #ifdef VERBOSE_DEBUG 29 | #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS) 30 | #define DEBUG_FUNCTION_LINE_VERBOSE_EX(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "", "", FMT, ##ARGS); 31 | #else 32 | #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) 33 | #define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0) 34 | #endif 35 | 36 | #define DEBUG_FUNCTION_LINE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS) 37 | 38 | #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG(WHBLogWritef, FMT, ##ARGS) 39 | 40 | #define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS) 41 | #define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##WARN ## ", "", FMT, ##ARGS) 42 | #define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##INFO ## ", "", FMT, ##ARGS) 43 | 44 | #define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS); 45 | 46 | #else 47 | 48 | #define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0) 49 | 50 | #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) 51 | 52 | #define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) 53 | 54 | #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) 55 | 56 | #define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS) 57 | #define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##WARN ## ", "\n", FMT, ##ARGS) 58 | #define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##INFO ## ", "\n", FMT, ##ARGS) 59 | 60 | #define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS); 61 | 62 | #endif 63 | 64 | void initLogging(); 65 | 66 | void deinitLogging(); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /source/patches.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | struct sead_String { 16 | char *mBuffer; 17 | uint32_t vtable; 18 | }; 19 | WUT_CHECK_OFFSET(sead_String, 0x00, mBuffer); 20 | WUT_CHECK_OFFSET(sead_String, 0x04, vtable); 21 | 22 | struct __attribute__((__packed__)) enl_RecordHeader { 23 | uint8_t mContentTransporterID; 24 | uint16_t mContentLength; 25 | }; 26 | WUT_CHECK_OFFSET(enl_RecordHeader, 0x00, mContentTransporterID); 27 | WUT_CHECK_OFFSET(enl_RecordHeader, 0x01, mContentLength); 28 | 29 | struct enl_Buffer { 30 | uint8_t *mData; 31 | size_t mCapacity; 32 | size_t mSize; 33 | bool isAllocated; 34 | }; 35 | WUT_CHECK_OFFSET(enl_Buffer, 0x00, mData); 36 | WUT_CHECK_OFFSET(enl_Buffer, 0x04, mCapacity); 37 | WUT_CHECK_OFFSET(enl_Buffer, 0x08, mSize); 38 | WUT_CHECK_OFFSET(enl_Buffer, 0x0C, isAllocated); 39 | 40 | struct enl_ContentTransporter { 41 | struct ContentTransporterVtbl { 42 | int a; 43 | int b; 44 | int f08; 45 | void (*init)(enl_ContentTransporter *_this); 46 | int _f10; 47 | void *(*getSendBuffer)(enl_ContentTransporter *_this); 48 | int _f18; 49 | int (*getSendBufferSize)(enl_ContentTransporter *_this); 50 | int _f20; 51 | bool (*isNeedSend)(enl_ContentTransporter *_thiss); 52 | int _f28; 53 | unsigned char (*getContentID)(enl_ContentTransporter *_this); 54 | // ... 55 | }; 56 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x00, a); 57 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x04, b); 58 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x08, f08); 59 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x0C, init); 60 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x10, _f10); 61 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x14, getSendBuffer); 62 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x18, _f18); 63 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x1C, getSendBufferSize); 64 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x20, _f20); 65 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x24, isNeedSend); 66 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x28, _f28); 67 | WUT_CHECK_OFFSET(ContentTransporterVtbl, 0x2C, getContentID); 68 | ContentTransporterVtbl *vtable; 69 | }; 70 | WUT_CHECK_OFFSET(enl_ContentTransporter, 0x00, vtable); 71 | 72 | 73 | class PatchData { 74 | public: 75 | PatchData(std::string name, PatchedFunctionHandle handle) : name(std::move(name)), handle(handle) { 76 | } 77 | 78 | std::string name; 79 | PatchedFunctionHandle handle; 80 | }; 81 | 82 | // ========================================================================================== 83 | 84 | #define MARIO_KART_8_TID_J 0x000500001010EB00 85 | #define MARIO_KART_8_TID_U 0x000500001010EC00 86 | #define MARIO_KART_8_TID_E 0x000500001010ED00 87 | 88 | #define MARIO_KART_8_TID MARIO_KART_8_TID_J, MARIO_KART_8_TID_U, MARIO_KART_8_TID_E 89 | 90 | bool MARIO_KART_8_AddPatches(std::vector &functionPatches); 91 | 92 | // ========================================================================================== 93 | 94 | #define SPLATOON_TID_J 0x0005000010162B00 95 | #define SPLATOON_TID_U 0x0005000010176900 96 | #define SPLATOON_TID_E 0x0005000010176A00 97 | 98 | #define SPLATOON_TID SPLATOON_TID_J, SPLATOON_TID_U, SPLATOON_TID_E 99 | #define SPLATOON_PATCHES PATCH_ENL_BUFFER_RCE 100 | 101 | bool SPLATOON_AddPatches(std::vector &functionPatches); 102 | 103 | // ========================================================================================== 104 | -------------------------------------------------------------------------------- /source/config.cpp: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include "globals.h" 3 | #include "patches.h" 4 | #include "utils/logger.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define MK8PATCHES_CONFIG_ID "mk8patches" 12 | #define SPLATOONPATCHES_CONFIG_ID "splatoonpatches" 13 | 14 | #define LOAD_BOOL_FROM_CONFIG(config_name, __variable__) \ 15 | if ((storageRes = WUPS_GetBool(nullptr, config_name, &__variable__)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \ 16 | if (WUPS_StoreBool(nullptr, config_name, __variable__) != WUPS_STORAGE_ERROR_SUCCESS) { \ 17 | DEBUG_FUNCTION_LINE_WARN("Failed to store bool"); \ 18 | } \ 19 | } else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \ 20 | DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \ 21 | } \ 22 | while (0) 23 | 24 | 25 | #define PROCESS_BOOL_ITEM_CHANGED(__config__name, __variable__) \ 26 | if (std::string_view(item->configId) == __config__name) { \ 27 | DEBUG_FUNCTION_LINE_VERBOSE("New value in %s: %d", __config__name, newValue); \ 28 | __variable__ = newValue; \ 29 | WUPS_StoreInt(nullptr, __config__name, __variable__); \ 30 | return; \ 31 | } \ 32 | while (0) 33 | 34 | bool prevActivateMK8Patches = true; 35 | bool prevActivateSplatoonPatches = true; 36 | 37 | void readStorage() { 38 | // Open storage to read values 39 | WUPSStorageError storageRes = WUPS_OpenStorage(); 40 | if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { 41 | DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); 42 | } else { 43 | LOAD_BOOL_FROM_CONFIG(MK8PATCHES_CONFIG_ID, gActivateMK8Patches); 44 | LOAD_BOOL_FROM_CONFIG(SPLATOONPATCHES_CONFIG_ID, gActivateSplatoonPatches); 45 | 46 | prevActivateMK8Patches = gActivateMK8Patches; 47 | prevActivateSplatoonPatches = gActivateSplatoonPatches; 48 | 49 | // Close storage 50 | if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { 51 | DEBUG_FUNCTION_LINE("Failed to close storage"); 52 | } 53 | } 54 | } 55 | 56 | void boolItemChanged(ConfigItemBoolean *item, bool newValue) { 57 | PROCESS_BOOL_ITEM_CHANGED(MK8PATCHES_CONFIG_ID, gActivateMK8Patches); 58 | PROCESS_BOOL_ITEM_CHANGED(SPLATOONPATCHES_CONFIG_ID, gActivateSplatoonPatches); 59 | } 60 | 61 | WUPS_GET_CONFIG() { 62 | // We open the storage, so we can persist the configuration the user did. 63 | if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) { 64 | DEBUG_FUNCTION_LINE("Failed to open storage"); 65 | return 0; 66 | } 67 | 68 | WUPSConfigHandle config; 69 | WUPSConfig_CreateHandled(&config, "RCE Patches"); 70 | 71 | WUPSConfigCategoryHandle cat; 72 | WUPSConfig_AddCategoryByNameHandled(config, "Games", &cat); 73 | 74 | WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, MK8PATCHES_CONFIG_ID, "Patch exploits in Mario Kart 8", gActivateMK8Patches, &boolItemChanged); 75 | WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, SPLATOONPATCHES_CONFIG_ID, "Patch exploits in Splatoon", gActivateSplatoonPatches, &boolItemChanged); 76 | 77 | return config; 78 | } 79 | 80 | WUPS_CONFIG_CLOSED() { 81 | // Save all changes 82 | if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { 83 | DEBUG_FUNCTION_LINE("Failed to close storage"); 84 | } 85 | 86 | if (prevActivateMK8Patches != gActivateMK8Patches) { 87 | if (OSGetTitleID() == MARIO_KART_8_TID_J || 88 | OSGetTitleID() == MARIO_KART_8_TID_E || 89 | OSGetTitleID() == MARIO_KART_8_TID_U) { 90 | _SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr); 91 | } 92 | } 93 | 94 | if (prevActivateSplatoonPatches != gActivateSplatoonPatches) { 95 | if (OSGetTitleID() == SPLATOON_TID_J || 96 | OSGetTitleID() == SPLATOON_TID_E || 97 | OSGetTitleID() == SPLATOON_TID_U) { 98 | _SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr); 99 | } 100 | } 101 | 102 | prevActivateMK8Patches = gActivateMK8Patches; 103 | prevActivateSplatoonPatches = gActivateSplatoonPatches; 104 | } 105 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #------------------------------------------------------------------------------- 4 | 5 | DISTRO ?= git 6 | 7 | ifeq ($(strip $(DEVKITPRO)),) 8 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 9 | endif 10 | 11 | TOPDIR ?= $(CURDIR) 12 | 13 | include $(DEVKITPRO)/wups/share/wups_rules 14 | 15 | WUT_ROOT := $(DEVKITPRO)/wut 16 | WUMS_ROOT := $(DEVKITPRO)/wums 17 | #------------------------------------------------------------------------------- 18 | # TARGET is the name of the output 19 | # BUILD is the directory where object files & intermediate files will be placed 20 | # SOURCES is a list of directories containing source code 21 | # DATA is a list of directories containing data files 22 | # INCLUDES is a list of directories containing header files 23 | #------------------------------------------------------------------------------- 24 | TARGET := rce_patches 25 | BUILD := build 26 | SOURCES := source source/utils 27 | DATA := data 28 | INCLUDES := source 29 | 30 | #------------------------------------------------------------------------------- 31 | # options for code generation 32 | #------------------------------------------------------------------------------- 33 | CFLAGS := -Wall -O2 -ffunction-sections \ 34 | $(MACHDEP) 35 | 36 | CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ -DDISTRO=\"$(DISTRO)\" 37 | 38 | CXXFLAGS := $(CFLAGS) -std=c++20 39 | 40 | ASFLAGS := $(ARCH) 41 | LDFLAGS = $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) $(WUPSSPECS) 42 | 43 | ifeq ($(DEBUG),1) 44 | CXXFLAGS += -DDEBUG -g 45 | CFLAGS += -DDEBUG -g 46 | endif 47 | 48 | ifeq ($(DEBUG),VERBOSE) 49 | CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g 50 | CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g 51 | endif 52 | 53 | LIBS := -lfunctionpatcher -lkernel -lwups -lwut 54 | 55 | #------------------------------------------------------------------------------- 56 | # list of directories containing libraries, this must be the top level 57 | # containing include and lib 58 | #------------------------------------------------------------------------------- 59 | LIBDIRS := $(PORTLIBS) $(WUMS_ROOT) $(WUPS_ROOT) $(WUT_ROOT) 60 | 61 | #------------------------------------------------------------------------------- 62 | # no real need to edit anything past this point unless you need to add additional 63 | # rules for different file extensions 64 | #------------------------------------------------------------------------------- 65 | ifneq ($(BUILD),$(notdir $(CURDIR))) 66 | #------------------------------------------------------------------------------- 67 | 68 | export OUTPUT := $(CURDIR)/$(TARGET) 69 | export TOPDIR := $(CURDIR) 70 | 71 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 72 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 73 | 74 | export DEPSDIR := $(CURDIR)/$(BUILD) 75 | 76 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 77 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 78 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 79 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 80 | 81 | #------------------------------------------------------------------------------- 82 | # use CXX for linking C++ projects, CC for standard C 83 | #------------------------------------------------------------------------------- 84 | ifeq ($(strip $(CPPFILES)),) 85 | #------------------------------------------------------------------------------- 86 | export LD := $(CC) 87 | #------------------------------------------------------------------------------- 88 | else 89 | #------------------------------------------------------------------------------- 90 | export LD := $(CXX) 91 | #------------------------------------------------------------------------------- 92 | endif 93 | #------------------------------------------------------------------------------- 94 | 95 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 96 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 97 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 98 | export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) 99 | 100 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 101 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 102 | -I$(CURDIR)/$(BUILD) 103 | 104 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 105 | 106 | .PHONY: $(BUILD) clean all 107 | 108 | #------------------------------------------------------------------------------- 109 | all: $(BUILD) 110 | 111 | $(BUILD): 112 | @$(shell [ ! -d $(BUILD) ] && mkdir -p $(BUILD)) 113 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 114 | 115 | #------------------------------------------------------------------------------- 116 | clean: 117 | @echo clean ... 118 | @rm -fr $(BUILD) $(TARGET).wps $(TARGET).elf 119 | 120 | #------------------------------------------------------------------------------- 121 | else 122 | .PHONY: all 123 | 124 | DEPENDS := $(OFILES:.o=.d) 125 | 126 | #------------------------------------------------------------------------------- 127 | # main targets 128 | #------------------------------------------------------------------------------- 129 | all : $(OUTPUT).wps 130 | 131 | $(OUTPUT).wps : $(OUTPUT).elf 132 | $(OUTPUT).elf : $(OFILES) 133 | 134 | $(OFILES_SRC) : $(HFILES_BIN) 135 | 136 | #------------------------------------------------------------------------------- 137 | # you need a rule like this for each extension you use as binary data 138 | #------------------------------------------------------------------------------- 139 | %.bin.o %_bin.h : %.bin 140 | #------------------------------------------------------------------------------- 141 | @echo $(notdir $<) 142 | @$(bin2o) 143 | 144 | -include $(DEPENDS) 145 | 146 | #------------------------------------------------------------------------------- 147 | endif 148 | #------------------------------------------------------------------------------- 149 | -------------------------------------------------------------------------------- /source/patches.cpp: -------------------------------------------------------------------------------- 1 | #include "patches.h" 2 | #include "utils/logger.h" 3 | #include 4 | #include 5 | 6 | // ========================================================================================== 7 | DECL_FUNCTION(bool, enl_ParseIdentificationToken, void *identifiationInfo, sead_String *identificationToken) { 8 | // Fix for RCE (stack overflow if identification buffer was bigger than 16) 9 | if (strnlen(identificationToken->mBuffer, 16) == 16) { 10 | DEBUG_FUNCTION_LINE_INFO("Avoided bufferoverlow in enl_ParseIdentificationToken!"); 11 | identificationToken->mBuffer[15] = '\0'; 12 | return real_enl_ParseIdentificationToken(identifiationInfo, identificationToken); 13 | } 14 | 15 | return real_enl_ParseIdentificationToken(identifiationInfo, identificationToken); 16 | } 17 | 18 | DECL_FUNCTION(enl_ContentTransporter *, enl_TransportManager_getContentTransporter, void *_this, unsigned char &id) { 19 | return real_enl_TransportManager_getContentTransporter(_this, id); 20 | } 21 | 22 | DECL_FUNCTION(void, enl_TransportManager_updateReceiveBuffer_, void *_this, signed char const &bufferId, uint8_t *data, uint32_t size) { 23 | 24 | static enl_RecordHeader s_TerminationRecord = {.mContentTransporterID = 0xff, .mContentLength = 0}; 25 | 26 | // Check for end record in the data, if there is not, drop packet 27 | bool hasEndRecord = false; 28 | 29 | // Loop through all records and check if there's a bad record (size mismatch) until out of bounds or end record 30 | uint8_t *pData = data; 31 | while (pData < (data + size)) { 32 | enl_RecordHeader *record = (enl_RecordHeader *) pData; 33 | if (record->mContentLength == 0 && record->mContentTransporterID == 0xff) { 34 | hasEndRecord = true; 35 | break; 36 | } 37 | 38 | enl_ContentTransporter *contentTransp = real_enl_TransportManager_getContentTransporter(_this, record->mContentTransporterID); 39 | // Actual fix for the ENL nullptr deref crash (lmao) 40 | if (!contentTransp) { 41 | DEBUG_FUNCTION_LINE_INFO("Avoided ENL nullptr deref crash in enl_TransportManager_updateReceiveBuffer_!"); 42 | return real_enl_TransportManager_updateReceiveBuffer_(_this, bufferId, (uint8_t *) &s_TerminationRecord, sizeof(enl_RecordHeader)); 43 | } 44 | 45 | if (record->mContentLength > 0x440) { 46 | DEBUG_FUNCTION_LINE_INFO("record->mContentLength was over 0x440 in enl_TransportManager_updateReceiveBuffer_!"); 47 | return real_enl_TransportManager_updateReceiveBuffer_(_this, bufferId, (uint8_t *) &s_TerminationRecord, sizeof(enl_RecordHeader)); 48 | } 49 | 50 | pData += sizeof(enl_RecordHeader); 51 | pData += record->mContentLength; 52 | } 53 | 54 | if (!hasEndRecord) { 55 | return real_enl_TransportManager_updateReceiveBuffer_(_this, bufferId, (uint8_t *) &s_TerminationRecord, sizeof(enl_RecordHeader)); 56 | } 57 | 58 | return real_enl_TransportManager_updateReceiveBuffer_(_this, bufferId, data, size); 59 | } 60 | 61 | DECL_FUNCTION(void, enl_Buffer_set, enl_Buffer *_this, uint8_t const *data, size_t size) { 62 | // Fix for the RCE 63 | if (!_this->mData || !size || size > _this->mCapacity) { 64 | DEBUG_FUNCTION_LINE_INFO("Avoided overflow in enl_Buffer_set!"); 65 | return; 66 | } 67 | 68 | memcpy(_this->mData, data, size); 69 | _this->mSize = size; 70 | } 71 | // ========================================================================================== 72 | 73 | bool MARIO_KART_8_AddPatches(std::vector &functionPatches) { 74 | uint64_t titleIds[] = {MARIO_KART_8_TID}; 75 | function_replacement_data_t repl = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( 76 | enl_ParseIdentificationToken, 77 | titleIds, sizeof(titleIds) / sizeof(titleIds[0]), 78 | "Turbo.rpx", 79 | 0x8E3930, // Address of 'enl::PiaUtil::ParseIdentificationToken' 80 | 64, 64); 81 | PatchedFunctionHandle handle = 0; 82 | if (FunctionPatcher_AddFunctionPatch(&repl, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { 83 | DEBUG_FUNCTION_LINE_ERR("Failed to add \"enl_ParseIdentificationToken\" patch"); 84 | return false; 85 | } 86 | functionPatches.emplace_back("enl::PiaUtil::ParseIdentificationToken", handle); 87 | 88 | function_replacement_data_t repl1 = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( 89 | enl_TransportManager_getContentTransporter, 90 | titleIds, sizeof(titleIds) / sizeof(titleIds[0]), 91 | "Turbo.rpx", 92 | 0x8D7678, // Address of 'enl::TransportManager::getContentTransporter' 93 | 64, 64); 94 | if (FunctionPatcher_AddFunctionPatch(&repl1, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { 95 | DEBUG_FUNCTION_LINE_ERR("Failed to add \"enl_TransportManager_getContentTransporter\" patch"); 96 | return false; 97 | } 98 | functionPatches.emplace_back("enl::TransportManager::getContentTransporter", handle); 99 | 100 | 101 | function_replacement_data_t repl2 = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( 102 | enl_TransportManager_updateReceiveBuffer_, 103 | titleIds, sizeof(titleIds) / sizeof(titleIds[0]), 104 | "Turbo.rpx", 105 | 0x8D772C, // Address of 'enl::TransportManager::updateReceiveBuffer_' 106 | 64, 64); 107 | if (FunctionPatcher_AddFunctionPatch(&repl2, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { 108 | DEBUG_FUNCTION_LINE_ERR("Failed to add \"enl_TransportManager_updateReceiveBuffer_\" patch"); 109 | return false; 110 | } 111 | functionPatches.emplace_back("enl::TransportManager::updateReceiveBuffer_", handle); 112 | 113 | function_replacement_data_t repl3 = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( 114 | enl_Buffer_set, 115 | titleIds, sizeof(titleIds) / sizeof(titleIds[0]), 116 | "Turbo.rpx", 117 | 0x8CF228, 118 | 64, 64); 119 | if (FunctionPatcher_AddFunctionPatch(&repl3, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { 120 | DEBUG_FUNCTION_LINE_ERR("Failed to add \"enl_Buffer_set\" patch"); 121 | return false; 122 | } 123 | functionPatches.emplace_back("enl:Buffer::set", handle); 124 | 125 | return true; 126 | } 127 | 128 | // ========================================================================================== 129 | 130 | bool SPLATOON_AddPatches(std::vector &functionPatches) { 131 | uint64_t titleIds[] = {SPLATOON_TID}; 132 | function_replacement_data_t repl = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( 133 | enl_TransportManager_getContentTransporter, 134 | titleIds, sizeof(titleIds) / sizeof(titleIds[0]), 135 | "Gambit.rpx", 136 | 0xB4108C, // Address of 'enl::TransportManager::getContentTransporter' 137 | 272, 272); 138 | PatchedFunctionHandle handle; 139 | if (FunctionPatcher_AddFunctionPatch(&repl, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { 140 | DEBUG_FUNCTION_LINE_ERR("Failed to add \"enl_TransportManager_getContentTransporter\" patch"); 141 | return false; 142 | } 143 | functionPatches.emplace_back("enl::TransportManager::getContentTransporter", handle); 144 | 145 | function_replacement_data_t repl1 = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( 146 | enl_TransportManager_updateReceiveBuffer_, 147 | titleIds, sizeof(titleIds) / sizeof(titleIds[0]), 148 | "Gambit.rpx", 149 | 0xB41140, // Address of 'enl::TransportManager::updateReceiveBuffer_' 150 | 272, 272); 151 | if (FunctionPatcher_AddFunctionPatch(&repl1, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { 152 | DEBUG_FUNCTION_LINE_ERR("Failed to add \"enl_TransportManager_updateReceiveBuffer_\" patch"); 153 | return false; 154 | } 155 | functionPatches.emplace_back("enl::TransportManager::updateReceiveBuffer_", handle); 156 | 157 | function_replacement_data_t repl2 = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( 158 | enl_Buffer_set, 159 | titleIds, sizeof(titleIds) / sizeof(titleIds[0]), 160 | "Gambit.rpx", 161 | 0xB4D178, // Address of 'enl:Buffer::set' 162 | 272, 272); 163 | if (FunctionPatcher_AddFunctionPatch(&repl2, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { 164 | DEBUG_FUNCTION_LINE_ERR("Failed to add \"enl_Buffer_set\" patch"); 165 | return false; 166 | } 167 | functionPatches.emplace_back("enl:Buffer::set", handle); 168 | return true; 169 | } 170 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------