Added Rosalina, see details
- see release notes - ( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°) - (∩ ͡° ͜ʖ ͡°)⊃━☆゚ - ( ͡ᵔ ͜ʖ ͡ᵔ) ♫┌( ͡° ͜ʖ ͡°)┘♪ ♫└( ͡° ͜ʖ ͡°)┐♪
This commit is contained in:
165
sysmodules/rosalina/source/menus/debugger.c
Normal file
165
sysmodules/rosalina/source/menus/debugger.c
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "menus/debugger.h"
|
||||
#include "memory.h"
|
||||
#include "draw.h"
|
||||
#include "minisoc.h"
|
||||
#include "fmt.h"
|
||||
#include "gdb/server.h"
|
||||
#include "gdb/debug.h"
|
||||
#include "gdb/monitor.h"
|
||||
#include "gdb/net.h"
|
||||
|
||||
Menu debuggerMenu = {
|
||||
"Debugger options menu",
|
||||
.nbItems = 2,
|
||||
{
|
||||
{ "Enable debugger", METHOD, .method = &DebuggerMenu_EnableDebugger },
|
||||
{ "Disable debugger", METHOD, .method = &DebuggerMenu_DisableDebugger }
|
||||
}
|
||||
};
|
||||
|
||||
static MyThread debuggerSocketThread;
|
||||
static MyThread debuggerDebugThread;
|
||||
static u8 ALIGN(8) debuggerSocketThreadStack[0x4000];
|
||||
static u8 ALIGN(8) debuggerDebugThreadStack[0x2000];
|
||||
|
||||
GDBServer gdbServer = { 0 };
|
||||
|
||||
void debuggerSocketThreadMain(void);
|
||||
MyThread *debuggerCreateSocketThread(void)
|
||||
{
|
||||
MyThread_Create(&debuggerSocketThread, debuggerSocketThreadMain, debuggerSocketThreadStack, 0x4000, 0x20, CORE_SYSTEM);
|
||||
return &debuggerSocketThread;
|
||||
}
|
||||
|
||||
void debuggerDebugThreadMain(void);
|
||||
MyThread *debuggerCreateDebugThread(void)
|
||||
{
|
||||
MyThread_Create(&debuggerDebugThread, debuggerDebugThreadMain, debuggerDebugThreadStack, 0x2000, 0x20, CORE_SYSTEM);
|
||||
return &debuggerDebugThread;
|
||||
}
|
||||
|
||||
void DebuggerMenu_EnableDebugger(void)
|
||||
{
|
||||
bool done = false, alreadyEnabled = gdbServer.super.running;
|
||||
Result res = 0;
|
||||
char buf[65];
|
||||
bool cantStart;
|
||||
Handle dummy;
|
||||
|
||||
res = OpenProcessByName("socket", &dummy);
|
||||
cantStart = R_FAILED(res);
|
||||
svcCloseHandle(dummy);
|
||||
|
||||
Draw_Lock();
|
||||
Draw_ClearFramebuffer();
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
|
||||
do
|
||||
{
|
||||
Draw_Lock();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Debugger options menu");
|
||||
|
||||
if(alreadyEnabled)
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Already enabled!");
|
||||
else if(cantStart)
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Can't start the debugger before the system has fi-\nnished loading.");
|
||||
else
|
||||
{
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Starting debugger...");
|
||||
|
||||
if(!done)
|
||||
{
|
||||
res = GDB_InitializeServer(&gdbServer);
|
||||
if(R_SUCCEEDED(res))
|
||||
{
|
||||
debuggerCreateSocketThread();
|
||||
debuggerCreateDebugThread();
|
||||
res = svcWaitSynchronization(gdbServer.super.started_event, 10 * 1000 * 1000 * 1000LL);
|
||||
}
|
||||
|
||||
if(res != 0)
|
||||
sprintf(buf, "Starting debugger... failed (0x%08x).", (u32)res);
|
||||
|
||||
done = true;
|
||||
}
|
||||
if(res == 0)
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Starting debugger... OK.");
|
||||
else
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, buf);
|
||||
}
|
||||
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
}
|
||||
while(!(waitInput() & BUTTON_B) && !terminationRequest);
|
||||
}
|
||||
|
||||
void DebuggerMenu_DisableDebugger(void)
|
||||
{
|
||||
bool initialized = gdbServer.referenceCount != 0;
|
||||
Result res = 0;
|
||||
char buf[65];
|
||||
|
||||
if(initialized)
|
||||
{
|
||||
svcSignalEvent(gdbServer.super.shall_terminate_event);
|
||||
res = MyThread_Join(&debuggerDebugThread, 5 * 1000 * 1000 * 1000LL);
|
||||
if(res == 0)
|
||||
res = MyThread_Join(&debuggerSocketThread, 5 * 1000 * 1000 * 1000LL);
|
||||
svcKernelSetState(0x10000, 2);
|
||||
}
|
||||
|
||||
if(res != 0)
|
||||
sprintf(buf, "Failed to disable debugger (0x%08x).", (u32)res);
|
||||
|
||||
do
|
||||
{
|
||||
Draw_Lock();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Debugger options menu");
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, initialized ? (res == 0 ? "Debugger disabled successfully." : buf) : "Debugger not enabled.");
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
}
|
||||
while(!(waitInput() & BUTTON_B) && !terminationRequest);
|
||||
}
|
||||
|
||||
void debuggerSocketThreadMain(void)
|
||||
{
|
||||
GDB_IncrementServerReferenceCount(&gdbServer);
|
||||
GDB_RunServer(&gdbServer);
|
||||
GDB_DecrementServerReferenceCount(&gdbServer);
|
||||
}
|
||||
|
||||
void debuggerDebugThreadMain(void)
|
||||
{
|
||||
GDB_IncrementServerReferenceCount(&gdbServer);
|
||||
GDB_RunMonitor(&gdbServer);
|
||||
GDB_DecrementServerReferenceCount(&gdbServer);
|
||||
}
|
||||
261
sysmodules/rosalina/source/menus/miscellaneous.c
Normal file
261
sysmodules/rosalina/source/menus/miscellaneous.c
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
#include "menus/miscellaneous.h"
|
||||
#include "input_redirection.h"
|
||||
#include "memory.h"
|
||||
#include "draw.h"
|
||||
#include "hbloader.h"
|
||||
#include "fmt.h"
|
||||
#include "utils.h" // for makeARMBranch
|
||||
#include "minisoc.h"
|
||||
|
||||
Menu miscellaneousMenu = {
|
||||
"Miscellaneous options menu",
|
||||
.nbItems = 3,
|
||||
{
|
||||
{ "Switch the hb. title to the current app.", METHOD, .method = &MiscellaneousMenu_SwitchBoot3dsxTargetTitle },
|
||||
{ "Change the menu combo", METHOD, .method = MiscellaneousMenu_ChangeMenuCombo },
|
||||
{ "Start InputRedirection", METHOD, .method = &MiscellaneousMenu_InputRedirection },
|
||||
}
|
||||
};
|
||||
|
||||
void MiscellaneousMenu_SwitchBoot3dsxTargetTitle(void)
|
||||
{
|
||||
Result res;
|
||||
u64 titleId = 0;
|
||||
char failureReason[64];
|
||||
|
||||
if(HBLDR_3DSX_TID == HBLDR_DEFAULT_3DSX_TID)
|
||||
{
|
||||
u32 pidList[0x40];
|
||||
s32 processAmount;
|
||||
|
||||
res = svcGetProcessList(&processAmount, pidList, 0x40);
|
||||
if(R_SUCCEEDED(res))
|
||||
{
|
||||
for(s32 i = 0; i < processAmount && (u32)(titleId >> 32) != 0x00040010 && (u32)(titleId >> 32) != 0x00040000; i++)
|
||||
{
|
||||
Handle processHandle;
|
||||
Result res = svcOpenProcess(&processHandle, pidList[i]);
|
||||
if(R_FAILED(res))
|
||||
continue;
|
||||
|
||||
svcGetProcessInfo((s64 *)&titleId, processHandle, 0x10001);
|
||||
svcCloseHandle(processHandle);
|
||||
}
|
||||
}
|
||||
|
||||
if(R_SUCCEEDED(res) && ((u32)(titleId >> 32) == 0x00040010 || (u32)(titleId >> 32) == 0x00040000))
|
||||
{
|
||||
HBLDR_3DSX_TID = titleId;
|
||||
miscellaneousMenu.items[0].title = "Switch the hb. title to hblauncher_loader";
|
||||
}
|
||||
else if(R_FAILED(res))
|
||||
sprintf(failureReason, "%08x", (u32)res);
|
||||
else
|
||||
{
|
||||
res = -1;
|
||||
strcpy(failureReason, "no suitable process found");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res = 0;
|
||||
HBLDR_3DSX_TID = HBLDR_DEFAULT_3DSX_TID;
|
||||
miscellaneousMenu.items[0].title = "Switch the hb. title to the current app.";
|
||||
}
|
||||
|
||||
Draw_Lock();
|
||||
Draw_ClearFramebuffer();
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
do
|
||||
{
|
||||
Draw_Lock();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Miscellaneous options menu");
|
||||
|
||||
if(R_SUCCEEDED(res))
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded.");
|
||||
else
|
||||
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (%s).", failureReason);
|
||||
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
}
|
||||
while(!(waitInput() & BUTTON_B) && !terminationRequest);
|
||||
}
|
||||
|
||||
static void MiscellaneousMenu_ConvertComboToString(char *out, u32 combo)
|
||||
{
|
||||
static const char *keys[] = { "A", "B", "Select", "Start", "Right", "Left", "Up", "Down", "R", "L", "X", "Y" };
|
||||
for(s32 i = 11; i >= 0; i--)
|
||||
{
|
||||
if(combo & (1 << i))
|
||||
{
|
||||
strcpy(out, keys[i]);
|
||||
out += strlen(keys[i]);
|
||||
*out++ = '+';
|
||||
}
|
||||
}
|
||||
|
||||
out[-1] = 0;
|
||||
}
|
||||
void MiscellaneousMenu_ChangeMenuCombo(void)
|
||||
{
|
||||
char comboStrOrig[64], comboStr[64];
|
||||
u32 posY;
|
||||
|
||||
Draw_Lock();
|
||||
Draw_ClearFramebuffer();
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
|
||||
MiscellaneousMenu_ConvertComboToString(comboStrOrig, menuCombo);
|
||||
|
||||
Draw_Lock();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Miscellaneous options menu");
|
||||
|
||||
posY = Draw_DrawFormattedString(10, 30, COLOR_WHITE, "The current menu combo is: %s", comboStrOrig);
|
||||
posY = Draw_DrawString(10, posY + SPACING_Y, COLOR_WHITE, "Please enter the new combo:");
|
||||
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
|
||||
menuCombo = waitInput();
|
||||
MiscellaneousMenu_ConvertComboToString(comboStr, menuCombo);
|
||||
|
||||
do
|
||||
{
|
||||
Draw_Lock();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Miscellaneous options menu");
|
||||
|
||||
posY = Draw_DrawFormattedString(10, 30, COLOR_WHITE, "The current menu combo is: %s", comboStrOrig);
|
||||
posY = Draw_DrawFormattedString(10, posY + SPACING_Y, COLOR_WHITE, "Please enter the new combo: %s", comboStr) + SPACING_Y;
|
||||
|
||||
posY = Draw_DrawString(10, posY + SPACING_Y, COLOR_WHITE, "Successfully changed the menu combo.");
|
||||
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
}
|
||||
while(!(waitInput() & BUTTON_B) && !terminationRequest);
|
||||
}
|
||||
|
||||
void MiscellaneousMenu_InputRedirection(void)
|
||||
{
|
||||
static MyThread *inputRedirectionThread = NULL;
|
||||
bool done = false;
|
||||
|
||||
Result res;
|
||||
char buf[65];
|
||||
bool wasEnabled = inputRedirectionEnabled;
|
||||
bool cantStart;
|
||||
|
||||
if(wasEnabled)
|
||||
{
|
||||
res = InputRedirection_DoOrUndoPatches();
|
||||
inputRedirectionEnabled = false;
|
||||
res = MyThread_Join(inputRedirectionThread, 5 * 1000 * 1000 * 1000LL);
|
||||
svcCloseHandle(inputRedirectionThreadStartedEvent);
|
||||
|
||||
if(res != 0)
|
||||
sprintf(buf, "Failed to stop InputRedirection (0x%08x).", (u32)res);
|
||||
else
|
||||
miscellaneousMenu.items[2].title = "Start InputRedirection";
|
||||
}
|
||||
else
|
||||
{
|
||||
Handle dummy;
|
||||
s64 dummyInfo;
|
||||
bool isN3DS = svcGetSystemInfo(&dummyInfo, 0x10001, 0) == 0;
|
||||
|
||||
res = OpenProcessByName("socket", &dummy);
|
||||
cantStart = R_FAILED(res);
|
||||
svcCloseHandle(dummy);
|
||||
|
||||
if(!cantStart && isN3DS)
|
||||
{
|
||||
res = OpenProcessByName("ir", &dummy);
|
||||
cantStart = R_FAILED(res);
|
||||
svcCloseHandle(dummy);
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Draw_Lock();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Miscellaneous options menu");
|
||||
|
||||
if(!wasEnabled && cantStart)
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Can't start the debugger before the system has fi-\nnished loading.");
|
||||
else if(!wasEnabled)
|
||||
{
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Starting InputRedirection...");
|
||||
if(!done)
|
||||
{
|
||||
res = InputRedirection_DoOrUndoPatches();
|
||||
if(R_SUCCEEDED(res))
|
||||
{
|
||||
res = svcCreateEvent(&inputRedirectionThreadStartedEvent, RESET_STICKY);
|
||||
if(R_SUCCEEDED(res))
|
||||
{
|
||||
inputRedirectionThread = inputRedirectionCreateThread();
|
||||
res = svcWaitSynchronization(inputRedirectionThreadStartedEvent, 10 * 1000 * 1000 * 1000LL);
|
||||
if(res == 0)
|
||||
res = (Result)inputRedirectionStartResult;
|
||||
|
||||
if(res != 0)
|
||||
InputRedirection_DoOrUndoPatches();
|
||||
}
|
||||
}
|
||||
|
||||
if(res != 0)
|
||||
sprintf(buf, "Starting InputRedirection... failed (0x%08x).", (u32)res);
|
||||
else
|
||||
miscellaneousMenu.items[2].title = "Stop InputRedirection";
|
||||
|
||||
done = true;
|
||||
}
|
||||
|
||||
if(res == 0)
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Starting InputRedirection... OK.");
|
||||
else
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(res == 0)
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "InputRedirection stopped successfully.");
|
||||
else
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, buf);
|
||||
}
|
||||
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
}
|
||||
while(!(waitInput() & BUTTON_B) && !terminationRequest);
|
||||
}
|
||||
74
sysmodules/rosalina/source/menus/n3ds.c
Normal file
74
sysmodules/rosalina/source/menus/n3ds.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
#include "fmt.h"
|
||||
#include "menus/n3ds.h"
|
||||
#include "memory.h"
|
||||
#include "menu.h"
|
||||
|
||||
static char clkRateBuf[128 + 1];
|
||||
|
||||
Menu N3DSMenu = {
|
||||
"New 3DS menu",
|
||||
.nbItems = 2,
|
||||
{
|
||||
{ "Enable L2 cache", METHOD, .method = &N3DSMenu_EnableDisableL2Cache },
|
||||
{ clkRateBuf, METHOD, .method = &N3DSMenu_ChangeClockRate }
|
||||
}
|
||||
};
|
||||
|
||||
static s64 clkRate = 0, higherClkRate = 0, L2CacheEnabled = 0;
|
||||
|
||||
void N3DSMenu_UpdateStatus(void)
|
||||
{
|
||||
svcGetSystemInfo(&clkRate, 0x10001, 0);
|
||||
svcGetSystemInfo(&higherClkRate, 0x10001, 1);
|
||||
svcGetSystemInfo(&L2CacheEnabled, 0x10001, 2);
|
||||
|
||||
N3DSMenu.items[0].title = L2CacheEnabled ? "Disable L2 cache" : "Enable L2 cache";
|
||||
sprintf(clkRateBuf, "Set clock rate to %uMHz", clkRate != 268 ? 268 : (u32)higherClkRate);
|
||||
}
|
||||
|
||||
void N3DSMenu_ChangeClockRate(void)
|
||||
{
|
||||
N3DSMenu_UpdateStatus();
|
||||
|
||||
s64 newBitMask = (L2CacheEnabled << 1) | ((clkRate != 268 ? 1 : 0) ^ 1);
|
||||
svcKernelSetState(10, (u32)newBitMask);
|
||||
|
||||
N3DSMenu_UpdateStatus();
|
||||
}
|
||||
|
||||
void N3DSMenu_EnableDisableL2Cache(void)
|
||||
{
|
||||
N3DSMenu_UpdateStatus();
|
||||
|
||||
s64 newBitMask = ((L2CacheEnabled ^ 1) << 1) | (clkRate != 268 ? 1 : 0);
|
||||
svcKernelSetState(10, (u32)newBitMask);
|
||||
|
||||
N3DSMenu_UpdateStatus();
|
||||
}
|
||||
229
sysmodules/rosalina/source/menus/process_list.c
Normal file
229
sysmodules/rosalina/source/menus/process_list.c
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
#include "menus/process_list.h"
|
||||
#include "memory.h"
|
||||
#include "draw.h"
|
||||
#include "menu.h"
|
||||
#include "utils.h"
|
||||
#include "fmt.h"
|
||||
#include "gdb/server.h"
|
||||
#include "minisoc.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
typedef struct ProcessInfo
|
||||
{
|
||||
u32 pid;
|
||||
u64 titleId;
|
||||
char name[8];
|
||||
bool isZombie;
|
||||
} ProcessInfo;
|
||||
|
||||
static ProcessInfo infos[0x40] = {0}, infosPrev[0x40] = {0};
|
||||
extern GDBServer gdbServer;
|
||||
|
||||
static inline int ProcessListMenu_FormatInfoLine(char *out, const ProcessInfo *info)
|
||||
{
|
||||
const char *checkbox;
|
||||
u32 id;
|
||||
for(id = 0; id < MAX_DEBUG && (!(gdbServer.ctxs[id].flags & GDB_FLAG_SELECTED) || gdbServer.ctxs[id].pid != info->pid); id++);
|
||||
checkbox = !gdbServer.super.running ? "" : (id < MAX_DEBUG ? "(x) " : "( ) ");
|
||||
|
||||
char commentBuf[23 + 1] = { 0 }; // exactly the size of "Remote: 255.255.255.255"
|
||||
memset(commentBuf, ' ', 23);
|
||||
|
||||
if(info->isZombie)
|
||||
memcpy(commentBuf, "Zombie", 7);
|
||||
|
||||
else if(gdbServer.super.running && id < MAX_DEBUG)
|
||||
{
|
||||
if(gdbServer.ctxs[id].state >= GDB_STATE_CONNECTED && gdbServer.ctxs[id].state < GDB_STATE_CLOSING)
|
||||
{
|
||||
u8 *addr = (u8 *)&gdbServer.ctxs[id].super.addr_in.sin_addr;
|
||||
checkbox = "(A) ";
|
||||
sprintf(commentBuf, "Remote: %hhu.%hhu.%hhu.%hhu", addr[0], addr[1], addr[2], addr[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkbox = "(W) ";
|
||||
sprintf(commentBuf, "Port: %d", GDB_PORT_BASE + id);
|
||||
}
|
||||
}
|
||||
|
||||
return sprintf(out, "%s%-4u %-8.8s %s", checkbox, info->pid, info->name, commentBuf); // Theoritically PIDs are 32-bit ints, but we'll only justify 4 digits
|
||||
}
|
||||
|
||||
static inline void ProcessListMenu_HandleSelected(const ProcessInfo *info)
|
||||
{
|
||||
if(!gdbServer.super.running || info->isZombie)
|
||||
return;
|
||||
|
||||
u32 id;
|
||||
for(id = 0; id < MAX_DEBUG && (!(gdbServer.ctxs[id].flags & GDB_FLAG_SELECTED) || gdbServer.ctxs[id].pid != info->pid); id++);
|
||||
|
||||
GDBContext *ctx = &gdbServer.ctxs[id];
|
||||
|
||||
if(id < MAX_DEBUG)
|
||||
{
|
||||
if(ctx->flags & GDB_FLAG_USED)
|
||||
{
|
||||
RecursiveLock_Lock(&ctx->lock);
|
||||
ctx->super.should_close = true;
|
||||
RecursiveLock_Unlock(&ctx->lock);
|
||||
|
||||
while(ctx->super.should_close)
|
||||
svcSleepThread(12 * 1000 * 1000LL);
|
||||
}
|
||||
else
|
||||
{
|
||||
RecursiveLock_Lock(&ctx->lock);
|
||||
ctx->flags &= ~GDB_FLAG_SELECTED;
|
||||
RecursiveLock_Unlock(&ctx->lock);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(id = 0; id < MAX_DEBUG && gdbServer.ctxs[id].flags & GDB_FLAG_SELECTED; id++);
|
||||
if(id < MAX_DEBUG)
|
||||
{
|
||||
ctx = &gdbServer.ctxs[id];
|
||||
RecursiveLock_Lock(&ctx->lock);
|
||||
ctx->pid = info->pid;
|
||||
ctx->flags |= GDB_FLAG_SELECTED;
|
||||
RecursiveLock_Unlock(&ctx->lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s32 ProcessListMenu_FetchInfo(void)
|
||||
{
|
||||
u32 pidList[0x40];
|
||||
s32 processAmount;
|
||||
|
||||
svcGetProcessList(&processAmount, pidList, 0x40);
|
||||
|
||||
for(s32 i = 0; i < processAmount; i++)
|
||||
{
|
||||
Handle processHandle;
|
||||
Result res = svcOpenProcess(&processHandle, pidList[i]);
|
||||
if(R_FAILED(res))
|
||||
continue;
|
||||
|
||||
infos[i].pid = pidList[i];
|
||||
svcGetProcessInfo((s64 *)&infos[i].name, processHandle, 0x10000);
|
||||
svcGetProcessInfo((s64 *)&infos[i].titleId, processHandle, 0x10001);
|
||||
infos[i].isZombie = svcWaitSynchronization(processHandle, 0) == 0;
|
||||
svcCloseHandle(processHandle);
|
||||
}
|
||||
|
||||
return processAmount;
|
||||
}
|
||||
|
||||
void RosalinaMenu_ProcessList(void)
|
||||
{
|
||||
s32 processAmount = ProcessListMenu_FetchInfo();
|
||||
s32 selected = 0, page = 0, pagePrev = 0;
|
||||
nfds_t nfdsPrev;
|
||||
|
||||
do
|
||||
{
|
||||
nfdsPrev = gdbServer.super.nfds;
|
||||
memcpy(infosPrev, infos, sizeof(infos));
|
||||
|
||||
Draw_Lock();
|
||||
if(page != pagePrev)
|
||||
Draw_ClearFramebuffer();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Process list");
|
||||
|
||||
if(gdbServer.super.running)
|
||||
{
|
||||
char ipBuffer[17];
|
||||
u32 ip = gethostid();
|
||||
u8 *addr = (u8 *)&ip;
|
||||
int n = sprintf(ipBuffer, "%hhu.%hhu.%hhu.%hhu", addr[0], addr[1], addr[2], addr[3]);
|
||||
Draw_DrawString(SCREEN_BOT_WIDTH - 10 - SPACING_X * n, 10, COLOR_WHITE, ipBuffer);
|
||||
}
|
||||
|
||||
|
||||
for(s32 i = 0; i < PROCESSES_PER_MENU_PAGE && page * PROCESSES_PER_MENU_PAGE + i < processAmount; i++)
|
||||
{
|
||||
char buf[65] = {0};
|
||||
ProcessListMenu_FormatInfoLine(buf, &infos[page * PROCESSES_PER_MENU_PAGE + i]);
|
||||
|
||||
Draw_DrawString(30, 30 + i * SPACING_Y, COLOR_WHITE, buf);
|
||||
Draw_DrawCharacter(10, 30 + i * SPACING_Y, COLOR_TITLE, page * PROCESSES_PER_MENU_PAGE + i == selected ? '>' : ' ');
|
||||
}
|
||||
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
|
||||
if(terminationRequest)
|
||||
break;
|
||||
|
||||
u32 pressed;
|
||||
do
|
||||
{
|
||||
pressed = waitInputWithTimeout(50);
|
||||
if(pressed != 0 || nfdsPrev != gdbServer.super.nfds)
|
||||
break;
|
||||
processAmount = ProcessListMenu_FetchInfo();
|
||||
if(memcmp(infos, infosPrev, sizeof(infos)) != 0)
|
||||
break;
|
||||
}
|
||||
while(pressed == 0 && !terminationRequest);
|
||||
|
||||
if(pressed & BUTTON_B)
|
||||
break;
|
||||
else if(pressed & BUTTON_A)
|
||||
ProcessListMenu_HandleSelected(&infos[selected]);
|
||||
else if(pressed & BUTTON_DOWN)
|
||||
selected++;
|
||||
else if(pressed & BUTTON_UP)
|
||||
selected--;
|
||||
else if(pressed & BUTTON_LEFT)
|
||||
selected -= PROCESSES_PER_MENU_PAGE;
|
||||
else if(pressed & BUTTON_RIGHT)
|
||||
{
|
||||
if(selected + PROCESSES_PER_MENU_PAGE < processAmount)
|
||||
selected += PROCESSES_PER_MENU_PAGE;
|
||||
else if((processAmount - 1) / PROCESSES_PER_MENU_PAGE == page)
|
||||
selected %= PROCESSES_PER_MENU_PAGE;
|
||||
else
|
||||
selected = processAmount - 1;
|
||||
}
|
||||
|
||||
if(selected < 0)
|
||||
selected = processAmount - 1;
|
||||
else if(selected >= processAmount)
|
||||
selected = 0;
|
||||
|
||||
pagePrev = page;
|
||||
page = selected / PROCESSES_PER_MENU_PAGE;
|
||||
}
|
||||
while(!terminationRequest);
|
||||
}
|
||||
183
sysmodules/rosalina/source/menus/process_patches.c
Normal file
183
sysmodules/rosalina/source/menus/process_patches.c
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
#include "csvc.h"
|
||||
#include "menus/process_patches.h"
|
||||
#include "memory.h"
|
||||
#include "draw.h"
|
||||
#include "hbloader.h"
|
||||
#include "fmt.h"
|
||||
#include "utils.h"
|
||||
|
||||
Menu processPatchesMenu = {
|
||||
"Process patches menu",
|
||||
.nbItems = 2,
|
||||
{
|
||||
{ "Patch SM for the service checks", METHOD, .method = &ProcessPatchesMenu_PatchUnpatchSM },
|
||||
{ "Patch FS for the archive checks", METHOD, .method = &ProcessPatchesMenu_PatchUnpatchFS },
|
||||
}
|
||||
};
|
||||
|
||||
static Result ProcessPatchesMenu_DoPatchUnpatchSM(u32 textTotalRoundedSize)
|
||||
{
|
||||
static bool patched = false;
|
||||
static u32 *off;
|
||||
static u32 origData[7];
|
||||
|
||||
if(patched)
|
||||
{
|
||||
memcpy(off, &origData, sizeof(origData));
|
||||
patched = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(off = (u32 *)0x00100000; off < (u32 *)(0x00100000 + textTotalRoundedSize) - 6 &&
|
||||
(off[0] != 0xE1A01006 || off[1] != 0xE1A00005 || off[3] != 0xE3500000 || off[6] != 0xE2850004);
|
||||
off++);
|
||||
|
||||
if(off >= (u32 *)(0x00100000 + textTotalRoundedSize) - 6)
|
||||
return -1;
|
||||
|
||||
memcpy(&origData, off, sizeof(origData));
|
||||
|
||||
off[2] = off[3] = off[4] = off[5] = 0xE320F000; // nop
|
||||
patched = true;
|
||||
}
|
||||
|
||||
processPatchesMenu.items[0].title = patched ? "Unpatch SM for the service checks" : "Patch SM for the service checks";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Result ProcessPatchesMenu_DoPatchUnpatchFS(u32 textTotalRoundedSize)
|
||||
{
|
||||
static bool patched = false;
|
||||
static u16 *off;
|
||||
static const u16 origData[2] = {
|
||||
0x4618, // mov r0, r3
|
||||
0x3481, // adds r4, #0x81
|
||||
};
|
||||
|
||||
if(patched)
|
||||
{
|
||||
memcpy(off, &origData, sizeof(origData));
|
||||
patched = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
off = (u16 *)memsearch((u8 *)0x00100000, &origData, textTotalRoundedSize, sizeof(origData));
|
||||
if(off == NULL)
|
||||
return -1;
|
||||
|
||||
off[0] = 0x2001; // mov r0, #1
|
||||
off[1] = 0x4770; // bx lr
|
||||
|
||||
patched = true;
|
||||
}
|
||||
|
||||
processPatchesMenu.items[1].title = patched ? "Unpatch FS for the archive checks" : "Patch FS for the archive checks";
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result OpenProcessByName(const char *name, Handle *h)
|
||||
{
|
||||
u32 pidList[0x40];
|
||||
s32 processCount;
|
||||
svcGetProcessList(&processCount, pidList, 0x40);
|
||||
Handle dstProcessHandle = 0;
|
||||
|
||||
for(s32 i = 0; i < processCount; i++)
|
||||
{
|
||||
Handle processHandle;
|
||||
Result res = svcOpenProcess(&processHandle, pidList[i]);
|
||||
if(R_FAILED(res))
|
||||
continue;
|
||||
|
||||
char procName[8] = {0};
|
||||
svcGetProcessInfo((s64 *)procName, processHandle, 0x10000);
|
||||
if(strncmp(procName, name, 8) == 0)
|
||||
dstProcessHandle = processHandle;
|
||||
else
|
||||
svcCloseHandle(processHandle);
|
||||
}
|
||||
|
||||
if(dstProcessHandle == 0)
|
||||
return -1;
|
||||
|
||||
*h = dstProcessHandle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 ProcessPatchesMenu_PatchUnpatchProcessByName(const char *name, Result (*func)(u32 size))
|
||||
{
|
||||
Result res;
|
||||
Handle processHandle;
|
||||
OpenProcessByName(name, &processHandle);
|
||||
|
||||
s64 textTotalRoundedSize = 0, startAddress = 0;
|
||||
svcGetProcessInfo(&textTotalRoundedSize, processHandle, 0x10002); // only patch .text
|
||||
svcGetProcessInfo(&startAddress, processHandle, 0x10005);
|
||||
if(R_FAILED(res = svcMapProcessMemoryEx(processHandle, 0x00100000, (u32) startAddress, textTotalRoundedSize)))
|
||||
return res;
|
||||
|
||||
res = func(textTotalRoundedSize);
|
||||
|
||||
svcUnmapProcessMemory(processHandle, 0x00100000, textTotalRoundedSize);
|
||||
return res;
|
||||
}
|
||||
|
||||
static void ProcessPatchesMenu_PatchUnpatchProcess(const char *processName, Result (*func)(u32 size))
|
||||
{
|
||||
Draw_Lock();
|
||||
Draw_ClearFramebuffer();
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
|
||||
Result res = ProcessPatchesMenu_PatchUnpatchProcessByName(processName, func);
|
||||
|
||||
do
|
||||
{
|
||||
Draw_Lock();
|
||||
Draw_DrawString(10, 10, COLOR_TITLE, "Process patches menu");
|
||||
if(R_SUCCEEDED(res))
|
||||
Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded.");
|
||||
else
|
||||
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08x).", res);
|
||||
Draw_FlushFramebuffer();
|
||||
Draw_Unlock();
|
||||
}
|
||||
while(!(waitInput() & BUTTON_B) && !terminationRequest);
|
||||
}
|
||||
|
||||
void ProcessPatchesMenu_PatchUnpatchSM(void)
|
||||
{
|
||||
ProcessPatchesMenu_PatchUnpatchProcess("sm", &ProcessPatchesMenu_DoPatchUnpatchSM);
|
||||
}
|
||||
|
||||
void ProcessPatchesMenu_PatchUnpatchFS(void)
|
||||
{
|
||||
ProcessPatchesMenu_PatchUnpatchProcess("fs", &ProcessPatchesMenu_DoPatchUnpatchFS);
|
||||
}
|
||||
Reference in New Issue
Block a user