Extend the wupsbackend api to provide some extra functions to query plugin information

This commit is contained in:
Maschell 2023-02-17 17:30:28 +01:00
parent 08c0d62c8a
commit d8a906f1db
3 changed files with 94 additions and 2 deletions

View File

@ -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

View File

@ -116,6 +116,14 @@ public:
return {};
}
void *getTextMemoryAddress() {
return allocatedTextMemoryAddress.get();
}
void *getDataMemoryAddress() {
return allocatedDataMemoryAddress.get();
}
private:
std::vector<std::unique_ptr<HookData>> hook_data_list;
std::vector<std::unique_ptr<FunctionData>> function_data_list;

View File

@ -221,4 +221,88 @@ WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByPath);
WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByBuffer);
WUMS_EXPORT_FUNCTION(WUPSGetMetaInformation);
WUMS_EXPORT_FUNCTION(WUPSGetLoadedPlugins);
WUMS_EXPORT_FUNCTION(WUPSGetPluginDataForContainerHandles);
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 &sectionInfoList = 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<std::mutex> 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);