Set the "out" value properly in "__OSDynLoad_InternalAcquire" hook to fix calling "OSDynLoad_IsModuleLoaded" with aroma module names

This commit is contained in:
Maschell 2022-10-05 15:52:24 +02:00
parent 769262a66c
commit fa6c26e26c
5 changed files with 23 additions and 3 deletions

View File

@ -10,6 +10,11 @@ void initDynload() {
DEBUG_FUNCTION_LINE_ERR("Failed to allocate gLoadedRPLData"); DEBUG_FUNCTION_LINE_ERR("Failed to allocate gLoadedRPLData");
OSFatal("AromaBaseModule: Failed to allocate gLoadedRPLData"); OSFatal("AromaBaseModule: Failed to allocate gLoadedRPLData");
} }
gRPLData = (RPL_DATA *) malloc(sizeof(RPL_DATA) * gModuleData->number_modules);
if (!gRPLData) {
DEBUG_FUNCTION_LINE_ERR("Failed to allocate gRPLData");
OSFatal("AromaBaseModule: Failed to allocate gRPLData");
}
DEBUG_FUNCTION_LINE("Patch functions for dynload patches"); DEBUG_FUNCTION_LINE("Patch functions for dynload patches");
for (uint32_t i = 0; i < dynload_function_replacements_size; i++) { for (uint32_t i = 0; i < dynload_function_replacements_size; i++) {

View File

@ -77,10 +77,14 @@ DECL_FUNCTION(LOADED_RPL *, LiFindRPLByName, char *name) {
return real_LiFindRPLByName(name); return real_LiFindRPLByName(name);
} }
DECL_FUNCTION(uint32_t, __OSDynLoad_InternalAcquire, char *name, void *out, uint32_t u1, uint32_t u2, uint32_t u3) { DECL_FUNCTION(uint32_t, __OSDynLoad_InternalAcquire, char *name, RPL_DATA **out, uint32_t u1, uint32_t u2, uint32_t u3) {
for (uint32_t i = 0; i < gModuleData->number_modules; i++) { for (uint32_t i = 0; i < gModuleData->number_modules; i++) {
auto *curModule = &gModuleData->modules[i]; auto *curModule = &gModuleData->modules[i];
if (strcmp(name, curModule->module_export_name) == 0) { if (strcmp(name, curModule->module_export_name) == 0) {
// OSDynLoad_IsModuleLoaded uses __OSDynLoad_InternalAcquire and expects out have a valid value.
// It uses the "handle", so don't need to fill the whole struct.
gRPLData[i].handle = MODULE_MAGIC | i;
*out = &gRPLData[i];
return 0; return 0;
} }
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <wut.h>
// see https://github.com/decaf-emu/decaf-emu/tree/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader // see https://github.com/decaf-emu/decaf-emu/tree/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader
struct LiImportTracking { struct LiImportTracking {
@ -35,6 +36,14 @@ struct LOADED_RPL {
char u4[12]; char u4[12];
}; };
// https://github.com/decaf-emu/decaf-emu/blob/6feb1be1db3938e6da2d4a65fc0a7a8599fc8dd6/src/libdecaf/src/cafe/libraries/coreinit/coreinit_dynload.cpp#L40
struct RPL_DATA {
uint32_t handle;
WUT_UNKNOWN_BYTES(0x94 - 0x4);
};
WUT_CHECK_SIZE(RPL_DATA, 0x94);
#define EXPORT_MASK 0xFFFF0000 #define EXPORT_MASK 0xFFFF0000
#define EXPORT_MAGIC_MASK 0x0000FFFF #define EXPORT_MAGIC_MASK 0x0000FFFF
#define FUNCTION_EXPORT_MAGIC 0x88660000 #define FUNCTION_EXPORT_MAGIC 0x88660000

View File

@ -2,4 +2,5 @@
module_information_t *gModuleData __attribute__((section(".data"))) = NULL; module_information_t *gModuleData __attribute__((section(".data"))) = NULL;
int32_t gSDMountRefCount __attribute__((section(".data"))) = 0; int32_t gSDMountRefCount __attribute__((section(".data"))) = 0;
LOADED_RPL *gLoadedRPLData __attribute__((section(".data"))) = nullptr; LOADED_RPL *gLoadedRPLData __attribute__((section(".data"))) = nullptr;
RPL_DATA *gRPLData __attribute__((section(".data"))) = nullptr;

View File

@ -3,4 +3,5 @@
extern module_information_t *gModuleData; extern module_information_t *gModuleData;
extern int32_t gSDMountRefCount; extern int32_t gSDMountRefCount;
extern LOADED_RPL *gLoadedRPLData; extern LOADED_RPL *gLoadedRPLData;
extern RPL_DATA *gRPLData;