2020-05-03 11:13:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2016-2018 Maschell
|
|
|
|
* With code from chadderz and dimok
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wups.h>
|
|
|
|
|
|
|
|
#include "function_patcher.h"
|
|
|
|
#include <utils/logger.h>
|
|
|
|
#include <utils/utils.h>
|
|
|
|
#include <kernel/kernel_defs.h>
|
|
|
|
#include <kernel/kernel_utils.h>
|
|
|
|
#include <coreinit/memorymap.h>
|
|
|
|
#include <coreinit/cache.h>
|
|
|
|
#include <whb/log.h>
|
|
|
|
#include <coreinit/dynload.h>
|
|
|
|
|
|
|
|
#define DEBUG_LOG_DYN 0
|
|
|
|
|
|
|
|
rpl_handling rpl_handles[] __attribute__((section(".data"))) = {
|
2020-05-03 12:30:15 +02:00
|
|
|
{WUPS_LOADER_LIBRARY_AVM, "avm.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_CAMERA, "camera.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_COREINIT, "coreinit.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_DC, "dc.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_DMAE, "dmae.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_DRMAPP, "drmapp.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_ERREULA, "erreula.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_GX2, "gx2.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_H264, "h264.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_LZMA920, "lzma920.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_MIC, "mic.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NFC, "nfc.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NIO_PROF, "nio_prof.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NLIBCURL, "nlibcurl.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NLIBNSS, "nlibnss.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NLIBNSS2, "nlibnss2.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_AC, "nn_ac.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_ACP, "nn_acp.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_ACT, "nn_act.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_AOC, "nn_aoc.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_BOSS, "nn_boss.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_CCR, "nn_ccr.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_CMPT, "nn_cmpt.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_DLP, "nn_dlp.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_EC, "nn_ec.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_FP, "nn_fp.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_HAI, "nn_hai.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_HPAD, "nn_hpad.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_IDBE, "nn_idbe.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_NDM, "nn_ndm.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_NETS2, "nn_nets2.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_NFP, "nn_nfp.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_NIM, "nn_nim.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_OLV, "nn_olv.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_PDM, "nn_pdm.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_SAVE, "nn_save.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_SL, "nn_sl.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_SPM, "nn_spm.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_TEMP, "nn_temp.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_UDS, "nn_uds.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NN_VCTL, "nn_vctl.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NSYSCCR, "nsysccr.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NSYSHID, "nsyshid.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NSYSKBD, "nsyskbd.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NSYSNET, "nsysnet.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NSYSUHS, "nsysuhs.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NSYSUVD, "nsysuvd.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_NTAG, "ntag.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_PADSCORE, "padscore.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_PROC_UI, "proc_ui.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_SNDCORE2, "sndcore2.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_SNDUSER2, "snduser2.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_SND_CORE, "snd_core.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_SND_USER, "snd_user.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_SWKBD, "swkbd.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_SYSAPP, "sysapp.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_TCL, "tcl.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_TVE, "tve.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_UAC, "uac.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_UAC_RPL, "uac_rpl.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_USB_MIC, "usb_mic.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_UVC, "uvc.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_UVD, "uvd.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_VPAD, "vpad.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_VPADBASE, "vpadbase.rpl", 0},
|
|
|
|
{WUPS_LOADER_LIBRARY_ZLIB125, "zlib125.rpl", 0}
|
2020-05-03 11:13:55 +02:00
|
|
|
};
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
void new_PatchInvidualMethodHooks(plugin_info_t *plugin_data) {
|
2020-05-03 11:13:55 +02:00
|
|
|
new_resetLibs();
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Patching %d given functions", plugin_data->number_used_functions);
|
2020-05-03 11:13:55 +02:00
|
|
|
|
|
|
|
int32_t method_hooks_count = plugin_data->number_used_functions;
|
|
|
|
|
|
|
|
uint32_t skip_instr = 1;
|
|
|
|
uint32_t my_instr_len = 6;
|
|
|
|
uint32_t instr_len = my_instr_len + skip_instr + 6;
|
2020-05-03 12:30:15 +02:00
|
|
|
uint32_t flush_len = 4 * instr_len;
|
|
|
|
for (int32_t i = 0; i < method_hooks_count; i++) {
|
|
|
|
replacement_data_function_t *function_data = &plugin_data->functions[i];
|
2020-05-03 11:13:55 +02:00
|
|
|
/* Patch branches to it. */
|
|
|
|
volatile uint32_t *space = function_data->replace_data;
|
|
|
|
|
2020-05-08 11:17:24 +02:00
|
|
|
DEBUG_FUNCTION_LINE_WRITE("Patching %s ...", function_data->function_name);
|
2020-05-03 11:13:55 +02:00
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->library == WUPS_LOADER_LIBRARY_OTHER) {
|
2020-05-08 11:17:24 +02:00
|
|
|
WHBLogWritef("Oh, using straight PA/VA");
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->alreadyPatched == 1) {
|
2020-05-03 11:13:55 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Skipping %s, its already patched", function_data->function_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->functionType == STATIC_FUNCTION && function_data->alreadyPatched == 1) {
|
|
|
|
if (new_isDynamicFunction((uint32_t) OSEffectiveToPhysical(function_data->realAddr))) {
|
2020-05-03 11:13:55 +02:00
|
|
|
DEBUG_FUNCTION_LINE("INFO: The function %s is a dynamic function.", function_data->function_name);
|
|
|
|
function_data->functionType = DYNAMIC_FUNCTION;
|
|
|
|
} else {
|
2020-05-08 11:17:24 +02:00
|
|
|
WHBLogWritef("Skipping %s, its already patched\n", function_data->function_name);
|
2020-05-03 11:13:55 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t physical = function_data->physicalAddr;
|
2020-05-03 12:30:15 +02:00
|
|
|
uint32_t repl_addr = (uint32_t) function_data->replaceAddr;
|
|
|
|
uint32_t call_addr = (uint32_t) function_data->replaceCall;
|
2020-05-03 11:13:55 +02:00
|
|
|
|
|
|
|
uint32_t real_addr = function_data->virtualAddr;
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->library != WUPS_LOADER_LIBRARY_OTHER) {
|
|
|
|
real_addr = new_GetAddressOfFunction(function_data->function_name, function_data->library);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (!real_addr) {
|
2020-05-08 11:17:24 +02:00
|
|
|
WHBLogWritef("\n");
|
2020-05-03 11:13:55 +02:00
|
|
|
DEBUG_FUNCTION_LINE("OSDynLoad_FindExport failed for %s\n", function_data->function_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (DEBUG_LOG_DYN) {
|
|
|
|
DEBUG_FUNCTION_LINE("%s is located at %08X!\n", function_data->function_name, real_addr);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->library != WUPS_LOADER_LIBRARY_OTHER) {
|
|
|
|
physical = (uint32_t) OSEffectiveToPhysical(real_addr);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (!physical) {
|
2020-05-08 11:17:24 +02:00
|
|
|
WHBLogWritef("Error. Something is wrong with the physical address\n");
|
2020-05-03 11:13:55 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (DEBUG_LOG_DYN) {
|
|
|
|
DEBUG_FUNCTION_LINE("%s physical is located at %08X!\n", function_data->function_name, physical);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
*(volatile uint32_t *) (call_addr) = (uint32_t) (space);
|
2020-05-03 11:13:55 +02:00
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
uint32_t targetAddr = (uint32_t) space;
|
|
|
|
if (targetAddr < 0x00800000 || targetAddr >= 0x01000000) {
|
2020-05-03 11:13:55 +02:00
|
|
|
targetAddr = (uint32_t) OSEffectiveToPhysical(targetAddr);
|
2020-05-03 12:30:15 +02:00
|
|
|
} else {
|
2020-05-03 11:13:55 +02:00
|
|
|
targetAddr = targetAddr + 0x30800000 - 0x00800000;
|
|
|
|
}
|
|
|
|
|
|
|
|
KernelCopyData(targetAddr, physical, 4);
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
ICInvalidateRange((void *) (space), 4);
|
|
|
|
DCFlushRange((void *) (space), 4);
|
2020-05-03 11:13:55 +02:00
|
|
|
|
|
|
|
space++;
|
|
|
|
|
|
|
|
//Only works if skip_instr == 1
|
2020-05-03 12:30:15 +02:00
|
|
|
if (skip_instr == 1) {
|
2020-05-03 11:13:55 +02:00
|
|
|
// fill the restore instruction section
|
|
|
|
function_data->realAddr = real_addr;
|
|
|
|
function_data->restoreInstruction = space[-1];
|
2020-05-03 12:30:15 +02:00
|
|
|
if (DEBUG_LOG_DYN) {
|
2020-05-03 11:13:55 +02:00
|
|
|
DEBUG_FUNCTION_LINE("function_data->realAddr = %08X!\n", function_data->realAddr);
|
|
|
|
}
|
2020-05-03 12:30:15 +02:00
|
|
|
if (DEBUG_LOG_DYN) {
|
|
|
|
DEBUG_FUNCTION_LINE("function_data->restoreInstruction = %08X!\n", function_data->restoreInstruction);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-05-08 11:17:24 +02:00
|
|
|
WHBLogWritef("Error. Can't save %s for restoring!\n", function_data->function_name);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//adding jump to real function thx @ dimok for the assembler code
|
|
|
|
/*
|
|
|
|
90 61 ff e0 stw r3,-32(r1)
|
|
|
|
3c 60 12 34 lis r3,4660
|
|
|
|
60 63 56 78 ori r3,r3,22136
|
|
|
|
7c 69 03 a6 mtctr r3
|
|
|
|
80 61 ff e0 lwz r3,-32(r1)
|
|
|
|
4e 80 04 20 bctr*/
|
|
|
|
*space = 0x9061FFE0;
|
|
|
|
space++;
|
|
|
|
*space = 0x3C600000 | (((real_addr + (skip_instr * 4)) >> 16) & 0x0000FFFF); // lis r3, real_addr@h
|
|
|
|
space++;
|
2020-05-03 12:30:15 +02:00
|
|
|
*space = 0x60630000 | ((real_addr + (skip_instr * 4)) & 0x0000ffff); // ori r3, r3, real_addr@l
|
2020-05-03 11:13:55 +02:00
|
|
|
space++;
|
|
|
|
*space = 0x7C6903A6; // mtctr r3
|
|
|
|
space++;
|
|
|
|
*space = 0x8061FFE0; // lwz r3,-32(r1)
|
|
|
|
space++;
|
|
|
|
*space = 0x4E800420; // bctr
|
|
|
|
space++;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t repl_addr_test = (uint32_t) space;
|
|
|
|
*space = 0x9061FFE0;
|
|
|
|
space++;
|
|
|
|
*space = 0x3C600000 | (((repl_addr) >> 16) & 0x0000FFFF); // lis r3, repl_addr@h
|
|
|
|
space++;
|
2020-05-03 12:30:15 +02:00
|
|
|
*space = 0x60630000 | ((repl_addr) & 0x0000ffff); // ori r3, r3, repl_addr@l
|
2020-05-03 11:13:55 +02:00
|
|
|
space++;
|
|
|
|
*space = 0x7C6903A6; // mtctr r3
|
|
|
|
space++;
|
|
|
|
*space = 0x8061FFE0; // lwz r3,-32(r1)
|
|
|
|
space++;
|
|
|
|
*space = 0x4E800420; // bctr
|
|
|
|
space++;
|
2020-05-03 12:30:15 +02:00
|
|
|
DCFlushRange((void *) (((uint32_t) space) - flush_len), flush_len);
|
|
|
|
ICInvalidateRange((void *) (((uint32_t) space) - flush_len), flush_len);
|
2020-05-03 11:13:55 +02:00
|
|
|
|
|
|
|
//setting jump back
|
|
|
|
uint32_t replace_instr = 0x48000002 | (repl_addr_test & 0x03fffffc);
|
|
|
|
ICInvalidateRange(&replace_instr, 4);
|
|
|
|
DCFlushRange(&replace_instr, 4);
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
KernelCopyData(physical, (uint32_t) OSEffectiveToPhysical((uint32_t) &replace_instr), 4);
|
|
|
|
ICInvalidateRange((void *) (real_addr), 4);
|
|
|
|
DCFlushRange((void *) (real_addr), 4);
|
2020-05-03 11:13:55 +02:00
|
|
|
|
|
|
|
function_data->alreadyPatched = 1;
|
|
|
|
DEBUG_FUNCTION_LINE("done with patching %s!\n", function_data->function_name);
|
|
|
|
|
|
|
|
}
|
|
|
|
DEBUG_FUNCTION_LINE("Done with patching given functions!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************************************************************** */
|
|
|
|
/* RESTORE ORIGINAL INSTRUCTIONS */
|
|
|
|
/* ****************************************************************** */
|
2020-05-03 12:30:15 +02:00
|
|
|
void new_RestoreInvidualInstructions(plugin_info_t *plugin_data) {
|
2020-05-03 11:13:55 +02:00
|
|
|
new_resetLibs();
|
|
|
|
DEBUG_FUNCTION_LINE("Restoring given functions!");
|
|
|
|
|
|
|
|
int32_t method_hooks_count = plugin_data->number_used_functions;
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
for (int32_t i = 0; i < method_hooks_count; i++) {
|
|
|
|
replacement_data_function_t *function_data = &plugin_data->functions[i];
|
2020-05-03 11:13:55 +02:00
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Restoring %s... ", function_data->function_name);
|
|
|
|
if (function_data->restoreInstruction == 0 || function_data->realAddr == 0) {
|
2020-05-03 11:13:55 +02:00
|
|
|
WHBLogPrintf("I dont have the information for the restore =( skip");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t real_addr = function_data->virtualAddr;
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->library != WUPS_LOADER_LIBRARY_OTHER) {
|
|
|
|
real_addr = new_GetAddressOfFunction(function_data->function_name, function_data->library);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
2020-05-03 12:30:15 +02:00
|
|
|
if (!real_addr) {
|
2020-05-03 11:13:55 +02:00
|
|
|
WHBLogPrintf("OSDynLoad_FindExport failed for %s", function_data->function_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
uint32_t physical = function_data->physicalAddr;
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->library != WUPS_LOADER_LIBRARY_OTHER) {
|
|
|
|
physical = (uint32_t) OSEffectiveToPhysical(real_addr);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
2020-05-03 12:30:15 +02:00
|
|
|
if (!physical) {
|
2020-05-03 11:13:55 +02:00
|
|
|
WHBLogPrintf("Something is wrong with the physical address");
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-03 12:30:15 +02:00
|
|
|
if ((function_data->library != WUPS_LOADER_LIBRARY_OTHER) && new_isDynamicFunction(physical)) {
|
|
|
|
WHBLogPrintf("Its a dynamic function. We don't need to restore it!", function_data->function_name);
|
2020-05-03 11:13:55 +02:00
|
|
|
} else {
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->library != WUPS_LOADER_LIBRARY_OTHER) {
|
|
|
|
physical = (uint32_t) OSEffectiveToPhysical(function_data->realAddr); //When its an static function, we need to use the old location
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG_LOG_DYN) {
|
|
|
|
DEBUG_FUNCTION_LINE("Restoring %08X to %08X", (uint32_t) function_data->restoreInstruction, physical);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
2020-05-03 12:30:15 +02:00
|
|
|
uint32_t targetAddr = (uint32_t) &(function_data->restoreInstruction);
|
|
|
|
if (targetAddr < 0x00800000 || targetAddr >= 0x01000000) {
|
2020-05-03 11:13:55 +02:00
|
|
|
targetAddr = (uint32_t) OSEffectiveToPhysical(targetAddr);
|
|
|
|
} else {
|
|
|
|
targetAddr = targetAddr + 0x30800000 - 0x00800000;
|
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Copy %d bytes from %08X to %08x", 4, targetAddr, physical);
|
2020-05-03 11:13:55 +02:00
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
KernelCopyData(physical, targetAddr, 4);
|
|
|
|
if (DEBUG_LOG_DYN) {
|
|
|
|
DEBUG_FUNCTION_LINE("ICInvalidateRange %08X", (void *) function_data->realAddr);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (function_data->library != WUPS_LOADER_LIBRARY_OTHER) {
|
|
|
|
ICInvalidateRange((void *) function_data->realAddr, 4);
|
|
|
|
DCFlushRange((void *) function_data->realAddr, 4);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
WHBLogPrintf("done");
|
|
|
|
}
|
|
|
|
function_data->alreadyPatched = 0; // In case a
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_FUNCTION_LINE("Done with restoring given functions!");
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t new_isDynamicFunction(uint32_t physicalAddress) {
|
2020-05-03 12:30:15 +02:00
|
|
|
if ((physicalAddress & 0x80000000) == 0x80000000) {
|
2020-05-03 11:13:55 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
uint32_t new_GetAddressOfFunction(const char *functionName, wups_loader_library_type_t library) {
|
2020-05-03 11:13:55 +02:00
|
|
|
uint32_t real_addr = 0;
|
|
|
|
|
|
|
|
OSDynLoad_Module rpl_handle = 0;
|
|
|
|
|
|
|
|
int32_t rpl_handles_size = sizeof rpl_handles / sizeof rpl_handles[0];
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
for (int32_t i = 0; i < rpl_handles_size; i++) {
|
|
|
|
if (rpl_handles[i].library == library) {
|
|
|
|
if (rpl_handles[i].handle == 0) {
|
|
|
|
DEBUG_FUNCTION_LINE("Lets acquire handle for rpl: %s\n", rpl_handles[i].rplname);
|
|
|
|
OSDynLoad_Acquire((char *) rpl_handles[i].rplname, &rpl_handles[i].handle);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
2020-05-03 12:30:15 +02:00
|
|
|
if (rpl_handles[i].handle == 0) {
|
2020-05-08 11:17:24 +02:00
|
|
|
WHBLogWritef("%s failed to acquire\n", rpl_handles[i].rplname);
|
2020-05-03 11:13:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rpl_handle = rpl_handles[i].handle;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (!rpl_handle) {
|
2020-05-03 11:13:55 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Failed to find the RPL handle for %s\n", functionName);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSDynLoad_FindExport(rpl_handle, 0, functionName, reinterpret_cast<void **>(&real_addr));
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if (!real_addr) {
|
2020-05-03 11:13:55 +02:00
|
|
|
DEBUG_FUNCTION_LINE("OSDynLoad_FindExport failed for %s\n", functionName);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
if ((library == WUPS_LOADER_LIBRARY_NN_ACP) && (uint32_t) (*(volatile uint32_t *) (real_addr) & 0x48000002) == 0x48000000) {
|
|
|
|
uint32_t address_diff = (uint32_t) (*(volatile uint32_t *) (real_addr) & 0x03FFFFFC);
|
|
|
|
if ((address_diff & 0x03000000) == 0x03000000) {
|
|
|
|
address_diff |= 0xFC000000;
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
2020-05-03 12:30:15 +02:00
|
|
|
real_addr += (int32_t) address_diff;
|
|
|
|
if ((uint32_t) (*(volatile uint32_t *) (real_addr) & 0x48000002) == 0x48000000) {
|
2020-05-03 11:13:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return real_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_resetLibs() {
|
|
|
|
int32_t rpl_handles_size = sizeof rpl_handles / sizeof rpl_handles[0];
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
for (int32_t i = 0; i < rpl_handles_size; i++) {
|
|
|
|
if (rpl_handles[i].handle != 0) {
|
|
|
|
DEBUG_FUNCTION_LINE("Resetting handle for rpl: %s\n", rpl_handles[i].rplname);
|
2020-05-03 11:13:55 +02:00
|
|
|
}
|
|
|
|
rpl_handles[i].handle = 0;
|
|
|
|
// Release handle?
|
|
|
|
}
|
|
|
|
}
|