From 809090e40dc4832913b7def3e86804c91754c0e4 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 22 Apr 2018 01:13:36 -0600 Subject: [PATCH] Stratosphere: Fix smhax. --- stratosphere/sm/source/sm_main.cpp | 4 ++-- stratosphere/sm/source/sm_user_service.cpp | 17 ++++++++++++++--- stratosphere/sm/source/sm_user_service.hpp | 5 ++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index 113b3d6bb..0556c538b 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -53,11 +53,11 @@ int main(int argc, char **argv) WaitableManager *server_manager = new WaitableManager(U64_MAX); /* Create sm:, (and thus allow things to register to it). */ - server_manager->add_waitable(new ManagedPortServer("sm:", 0x40)); + server_manager->add_waitable(new ManagedPortServer("dbg:", 0x40)); /* Create sm:m manually. */ Handle smm_h; - if (R_FAILED(Registration::RegisterServiceForSelf(smEncodeName("sm:m"), 1, false, &smm_h))) { + if (R_FAILED(Registration::RegisterServiceForSelf(smEncodeName("dbg:m"), 1, false, &smm_h))) { /* TODO: Panic. */ } diff --git a/stratosphere/sm/source/sm_user_service.cpp b/stratosphere/sm/source/sm_user_service.cpp index 44726aa1c..78652366d 100644 --- a/stratosphere/sm/source/sm_user_service.cpp +++ b/stratosphere/sm/source/sm_user_service.cpp @@ -27,21 +27,32 @@ Result UserService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, std::tuple UserService::initialize(PidDescriptor pid) { this->pid = pid.pid; + this->has_initialized = true; return std::make_tuple(0); } std::tuple UserService::get_service(u64 service) { Handle session_h = 0; - Result rc = Registration::GetServiceForPid(this->pid, service, &session_h); + Result rc = 0x415; + if (this->has_initialized) { + rc = Registration::GetServiceForPid(this->pid, service, &session_h); + } return std::make_tuple(rc, MovedHandle{session_h}); } std::tuple UserService::register_service(u64 service, u8 is_light, u32 max_sessions) { Handle service_h = 0; - Result rc = Registration::RegisterServiceForPid(this->pid, service, max_sessions, is_light != 0, &service_h); + Result rc = 0x415; + if (this->has_initialized) { + rc = Registration::RegisterServiceForPid(this->pid, service, max_sessions, is_light != 0, &service_h); + } return std::make_tuple(rc, MovedHandle{service_h}); } std::tuple UserService::unregister_service(u64 service) { - return std::make_tuple(Registration::UnregisterServiceForPid(this->pid, service)); + Result rc = 0x415; + if (this->has_initialized) { + rc = Registration::UnregisterServiceForPid(this->pid, service); + } + return std::make_tuple(rc); } diff --git a/stratosphere/sm/source/sm_user_service.hpp b/stratosphere/sm/source/sm_user_service.hpp index f01d14acd..1bcfddc6c 100644 --- a/stratosphere/sm/source/sm_user_service.hpp +++ b/stratosphere/sm/source/sm_user_service.hpp @@ -11,12 +11,11 @@ enum UserServiceCmd { class UserService : IServiceObject { u64 pid; + bool has_initialized; public: Result dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size); - UserService() { - this->pid = U64_MAX; - } + UserService() : pid(U64_MAX), has_initialized(false) { } private: /* Actual commands. */