diff --git a/Dockerfile b/Dockerfile index a6f63d3..f34083b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,6 @@ COPY --from=wiiuenv/wiiumodulesystem:20230106 /artifacts $DEVKITPRO COPY --from=wiiuenv/wiiupluginsystem:20230215 /artifacts $DEVKITPRO COPY --from=wiiuenv/libfunctionpatcher:20230108 /artifacts $DEVKITPRO COPY --from=wiiuenv/libmappedmemory:20220904 /artifacts $DEVKITPRO -COPY --from=wiiuenv/libwupsbackend:20220904 /artifacts $DEVKITPRO +COPY --from=wiiuenv/libwupsbackend:20230217 /artifacts $DEVKITPRO WORKDIR project diff --git a/source/plugin/PluginInformation.h b/source/plugin/PluginInformation.h index 0fcc97e..8f43f75 100644 --- a/source/plugin/PluginInformation.h +++ b/source/plugin/PluginInformation.h @@ -116,6 +116,14 @@ public: return {}; } + void *getTextMemoryAddress() { + return allocatedTextMemoryAddress.get(); + } + + void *getDataMemoryAddress() { + return allocatedDataMemoryAddress.get(); + } + private: std::vector> hook_data_list; std::vector> function_data_list; diff --git a/source/utils/exports.cpp b/source/utils/exports.cpp index c4212f7..5ed934a 100644 --- a/source/utils/exports.cpp +++ b/source/utils/exports.cpp @@ -221,4 +221,88 @@ WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByPath); WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByBuffer); WUMS_EXPORT_FUNCTION(WUPSGetMetaInformation); WUMS_EXPORT_FUNCTION(WUPSGetLoadedPlugins); -WUMS_EXPORT_FUNCTION(WUPSGetPluginDataForContainerHandles); \ No newline at end of file +WUMS_EXPORT_FUNCTION(WUPSGetPluginDataForContainerHandles); + +// API 2.0 +extern "C" PluginBackendApiErrorType WUPSGetAPIVersion(WUPSBackendAPIVersion *outVersion) { + if (outVersion == nullptr) { + return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + *outVersion = 2; + return PLUGIN_BACKEND_API_ERROR_NONE; +} + +extern "C" PluginBackendApiErrorType WUPSGetNumberOfLoadedPlugins(uint32_t *outCount) { + if (outCount == nullptr) { + return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + *outCount = gLoadedPlugins.size(); + return PLUGIN_BACKEND_API_ERROR_NONE; +} + +extern "C" PluginBackendApiErrorType WUPSGetSectionInformationForPlugin(const plugin_container_handle handle, plugin_section_info *plugin_section_list, uint32_t buffer_size, uint32_t *out_count) { + PluginBackendApiErrorType res = PLUGIN_BACKEND_API_ERROR_NONE; + if (out_count != nullptr) { + *out_count = 0; + } + if (handle != 0 && plugin_section_list != nullptr && buffer_size != 0) { + bool found = false; + for (auto &curContainer : gLoadedPlugins) { + if (curContainer->getHandle() == handle) { + found = true; + auto §ionInfoList = curContainer->getPluginInformation()->getSectionInfoList(); + + uint32_t offset = 0; + for (auto const &[key, sectionInfo] : sectionInfoList) { + if (offset >= buffer_size) { + break; + } + plugin_section_list[offset].plugin_section_info_version = PLUGIN_SECTION_INFORMATION_VERSION; + strncpy(plugin_section_list[offset].name, sectionInfo->getName().c_str(), sizeof(plugin_section_list[offset].name) - 1); + plugin_section_list[offset].address = (void *) sectionInfo->getAddress(); + plugin_section_list[offset].size = sectionInfo->getSize(); + offset++; + } + if (out_count != nullptr) { + *out_count = offset; + } + break; + } + } + if (!found) { + res = PLUGIN_BACKEND_API_INVALID_HANDLE; + } + } else { + res = PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + return res; +} + +extern "C" PluginBackendApiErrorType WUPSWillReloadPluginsOnNextLaunch(bool *out) { + if (out == nullptr) { + return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + std::lock_guard lock(gLoadedDataMutex); + *out = !gLoadOnNextLaunch.empty(); + return PLUGIN_BACKEND_API_ERROR_NONE; +} + +extern "C" PluginBackendApiErrorType WUPSGetSectionMemoryAddresses(plugin_container_handle handle, void **textAddress, void **dataAddress) { + if (handle == 0 || textAddress == nullptr || dataAddress == nullptr) { + return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + for (auto &curContainer : gLoadedPlugins) { + if (curContainer->getHandle() == handle) { + *textAddress = curContainer->getPluginInformation()->getTextMemoryAddress(); + *dataAddress = curContainer->getPluginInformation()->getDataMemoryAddress(); + return PLUGIN_BACKEND_API_ERROR_NONE; + } + } + return PLUGIN_BACKEND_API_INVALID_HANDLE; +} + +WUMS_EXPORT_FUNCTION(WUPSGetAPIVersion); +WUMS_EXPORT_FUNCTION(WUPSGetNumberOfLoadedPlugins); +WUMS_EXPORT_FUNCTION(WUPSGetSectionInformationForPlugin); +WUMS_EXPORT_FUNCTION(WUPSWillReloadPluginsOnNextLaunch); +WUMS_EXPORT_FUNCTION(WUPSGetSectionMemoryAddresses); \ No newline at end of file