dmnt: Skeleton real process implementation.

This commit is contained in:
Michael Scire 2018-12-05 23:35:09 -08:00
parent 588315f877
commit 94e527e763
3 changed files with 183 additions and 2 deletions

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2018 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 <switch.h>
#include "dmnt_debug_monitor.hpp"
Result DebugMonitorService::BreakDebugProcess(Handle debug_hnd) {
/* Nintendo discards the output of this command, but we will return it. */
return svcBreakDebugProcess(debug_hnd);
}
Result DebugMonitorService::TerminateDebugProcess(Handle debug_hnd) {
/* Nintendo discards the output of this command, but we will return it. */
return svcTerminateDebugProcess(debug_hnd);
}
Result DebugMonitorService::CloseHandle(Handle debug_hnd) {
/* Nintendo discards the output of this command, but we will return it. */
/* This command is, entertainingly, also pretty unsafe in general... */
return svcCloseHandle(debug_hnd);
}

View file

@ -0,0 +1,136 @@
/*
* Copyright (c) 2018 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
enum DmntCmd {
DebugMonitor_Cmd_BreakDebugProcess = 0,
DebugMonitor_Cmd_TerminateDebugProcess = 1,
DebugMonitor_Cmd_CloseHandle = 2,
DebugMonitor_Cmd_LoadImage = 3,
DebugMonitor_Cmd_GetProcessId = 4,
DebugMonitor_Cmd_GetProcessHandle = 5,
DebugMonitor_Cmd_WaitSynchronization = 6,
DebugMonitor_Cmd_GetDebugEvent = 7,
DebugMonitor_Cmd_GetProcessModuleInfo = 8,
DebugMonitor_Cmd_GetProcessList = 9,
DebugMonitor_Cmd_GetThreadList = 10,
DebugMonitor_Cmd_GetDebugThreadContext = 11,
DebugMonitor_Cmd_ContinueDebugEvent = 12,
DebugMonitor_Cmd_ReadDebugProcessMemory = 13,
DebugMonitor_Cmd_WriteDebugProcessMemory = 14,
DebugMonitor_Cmd_SetDebugThreadContext = 15,
DebugMonitor_Cmd_GetDebugThreadParam = 16,
DebugMonitor_Cmd_InitializeThreadInfo = 17,
DebugMonitor_Cmd_SetHardwareBreakPoint = 18,
DebugMonitor_Cmd_QueryDebugProcessMemory = 19,
DebugMonitor_Cmd_GetProcessMemoryDetails = 20,
DebugMonitor_Cmd_AttachByProgramId = 21,
DebugMonitor_Cmd_AttachOnLaunch = 22,
DebugMonitor_Cmd_GetDebugMonitorProcessId = 23,
DebugMonitor_Cmd_GetJitDebugProcessList = 25,
DebugMonitor_Cmd_CreateCoreDump = 26,
DebugMonitor_Cmd_GetAllDebugThreadInfo = 27,
DebugMonitor_Cmd_TargetIO_FileOpen = 29,
DebugMonitor_Cmd_TargetIO_FileClose = 30,
DebugMonitor_Cmd_TargetIO_FileRead = 31,
DebugMonitor_Cmd_TargetIO_FileWrite = 32,
DebugMonitor_Cmd_TargetIO_FileSetAttributes = 33,
DebugMonitor_Cmd_TargetIO_FileGetInformation = 34,
DebugMonitor_Cmd_TargetIO_FileSetTime = 35,
DebugMonitor_Cmd_TargetIO_FileSetSize = 36,
DebugMonitor_Cmd_TargetIO_FileDelete = 37,
DebugMonitor_Cmd_TargetIO_FileMove = 38,
DebugMonitor_Cmd_TargetIO_DirectoryCreate = 39,
DebugMonitor_Cmd_TargetIO_DirectoryDelete = 40,
DebugMonitor_Cmd_TargetIO_DirectoryRename = 41,
DebugMonitor_Cmd_TargetIO_DirectoryGetCount = 42,
DebugMonitor_Cmd_TargetIO_DirectoryOpen = 43,
DebugMonitor_Cmd_TargetIO_DirectoryGetNext = 44,
DebugMonitor_Cmd_TargetIO_DirectoryClose = 45,
DebugMonitor_Cmd_TargetIO_GetFreeSpace = 46,
DebugMonitor_Cmd_TargetIO_GetVolumeInformation = 47,
DebugMonitor_Cmd_InitiateCoreDump = 48,
DebugMonitor_Cmd_ContinueCoreDump = 49,
DebugMonitor_Cmd_AddTTYToCoreDump = 50,
DebugMonitor_Cmd_AddImageToCoreDump = 51,
DebugMonitor_Cmd_CloseCoreDump = 52,
DebugMonitor_Cmd_CancelAttach = 53,
};
class DebugMonitorService final : public IServiceObject {
private:
Result BreakDebugProcess(Handle debug_hnd);
Result TerminateDebugProcess(Handle debug_hnd);
Result CloseHandle(Handle debug_hnd);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MakeServiceCommandMeta<DebugMonitor_Cmd_BreakDebugProcess, &DebugMonitorService::BreakDebugProcess>(),
MakeServiceCommandMeta<DebugMonitor_Cmd_TerminateDebugProcess, &DebugMonitorService::TerminateDebugProcess>(),
MakeServiceCommandMeta<DebugMonitor_Cmd_CloseHandle, &DebugMonitorService::CloseHandle>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_LoadImage, &DebugMonitorService::LoadImage>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetProcessId, &DebugMonitorService::GetProcessId>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetProcessHandle, &DebugMonitorService::GetProcessHandle>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_WaitSynchronization, &DebugMonitorService::WaitSynchronization>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetDebugEvent, &DebugMonitorService::GetDebugEvent>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetProcessModuleInfo, &DebugMonitorService::GetProcessModuleInfo>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetProcessList, &DebugMonitorService::GetProcessList>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetThreadList, &DebugMonitorService::GetThreadList>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetDebugThreadContext, &DebugMonitorService::GetDebugThreadContext>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_ContinueDebugEvent, &DebugMonitorService::ContinueDebugEvent>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_ReadDebugProcessMemory, &DebugMonitorService::ReadDebugProcessMemory>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_WriteDebugProcessMemory, &DebugMonitorService::WriteDebugProcessMemory>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_SetDebugThreadContext, &DebugMonitorService::SetDebugThreadContext>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetDebugThreadParam, &DebugMonitorService::GetDebugThreadParam>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_InitializeThreadInfo, &DebugMonitorService::InitializeThreadInfo>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_SetHardwareBreakPoint, &DebugMonitorService::SetHardwareBreakPoint>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_QueryDebugProcessMemory, &DebugMonitorService::QueryDebugProcessMemory>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetProcessMemoryDetails, &DebugMonitorService::GetProcessMemoryDetails>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_AttachByProgramId, &DebugMonitorService::AttachByProgramId>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_AttachOnLaunch, &DebugMonitorService::AttachOnLaunch>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetDebugMonitorProcessId, &DebugMonitorService::GetDebugMonitorProcessId>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetJitDebugProcessList, &DebugMonitorService::GetJitDebugProcessList>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_CreateCoreDump, &DebugMonitorService::CreateCoreDump>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_GetAllDebugThreadInfo, &DebugMonitorService::GetAllDebugThreadInfo>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileOpen, &DebugMonitorService::TargetIO_FileOpen>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileClose, &DebugMonitorService::TargetIO_FileClose>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileRead, &DebugMonitorService::TargetIO_FileRead>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileWrite, &DebugMonitorService::TargetIO_FileWrite>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileSetAttributes, &DebugMonitorService::TargetIO_FileSetAttributes>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileGetInformation, &DebugMonitorService::TargetIO_FileGetInformation>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileSetTime, &DebugMonitorService::TargetIO_FileSetTime>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileSetSize, &DebugMonitorService::TargetIO_FileSetSize>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileDelete, &DebugMonitorService::TargetIO_FileDelete>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_FileMove, &DebugMonitorService::TargetIO_FileMove>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_DirectoryCreate, &DebugMonitorService::TargetIO_DirectoryCreate>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_DirectoryDelete, &DebugMonitorService::TargetIO_DirectoryDelete>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_DirectoryRename, &DebugMonitorService::TargetIO_DirectoryRename>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_DirectoryGetCount, &DebugMonitorService::TargetIO_DirectoryGetCount>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_DirectoryOpen, &DebugMonitorService::TargetIO_DirectoryOpen>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_DirectoryGetNext, &DebugMonitorService::TargetIO_DirectoryGetNext>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_DirectoryClose, &DebugMonitorService::TargetIO_DirectoryClose>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_GetFreeSpace, &DebugMonitorService::TargetIO_GetFreeSpace>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_TargetIO_GetVolumeInformation, &DebugMonitorService::TargetIO_GetVolumeInformation>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_InitiateCoreDump, &DebugMonitorService::InitiateCoreDump>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_ContinueCoreDump, &DebugMonitorService::ContinueCoreDump>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_AddTTYToCoreDump, &DebugMonitorService::AddTTYToCoreDump>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_AddImageToCoreDump, &DebugMonitorService::AddImageToCoreDump>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_CloseCoreDump, &DebugMonitorService::CloseCoreDump>(),
// MakeServiceCommandMeta<DebugMonitor_Cmd_CancelAttach, &DebugMonitorService::CancelAttach>(),
};
};

View file

@ -23,6 +23,8 @@
#include <atmosphere.h> #include <atmosphere.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "dmnt_debug_monitor.hpp"
extern "C" { extern "C" {
extern u32 __start__; extern u32 __start__;
@ -121,8 +123,17 @@ void __appExit(void) {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
consoleDebugInit(debugDevice_SVC); consoleDebugInit(debugDevice_SVC);
/* TODO: Make a server manager, and process on it. */ /* Nintendo uses four threads. */
auto server_manager = new WaitableManager(4);
/* Create services. */
server_manager->AddWaitable(new ServiceServer<DebugMonitorService>("dmnt:-", 4));
/* Loop forever, servicing our services. */
server_manager->Process();
delete server_manager;
return 0; return 0;
} }