#pragma once #include #include #include "sm_mitm.h" #include "mitm_session.hpp" #include "debug.hpp" template class MitMSession; template class MitMServer final : public IServer { static_assert(std::is_base_of::value, "Service Objects must derive from IServiceObject"); private: char mitm_name[9]; public: MitMServer(const char *service_name, unsigned int max_s, bool s_d = false) : IServer(service_name, max_s, s_d) { Handle tmp_hnd; Result rc; if (R_SUCCEEDED((rc = smGetServiceOriginal(&tmp_hnd, smEncodeName(service_name))))) { svcCloseHandle(tmp_hnd); } else { fatalSimple(rc); } strncpy(mitm_name, service_name, 8); mitm_name[8] = '\x00'; if (R_FAILED((rc = smMitMInstall(&this->port_handle, mitm_name)))) { fatalSimple(rc); } } virtual ~MitMServer() { if (this->port_handle) { if (R_FAILED(smMitMUninstall(this->mitm_name))) { /* TODO: Panic. */ } /* svcCloseHandle(port_handle); was called by ~IServer. */ } } ISession *get_new_session(Handle session_h) override { return new MitMSession(this, session_h, 0, mitm_name); } };