Use WUMS 0.3.2 and latest libfunctionpatcher

This commit is contained in:
Maschell 2023-01-06 20:35:40 +01:00
parent 15c0971aae
commit 4803d90ddf
10 changed files with 40 additions and 11 deletions

View File

@ -1,6 +1,6 @@
FROM wiiuenv/devkitppc:20220917
FROM wiiuenv/devkitppc:20221228
COPY --from=wiiuenv/libfunctionpatcher:20220904 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiumodulesystem:20221005 /artifacts $DEVKITPRO
COPY --from=wiiuenv/libfunctionpatcher:20230106 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiumodulesystem:20230106 /artifacts $DEVKITPRO
WORKDIR project

View File

@ -41,7 +41,7 @@ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
CXXFLAGS := $(CFLAGS) -std=c++20
ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libfunctionpatcher.ld $(WUMSSPECS)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -Tfunctionpatcher.ld $(WUMSSPECS)
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
@ -79,6 +79,7 @@ export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
DEFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.def)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#-------------------------------------------------------------------------------
@ -96,7 +97,7 @@ endif
#-------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES_SRC := $(DEFFILES:.def=.o) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
@ -145,6 +146,11 @@ $(OFILES_SRC) : $(HFILES_BIN)
#-------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
%.o: %.def
$(SILENTMSG) $(notdir $<)
$(SILENTCMD)rplimportgen $< $*.s $*.ld $(ERROR_FILTER)
$(SILENTCMD)$(CC) -x assembler-with-cpp $(ASFLAGS) -c $*.s -o $@ $(ERROR_FILTER)
-include $(DEPENDS)

View File

@ -6,7 +6,8 @@
void initApplicationEndsHook() {
DEBUG_FUNCTION_LINE("Patch ApplicationEndsHook functions");
for (uint32_t i = 0; i < applicationendshook_function_replacements_size; i++) {
if (!FunctionPatcherPatchFunction(&applicationendshook_function_replacements[i], nullptr)) {
bool wasPatched = false;
if (FunctionPatcher_AddFunctionPatch(&applicationendshook_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
OSFatal("AromaBaseModule: Failed to patch ApplicationEndsHook function");
}
}

View File

@ -4,6 +4,8 @@
#include "logger.h"
#include <malloc.h>
extern "C" FunctionPatcherStatus FPAddFunctionPatch(function_replacement_data_t *function_data, PatchedFunctionHandle *outHandle, bool *outHasBeenPatched);
void initDynload() {
gLoadedRPLData = (LOADED_RPL *) malloc(sizeof(LOADED_RPL) * gModuleData->number_modules);
if (!gLoadedRPLData) {
@ -18,7 +20,9 @@ void initDynload() {
DEBUG_FUNCTION_LINE("Patch functions for dynload patches");
for (uint32_t i = 0; i < dynload_function_replacements_size; i++) {
if (!FunctionPatcherPatchFunction(&dynload_function_replacements[i], nullptr)) {
bool wasPatched = false;
// We need to use FPAddFunctionPatch because we can't use libfunctionpatcher yet. This patch enables it though.
if (FPAddFunctionPatch(&dynload_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
OSFatal("AromaBaseModule: Failed to patch function for dynload patches");
}
}

View File

@ -0,0 +1,4 @@
:NAME homebrew_functionpatcher
:TEXT
FPAddFunctionPatch

View File

@ -1,4 +1,5 @@
#include "dynload/loader_defines.h"
#include <function_patcher/fpatching_defines.h>
#include <wums.h>
extern module_information_t *gModuleData;

View File

@ -6,10 +6,12 @@
#include "sdrefcount/refcount.h"
#include "symbolnamepatcher/symbolname.h"
#include "version.h"
#include <function_patcher/function_patching.h>
#include <wums.h>
WUMS_MODULE_EXPORT_NAME("homebrew_basemodule");
WUMS_MODULE_SKIP_INIT_FINI();
WUMS_DEPENDS_ON(homebrew_functionpatcher);
#define VERSION "v0.2.0"
@ -23,10 +25,18 @@ WUMS_INITIALIZE(args) {
OSFatal("AromaBaseModule: The module information struct version does not match.");
}
// First init Dynload to have proper OSDynLoad support!
initDynload();
// Now init the library so we can use it for the other patches.
if (FunctionPatcher_InitLibrary() != FUNCTION_PATCHER_RESULT_SUCCESS) {
OSFatal("homebrew_basemodule: FunctionPatcher_InitLibrary failed");
}
initApplicationEndsHook();
initSDRefCount();
initSymbolNamePatcher();
initDynload();
initCommonPatches();
deinitLogging();

View File

@ -21,7 +21,8 @@ void initCommonPatches() {
DEBUG_FUNCTION_LINE("Do common patches");
for (uint32_t i = 0; i < patches_function_replacements_size; i++) {
if (!FunctionPatcherPatchFunction(&patches_function_replacements[i], nullptr)) {
bool wasPatched = false;
if (FunctionPatcher_AddFunctionPatch(&patches_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
OSFatal("AromaBaseModule: Failed apply common patches");
}
}

View File

@ -21,7 +21,8 @@ void initSDRefCount() {
DEBUG_FUNCTION_LINE("Patch SDRefCount functions");
for (uint32_t i = 0; i < sdrefcount_function_replacements_size; i++) {
if (!FunctionPatcherPatchFunction(&sdrefcount_function_replacements[i], nullptr)) {
bool wasPatched = false;
if (FunctionPatcher_AddFunctionPatch(&sdrefcount_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
OSFatal("AromaBaseModule: Failed to patch function for sd ref counting");
}
}

View File

@ -5,7 +5,8 @@
void initSymbolNamePatcher() {
DEBUG_FUNCTION_LINE("Patch SymbolNamePatcher functions");
for (uint32_t i = 0; i < symbolname_function_replacements_size; i++) {
if (!FunctionPatcherPatchFunction(&symbolname_function_replacements[i], nullptr)) {
bool wasPatched = false;
if (FunctionPatcher_AddFunctionPatch(&symbolname_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
OSFatal("AromaBaseModule: Failed to patch SymbolNamePatcher function");
}
}