2020-04-29 18:02:36 +02:00
|
|
|
#include <wups.h>
|
|
|
|
#include <whb/log.h>
|
|
|
|
#include <whb/log_udp.h>
|
|
|
|
#include <exception>
|
|
|
|
#include <sysapp/launch.h>
|
|
|
|
#include <coreinit/memexpheap.h>
|
|
|
|
#include <coreinit/dynload.h>
|
|
|
|
#include <coreinit/cache.h>
|
|
|
|
#include "plugin/PluginDataFactory.h"
|
|
|
|
#include "plugin/PluginContainerPersistence.h"
|
|
|
|
#include "plugin/PluginInformationFactory.h"
|
|
|
|
#include "plugin/PluginMetaInformationFactory.h"
|
|
|
|
#include "plugin/FunctionData.h"
|
|
|
|
#include "plugin/PluginContainer.h"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "kernel/kernel_utils.h"
|
2020-05-03 10:21:05 +02:00
|
|
|
|
2020-04-29 18:02:36 +02:00
|
|
|
#include "utils/ElfUtils.h"
|
|
|
|
#include "common/relocation_defines.h"
|
|
|
|
#include "common/plugin_defines.h"
|
|
|
|
#include "common/plugin_defines.h"
|
|
|
|
#include "common/module_defines.h"
|
|
|
|
#include "hooks.h"
|
2020-05-03 10:21:05 +02:00
|
|
|
#include "PluginManagement.h"
|
2020-05-17 20:40:05 +02:00
|
|
|
#include "globals.h"
|
2020-04-29 18:02:36 +02:00
|
|
|
#include <whb/sdcard.h>
|
|
|
|
|
|
|
|
|
|
|
|
int test();
|
|
|
|
|
2020-05-03 14:14:22 +02:00
|
|
|
std::vector<PluginContainer> loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle);
|
2020-05-03 12:37:20 +02:00
|
|
|
|
2020-04-29 18:02:36 +02:00
|
|
|
#define gModuleData ((module_information_t *) (0x00880000))
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
int test() {
|
|
|
|
WHBLogUdpInit();
|
2020-05-03 10:21:05 +02:00
|
|
|
bool initNeeded = false;
|
|
|
|
if (pluginDataHeap == NULL) {
|
2020-04-29 18:02:36 +02:00
|
|
|
kernelInitialize();
|
|
|
|
DEBUG_FUNCTION_LINE("Kernel init done");
|
2020-05-03 10:21:05 +02:00
|
|
|
DCFlushRange((void *) 0x00880000, sizeof(module_information_t));
|
2020-04-29 18:02:36 +02:00
|
|
|
uint32_t endAddress = 0;
|
2020-05-03 10:21:05 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Using %d modules", gModuleData->number_used_modules);
|
|
|
|
for (int i = 0; i < gModuleData->number_used_modules; i++) {
|
|
|
|
DEBUG_FUNCTION_LINE("%08x", gModuleData->module_data[i].endAddress);
|
2020-04-29 18:02:36 +02:00
|
|
|
uint32_t curEndAddr = gModuleData->module_data[i].endAddress;
|
2020-05-03 10:21:05 +02:00
|
|
|
if (curEndAddr > endAddress) {
|
2020-04-29 18:02:36 +02:00
|
|
|
endAddress = curEndAddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If this address is 0, make sure the header common match the one
|
2020-05-03 10:21:05 +02:00
|
|
|
// in the SetupPayload repo. (I know that's a bad idea)
|
2020-04-29 18:02:36 +02:00
|
|
|
endAddress = (endAddress + 0x100) & 0xFFFFFF00;
|
|
|
|
DEBUG_FUNCTION_LINE("endAddress: %08X", endAddress);
|
|
|
|
|
|
|
|
DEBUG_FUNCTION_LINE("Create heap");
|
2020-05-03 10:21:05 +02:00
|
|
|
pluginDataHeap = MEMCreateExpHeapEx((void *) (endAddress), 0x00FFF000 - endAddress, 0);
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2020-05-03 10:21:05 +02:00
|
|
|
if (pluginDataHeap != NULL) {
|
|
|
|
if (gPluginInformation == NULL) {
|
|
|
|
gPluginInformation = (plugin_information_t *) MEMAllocFromExpHeapEx(pluginDataHeap, sizeof(plugin_information_t), 4);
|
|
|
|
if (gPluginInformation == NULL) {
|
2020-04-29 18:02:36 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Failed to allocate global plugin information");
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-03 10:21:05 +02:00
|
|
|
memset((void *) gPluginInformation, 0, sizeof(plugin_information_t));
|
2020-05-03 11:13:55 +02:00
|
|
|
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
2020-05-03 10:21:05 +02:00
|
|
|
DEBUG_FUNCTION_LINE("MEMGetAllocatableSizeForExpHeapEx %d kb", MEMGetAllocatableSizeForExpHeapEx(pluginDataHeap, 4) / 1024);
|
2020-04-29 18:02:36 +02:00
|
|
|
std::vector<PluginData> pluginList = PluginDataFactory::loadDir("fs:/vol/external01/wiiu/plugins/", pluginDataHeap);
|
|
|
|
DEBUG_FUNCTION_LINE("Loaded %d plugin data", pluginList.size());
|
2020-05-03 11:13:55 +02:00
|
|
|
|
2020-05-03 14:20:00 +02:00
|
|
|
std::vector<PluginContainer> plugins = PluginManagement::loadPlugins(pluginList, pluginDataHeap, gPluginInformation->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2020-05-03 12:37:20 +02:00
|
|
|
for (auto &pluginContainer : plugins) {
|
|
|
|
for (const auto &kv : pluginContainer.getPluginInformation().getSectionInfoList()) {
|
2020-04-29 18:02:36 +02:00
|
|
|
DEBUG_FUNCTION_LINE("%s = %s %08X %d", kv.first.c_str(), kv.second.getName().c_str(), kv.second.getAddress(), kv.second.getSize());
|
|
|
|
}
|
2020-05-03 10:21:05 +02:00
|
|
|
if (!PluginContainerPersistence::savePlugin(gPluginInformation, pluginContainer)) {
|
|
|
|
DEBUG_FUNCTION_LINE("Failed to save plugin");
|
|
|
|
}
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
2020-05-03 10:21:05 +02:00
|
|
|
initNeeded = true;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 10:21:05 +02:00
|
|
|
if (pluginDataHeap != NULL) {
|
2020-04-29 18:02:36 +02:00
|
|
|
std::vector<PluginContainer> plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
|
2020-05-03 10:21:05 +02:00
|
|
|
PluginManagement::doRelocations(plugins, gPluginInformation->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
|
|
|
|
PluginManagement::memsetBSS(plugins);
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2020-05-03 10:21:05 +02:00
|
|
|
DCFlushRange((void *) 0x00800000, 0x00800000);
|
|
|
|
ICInvalidateRange((void *) 0x00800000, 0x00800000);
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2020-05-03 10:21:05 +02:00
|
|
|
if (initNeeded) {
|
|
|
|
PluginManagement::callInitHooks(gPluginInformation);
|
|
|
|
initNeeded = false;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 10:21:05 +02:00
|
|
|
PluginManagement::PatchFunctionsAndCallHooks(gPluginInformation);
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|