ns.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/logging/log.h"
  5. #include "core/file_sys/control_metadata.h"
  6. #include "core/file_sys/patch_manager.h"
  7. #include "core/hle/ipc_helpers.h"
  8. #include "core/hle/kernel/hle_ipc.h"
  9. #include "core/hle/service/ns/errors.h"
  10. #include "core/hle/service/ns/language.h"
  11. #include "core/hle/service/ns/ns.h"
  12. #include "core/hle/service/ns/pl_u.h"
  13. #include "core/hle/service/set/set.h"
  14. #include "core/settings.h"
  15. namespace Service::NS {
  16. IAccountProxyInterface::IAccountProxyInterface() : ServiceFramework{"IAccountProxyInterface"} {
  17. // clang-format off
  18. static const FunctionInfo functions[] = {
  19. {0, nullptr, "CreateUserAccount"},
  20. };
  21. // clang-format on
  22. RegisterHandlers(functions);
  23. }
  24. IAccountProxyInterface::~IAccountProxyInterface() = default;
  25. IApplicationManagerInterface::IApplicationManagerInterface()
  26. : ServiceFramework{"IApplicationManagerInterface"} {
  27. // clang-format off
  28. static const FunctionInfo functions[] = {
  29. {0, nullptr, "ListApplicationRecord"},
  30. {1, nullptr, "GenerateApplicationRecordCount"},
  31. {2, nullptr, "GetApplicationRecordUpdateSystemEvent"},
  32. {3, nullptr, "GetApplicationViewDeprecated"},
  33. {4, nullptr, "DeleteApplicationEntity"},
  34. {5, nullptr, "DeleteApplicationCompletely"},
  35. {6, nullptr, "IsAnyApplicationEntityRedundant"},
  36. {7, nullptr, "DeleteRedundantApplicationEntity"},
  37. {8, nullptr, "IsApplicationEntityMovable"},
  38. {9, nullptr, "MoveApplicationEntity"},
  39. {11, nullptr, "CalculateApplicationOccupiedSize"},
  40. {16, nullptr, "PushApplicationRecord"},
  41. {17, nullptr, "ListApplicationRecordContentMeta"},
  42. {19, nullptr, "LaunchApplicationOld"},
  43. {21, nullptr, "GetApplicationContentPath"},
  44. {22, nullptr, "TerminateApplication"},
  45. {23, nullptr, "ResolveApplicationContentPath"},
  46. {26, nullptr, "BeginInstallApplication"},
  47. {27, nullptr, "DeleteApplicationRecord"},
  48. {30, nullptr, "RequestApplicationUpdateInfo"},
  49. {32, nullptr, "CancelApplicationDownload"},
  50. {33, nullptr, "ResumeApplicationDownload"},
  51. {35, nullptr, "UpdateVersionList"},
  52. {36, nullptr, "PushLaunchVersion"},
  53. {37, nullptr, "ListRequiredVersion"},
  54. {38, nullptr, "CheckApplicationLaunchVersion"},
  55. {39, nullptr, "CheckApplicationLaunchRights"},
  56. {40, nullptr, "GetApplicationLogoData"},
  57. {41, nullptr, "CalculateApplicationDownloadRequiredSize"},
  58. {42, nullptr, "CleanupSdCard"},
  59. {43, nullptr, "CheckSdCardMountStatus"},
  60. {44, nullptr, "GetSdCardMountStatusChangedEvent"},
  61. {45, nullptr, "GetGameCardAttachmentEvent"},
  62. {46, nullptr, "GetGameCardAttachmentInfo"},
  63. {47, nullptr, "GetTotalSpaceSize"},
  64. {48, nullptr, "GetFreeSpaceSize"},
  65. {49, nullptr, "GetSdCardRemovedEvent"},
  66. {52, nullptr, "GetGameCardUpdateDetectionEvent"},
  67. {53, nullptr, "DisableApplicationAutoDelete"},
  68. {54, nullptr, "EnableApplicationAutoDelete"},
  69. {55, &IApplicationManagerInterface::GetApplicationDesiredLanguage, "GetApplicationDesiredLanguage"},
  70. {56, nullptr, "SetApplicationTerminateResult"},
  71. {57, nullptr, "ClearApplicationTerminateResult"},
  72. {58, nullptr, "GetLastSdCardMountUnexpectedResult"},
  73. {59, &IApplicationManagerInterface::ConvertApplicationLanguageToLanguageCode, "ConvertApplicationLanguageToLanguageCode"},
  74. {60, nullptr, "ConvertLanguageCodeToApplicationLanguage"},
  75. {61, nullptr, "GetBackgroundDownloadStressTaskInfo"},
  76. {62, nullptr, "GetGameCardStopper"},
  77. {63, nullptr, "IsSystemProgramInstalled"},
  78. {64, nullptr, "StartApplyDeltaTask"},
  79. {65, nullptr, "GetRequestServerStopper"},
  80. {66, nullptr, "GetBackgroundApplyDeltaStressTaskInfo"},
  81. {67, nullptr, "CancelApplicationApplyDelta"},
  82. {68, nullptr, "ResumeApplicationApplyDelta"},
  83. {69, nullptr, "CalculateApplicationApplyDeltaRequiredSize"},
  84. {70, nullptr, "ResumeAll"},
  85. {71, nullptr, "GetStorageSize"},
  86. {80, nullptr, "RequestDownloadApplication"},
  87. {81, nullptr, "RequestDownloadAddOnContent"},
  88. {82, nullptr, "DownloadApplication"},
  89. {83, nullptr, "CheckApplicationResumeRights"},
  90. {84, nullptr, "GetDynamicCommitEvent"},
  91. {85, nullptr, "RequestUpdateApplication2"},
  92. {86, nullptr, "EnableApplicationCrashReport"},
  93. {87, nullptr, "IsApplicationCrashReportEnabled"},
  94. {90, nullptr, "BoostSystemMemoryResourceLimit"},
  95. {91, nullptr, "DeprecatedLaunchApplication"},
  96. {92, nullptr, "GetRunningApplicationProgramId"},
  97. {93, nullptr, "GetMainApplicationProgramIndex"},
  98. {94, nullptr, "LaunchApplication"},
  99. {95, nullptr, "GetApplicationLaunchInfo"},
  100. {96, nullptr, "AcquireApplicationLaunchInfo"},
  101. {97, nullptr, "GetMainApplicationProgramIndex2"},
  102. {98, nullptr, "EnableApplicationAllThreadDumpOnCrash"},
  103. {100, nullptr, "ResetToFactorySettings"},
  104. {101, nullptr, "ResetToFactorySettingsWithoutUserSaveData"},
  105. {102, nullptr, "ResetToFactorySettingsForRefurbishment"},
  106. {200, nullptr, "CalculateUserSaveDataStatistics"},
  107. {201, nullptr, "DeleteUserSaveDataAll"},
  108. {210, nullptr, "DeleteUserSystemSaveData"},
  109. {211, nullptr, "DeleteSaveData"},
  110. {220, nullptr, "UnregisterNetworkServiceAccount"},
  111. {221, nullptr, "UnregisterNetworkServiceAccountWithUserSaveDataDeletion"},
  112. {300, nullptr, "GetApplicationShellEvent"},
  113. {301, nullptr, "PopApplicationShellEventInfo"},
  114. {302, nullptr, "LaunchLibraryApplet"},
  115. {303, nullptr, "TerminateLibraryApplet"},
  116. {304, nullptr, "LaunchSystemApplet"},
  117. {305, nullptr, "TerminateSystemApplet"},
  118. {306, nullptr, "LaunchOverlayApplet"},
  119. {307, nullptr, "TerminateOverlayApplet"},
  120. {400, &IApplicationManagerInterface::GetApplicationControlData, "GetApplicationControlData"},
  121. {401, nullptr, "InvalidateAllApplicationControlCache"},
  122. {402, nullptr, "RequestDownloadApplicationControlData"},
  123. {403, nullptr, "GetMaxApplicationControlCacheCount"},
  124. {404, nullptr, "InvalidateApplicationControlCache"},
  125. {405, nullptr, "ListApplicationControlCacheEntryInfo"},
  126. {406, nullptr, "GetApplicationControlProperty"},
  127. {502, nullptr, "RequestCheckGameCardRegistration"},
  128. {503, nullptr, "RequestGameCardRegistrationGoldPoint"},
  129. {504, nullptr, "RequestRegisterGameCard"},
  130. {505, nullptr, "GetGameCardMountFailureEvent"},
  131. {506, nullptr, "IsGameCardInserted"},
  132. {507, nullptr, "EnsureGameCardAccess"},
  133. {508, nullptr, "GetLastGameCardMountFailureResult"},
  134. {509, nullptr, "ListApplicationIdOnGameCard"},
  135. {600, nullptr, "CountApplicationContentMeta"},
  136. {601, nullptr, "ListApplicationContentMetaStatus"},
  137. {602, nullptr, "ListAvailableAddOnContent"},
  138. {603, nullptr, "GetOwnedApplicationContentMetaStatus"},
  139. {604, nullptr, "RegisterContentsExternalKey"},
  140. {605, nullptr, "ListApplicationContentMetaStatusWithRightsCheck"},
  141. {606, nullptr, "GetContentMetaStorage"},
  142. {607, nullptr, "ListAvailableAddOnContent"},
  143. {700, nullptr, "PushDownloadTaskList"},
  144. {701, nullptr, "ClearTaskStatusList"},
  145. {702, nullptr, "RequestDownloadTaskList"},
  146. {703, nullptr, "RequestEnsureDownloadTask"},
  147. {704, nullptr, "ListDownloadTaskStatus"},
  148. {705, nullptr, "RequestDownloadTaskListData"},
  149. {800, nullptr, "RequestVersionList"},
  150. {801, nullptr, "ListVersionList"},
  151. {802, nullptr, "RequestVersionListData"},
  152. {900, nullptr, "GetApplicationRecord"},
  153. {901, nullptr, "GetApplicationRecordProperty"},
  154. {902, nullptr, "EnableApplicationAutoUpdate"},
  155. {903, nullptr, "DisableApplicationAutoUpdate"},
  156. {904, nullptr, "TouchApplication"},
  157. {905, nullptr, "RequestApplicationUpdate"},
  158. {906, nullptr, "IsApplicationUpdateRequested"},
  159. {907, nullptr, "WithdrawApplicationUpdateRequest"},
  160. {908, nullptr, "ListApplicationRecordInstalledContentMeta"},
  161. {909, nullptr, "WithdrawCleanupAddOnContentsWithNoRightsRecommendation"},
  162. {910, nullptr, "HasApplicationRecord"},
  163. {911, nullptr, "SetPreInstalledApplication"},
  164. {912, nullptr, "ClearPreInstalledApplicationFlag"},
  165. {1000, nullptr, "RequestVerifyApplicationDeprecated"},
  166. {1001, nullptr, "CorruptApplicationForDebug"},
  167. {1002, nullptr, "RequestVerifyAddOnContentsRights"},
  168. {1003, nullptr, "RequestVerifyApplication"},
  169. {1004, nullptr, "CorruptContentForDebug"},
  170. {1200, nullptr, "NeedsUpdateVulnerability"},
  171. {1300, nullptr, "IsAnyApplicationEntityInstalled"},
  172. {1301, nullptr, "DeleteApplicationContentEntities"},
  173. {1302, nullptr, "CleanupUnrecordedApplicationEntity"},
  174. {1303, nullptr, "CleanupAddOnContentsWithNoRights"},
  175. {1304, nullptr, "DeleteApplicationContentEntity"},
  176. {1305, nullptr, "TryDeleteRunningApplicationEntity"},
  177. {1306, nullptr, "TryDeleteRunningApplicationCompletely"},
  178. {1307, nullptr, "TryDeleteRunningApplicationContentEntities"},
  179. {1308, nullptr, "DeleteApplicationCompletelyForDebug"},
  180. {1309, nullptr, "CleanupUnavailableAddOnContents"},
  181. {1400, nullptr, "PrepareShutdown"},
  182. {1500, nullptr, "FormatSdCard"},
  183. {1501, nullptr, "NeedsSystemUpdateToFormatSdCard"},
  184. {1502, nullptr, "GetLastSdCardFormatUnexpectedResult"},
  185. {1504, nullptr, "InsertSdCard"},
  186. {1505, nullptr, "RemoveSdCard"},
  187. {1600, nullptr, "GetSystemSeedForPseudoDeviceId"},
  188. {1601, nullptr, "ResetSystemSeedForPseudoDeviceId"},
  189. {1700, nullptr, "ListApplicationDownloadingContentMeta"},
  190. {1701, nullptr, "GetApplicationView"},
  191. {1702, nullptr, "GetApplicationDownloadTaskStatus"},
  192. {1703, nullptr, "GetApplicationViewDownloadErrorContext"},
  193. {1800, nullptr, "IsNotificationSetupCompleted"},
  194. {1801, nullptr, "GetLastNotificationInfoCount"},
  195. {1802, nullptr, "ListLastNotificationInfo"},
  196. {1803, nullptr, "ListNotificationTask"},
  197. {1900, nullptr, "IsActiveAccount"},
  198. {1901, nullptr, "RequestDownloadApplicationPrepurchasedRights"},
  199. {1902, nullptr, "GetApplicationTicketInfo"},
  200. {2000, nullptr, "GetSystemDeliveryInfo"},
  201. {2001, nullptr, "SelectLatestSystemDeliveryInfo"},
  202. {2002, nullptr, "VerifyDeliveryProtocolVersion"},
  203. {2003, nullptr, "GetApplicationDeliveryInfo"},
  204. {2004, nullptr, "HasAllContentsToDeliver"},
  205. {2005, nullptr, "CompareApplicationDeliveryInfo"},
  206. {2006, nullptr, "CanDeliverApplication"},
  207. {2007, nullptr, "ListContentMetaKeyToDeliverApplication"},
  208. {2008, nullptr, "NeedsSystemUpdateToDeliverApplication"},
  209. {2009, nullptr, "EstimateRequiredSize"},
  210. {2010, nullptr, "RequestReceiveApplication"},
  211. {2011, nullptr, "CommitReceiveApplication"},
  212. {2012, nullptr, "GetReceiveApplicationProgress"},
  213. {2013, nullptr, "RequestSendApplication"},
  214. {2014, nullptr, "GetSendApplicationProgress"},
  215. {2015, nullptr, "CompareSystemDeliveryInfo"},
  216. {2016, nullptr, "ListNotCommittedContentMeta"},
  217. {2017, nullptr, "CreateDownloadTask"},
  218. {2018, nullptr, "GetApplicationDeliveryInfoHash"},
  219. {2050, nullptr, "GetApplicationRightsOnClient"},
  220. {2100, nullptr, "GetApplicationTerminateResult"},
  221. {2101, nullptr, "GetRawApplicationTerminateResult"},
  222. {2150, nullptr, "CreateRightsEnvironment"},
  223. {2151, nullptr, "DestroyRightsEnvironment"},
  224. {2152, nullptr, "ActivateRightsEnvironment"},
  225. {2153, nullptr, "DeactivateRightsEnvironment"},
  226. {2154, nullptr, "ForceActivateRightsContextForExit"},
  227. {2160, nullptr, "AddTargetApplicationToRightsEnvironment"},
  228. {2161, nullptr, "SetUsersToRightsEnvironment"},
  229. {2170, nullptr, "GetRightsEnvironmentStatus"},
  230. {2171, nullptr, "GetRightsEnvironmentStatusChangedEvent"},
  231. {2180, nullptr, "RequestExtendRightsInRightsEnvironment"},
  232. {2181, nullptr, "GetLastResultOfExtendRightsInRightsEnvironment"},
  233. {2182, nullptr, "SetActiveRightsContextUsingStateToRightsEnvironment"},
  234. {2190, nullptr, "GetRightsEnvironmentHandleForApplication"},
  235. {2199, nullptr, "GetRightsEnvironmentCountForDebug"},
  236. {2200, nullptr, "GetGameCardApplicationCopyIdentifier"},
  237. {2201, nullptr, "GetInstalledApplicationCopyIdentifier"},
  238. {2250, nullptr, "RequestReportActiveELicence"},
  239. {2300, nullptr, "ListEventLog"},
  240. };
  241. // clang-format on
  242. RegisterHandlers(functions);
  243. }
  244. IApplicationManagerInterface::~IApplicationManagerInterface() = default;
  245. void IApplicationManagerInterface::GetApplicationControlData(Kernel::HLERequestContext& ctx) {
  246. IPC::RequestParser rp{ctx};
  247. const auto flag = rp.PopRaw<u64>();
  248. LOG_DEBUG(Service_NS, "called with flag={:016X}", flag);
  249. const auto title_id = rp.PopRaw<u64>();
  250. const auto size = ctx.GetWriteBufferSize();
  251. const FileSys::PatchManager pm{title_id};
  252. const auto control = pm.GetControlMetadata();
  253. std::vector<u8> out;
  254. if (control.first != nullptr) {
  255. if (size < 0x4000) {
  256. LOG_ERROR(Service_NS,
  257. "output buffer is too small! (actual={:016X}, expected_min=0x4000)", size);
  258. IPC::ResponseBuilder rb{ctx, 2};
  259. // TODO(DarkLordZach): Find a better error code for this.
  260. rb.Push(ResultCode(-1));
  261. return;
  262. }
  263. out.resize(0x4000);
  264. const auto bytes = control.first->GetRawBytes();
  265. std::memcpy(out.data(), bytes.data(), bytes.size());
  266. } else {
  267. LOG_WARNING(Service_NS, "missing NACP data for title_id={:016X}, defaulting to zeros.",
  268. title_id);
  269. out.resize(std::min<u64>(0x4000, size));
  270. }
  271. if (control.second != nullptr) {
  272. if (size < 0x4000 + control.second->GetSize()) {
  273. LOG_ERROR(Service_NS,
  274. "output buffer is too small! (actual={:016X}, expected_min={:016X})", size,
  275. 0x4000 + control.second->GetSize());
  276. IPC::ResponseBuilder rb{ctx, 2};
  277. // TODO(DarkLordZach): Find a better error code for this.
  278. rb.Push(ResultCode(-1));
  279. return;
  280. }
  281. out.resize(0x4000 + control.second->GetSize());
  282. control.second->Read(out.data() + 0x4000, control.second->GetSize());
  283. } else {
  284. LOG_WARNING(Service_NS, "missing icon data for title_id={:016X}, defaulting to zeros.",
  285. title_id);
  286. }
  287. ctx.WriteBuffer(out);
  288. IPC::ResponseBuilder rb{ctx, 3};
  289. rb.Push(RESULT_SUCCESS);
  290. rb.Push<u32>(static_cast<u32>(out.size()));
  291. }
  292. void IApplicationManagerInterface::GetApplicationDesiredLanguage(Kernel::HLERequestContext& ctx) {
  293. IPC::RequestParser rp{ctx};
  294. const auto supported_languages = rp.Pop<u32>();
  295. const auto res = GetApplicationDesiredLanguage(supported_languages);
  296. if (res.Succeeded()) {
  297. IPC::ResponseBuilder rb{ctx, 3};
  298. rb.Push(RESULT_SUCCESS);
  299. rb.Push<u32>(*res);
  300. } else {
  301. IPC::ResponseBuilder rb{ctx, 2};
  302. rb.Push(res.Code());
  303. }
  304. }
  305. ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage(
  306. const u32 supported_languages) {
  307. LOG_DEBUG(Service_NS, "called with supported_languages={:08X}", supported_languages);
  308. // Get language code from settings
  309. const auto language_code = Set::GetLanguageCodeFromIndex(Settings::values.language_index);
  310. // Convert to application language, get priority list
  311. const auto application_language = ConvertToApplicationLanguage(language_code);
  312. if (application_language == std::nullopt) {
  313. return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
  314. }
  315. const auto priority_list = GetApplicationLanguagePriorityList(*application_language);
  316. if (!priority_list) {
  317. return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
  318. }
  319. // Try to find a valid language.
  320. for (const auto lang : *priority_list) {
  321. const auto supported_flag = GetSupportedLanguageFlag(lang);
  322. if (supported_languages == 0 || (supported_languages & supported_flag) == supported_flag) {
  323. return MakeResult(static_cast<u8>(lang));
  324. }
  325. }
  326. return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
  327. }
  328. void IApplicationManagerInterface::ConvertApplicationLanguageToLanguageCode(
  329. Kernel::HLERequestContext& ctx) {
  330. IPC::RequestParser rp{ctx};
  331. const auto application_language = rp.Pop<u8>();
  332. const auto res = ConvertApplicationLanguageToLanguageCode(application_language);
  333. if (res.Succeeded()) {
  334. IPC::ResponseBuilder rb{ctx, 4};
  335. rb.Push(RESULT_SUCCESS);
  336. rb.Push(*res);
  337. } else {
  338. IPC::ResponseBuilder rb{ctx, 2};
  339. rb.Push(res.Code());
  340. }
  341. }
  342. ResultVal<u64> IApplicationManagerInterface::ConvertApplicationLanguageToLanguageCode(
  343. u8 application_language) {
  344. const auto language_code =
  345. ConvertToLanguageCode(static_cast<ApplicationLanguage>(application_language));
  346. if (language_code == std::nullopt) {
  347. return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
  348. }
  349. return MakeResult(static_cast<u64>(*language_code));
  350. }
  351. IApplicationVersionInterface::IApplicationVersionInterface()
  352. : ServiceFramework{"IApplicationVersionInterface"} {
  353. // clang-format off
  354. static const FunctionInfo functions[] = {
  355. {0, nullptr, "GetLaunchRequiredVersion"},
  356. {1, nullptr, "UpgradeLaunchRequiredVersion"},
  357. {35, nullptr, "UpdateVersionList"},
  358. {36, nullptr, "PushLaunchVersion"},
  359. {37, nullptr, "ListRequiredVersion"},
  360. {800, nullptr, "RequestVersionList"},
  361. {801, nullptr, "ListVersionList"},
  362. {802, nullptr, "RequestVersionListData"},
  363. {1000, nullptr, "PerformAutoUpdate"},
  364. };
  365. // clang-format on
  366. RegisterHandlers(functions);
  367. }
  368. IApplicationVersionInterface::~IApplicationVersionInterface() = default;
  369. IContentManagerInterface::IContentManagerInterface()
  370. : ServiceFramework{"IContentManagerInterface"} {
  371. // clang-format off
  372. static const FunctionInfo functions[] = {
  373. {11, nullptr, "CalculateApplicationOccupiedSize"},
  374. {43, nullptr, "CheckSdCardMountStatus"},
  375. {47, nullptr, "GetTotalSpaceSize"},
  376. {48, nullptr, "GetFreeSpaceSize"},
  377. {600, nullptr, "CountApplicationContentMeta"},
  378. {601, nullptr, "ListApplicationContentMetaStatus"},
  379. {605, nullptr, "ListApplicationContentMetaStatusWithRightsCheck"},
  380. {607, nullptr, "IsAnyApplicationRunning"},
  381. };
  382. // clang-format on
  383. RegisterHandlers(functions);
  384. }
  385. IContentManagerInterface::~IContentManagerInterface() = default;
  386. IDocumentInterface::IDocumentInterface() : ServiceFramework{"IDocumentInterface"} {
  387. // clang-format off
  388. static const FunctionInfo functions[] = {
  389. {21, nullptr, "GetApplicationContentPath"},
  390. {23, nullptr, "ResolveApplicationContentPath"},
  391. {93, nullptr, "GetRunningApplicationProgramId"},
  392. };
  393. // clang-format on
  394. RegisterHandlers(functions);
  395. }
  396. IDocumentInterface::~IDocumentInterface() = default;
  397. IDownloadTaskInterface::IDownloadTaskInterface() : ServiceFramework{"IDownloadTaskInterface"} {
  398. // clang-format off
  399. static const FunctionInfo functions[] = {
  400. {701, nullptr, "ClearTaskStatusList"},
  401. {702, nullptr, "RequestDownloadTaskList"},
  402. {703, nullptr, "RequestEnsureDownloadTask"},
  403. {704, nullptr, "ListDownloadTaskStatus"},
  404. {705, nullptr, "RequestDownloadTaskListData"},
  405. {706, nullptr, "TryCommitCurrentApplicationDownloadTask"},
  406. {707, nullptr, "EnableAutoCommit"},
  407. {708, nullptr, "DisableAutoCommit"},
  408. {709, nullptr, "TriggerDynamicCommitEvent"},
  409. };
  410. // clang-format on
  411. RegisterHandlers(functions);
  412. }
  413. IDownloadTaskInterface::~IDownloadTaskInterface() = default;
  414. IECommerceInterface::IECommerceInterface() : ServiceFramework{"IECommerceInterface"} {
  415. // clang-format off
  416. static const FunctionInfo functions[] = {
  417. {0, nullptr, "RequestLinkDevice"},
  418. {1, nullptr, "RequestCleanupAllPreInstalledApplications"},
  419. {2, nullptr, "RequestCleanupPreInstalledApplication"},
  420. {3, nullptr, "RequestSyncRights"},
  421. {4, nullptr, "RequestUnlinkDevice"},
  422. {5, nullptr, "RequestRevokeAllELicense"},
  423. };
  424. // clang-format on
  425. RegisterHandlers(functions);
  426. }
  427. IECommerceInterface::~IECommerceInterface() = default;
  428. IFactoryResetInterface::IFactoryResetInterface::IFactoryResetInterface()
  429. : ServiceFramework{"IFactoryResetInterface"} {
  430. // clang-format off
  431. static const FunctionInfo functions[] = {
  432. {100, nullptr, "ResetToFactorySettings"},
  433. {101, nullptr, "ResetToFactorySettingsWithoutUserSaveData"},
  434. {102, nullptr, "ResetToFactorySettingsForRefurbishment"},
  435. };
  436. // clang-format on
  437. RegisterHandlers(functions);
  438. }
  439. IFactoryResetInterface::~IFactoryResetInterface() = default;
  440. NS::NS(const char* name) : ServiceFramework{name} {
  441. // clang-format off
  442. static const FunctionInfo functions[] = {
  443. {7992, &NS::PushInterface<IECommerceInterface>, "GetECommerceInterface"},
  444. {7993, &NS::PushInterface<IApplicationVersionInterface>, "GetApplicationVersionInterface"},
  445. {7994, &NS::PushInterface<IFactoryResetInterface>, "GetFactoryResetInterface"},
  446. {7995, &NS::PushInterface<IAccountProxyInterface>, "GetAccountProxyInterface"},
  447. {7996, &NS::PushInterface<IApplicationManagerInterface>, "GetApplicationManagerInterface"},
  448. {7997, &NS::PushInterface<IDownloadTaskInterface>, "GetDownloadTaskInterface"},
  449. {7998, &NS::PushInterface<IContentManagerInterface>, "GetContentManagementInterface"},
  450. {7999, &NS::PushInterface<IDocumentInterface>, "GetDocumentInterface"},
  451. };
  452. // clang-format on
  453. RegisterHandlers(functions);
  454. }
  455. NS::~NS() = default;
  456. std::shared_ptr<IApplicationManagerInterface> NS::GetApplicationManagerInterface() const {
  457. return GetInterface<IApplicationManagerInterface>();
  458. }
  459. class NS_DEV final : public ServiceFramework<NS_DEV> {
  460. public:
  461. explicit NS_DEV() : ServiceFramework{"ns:dev"} {
  462. // clang-format off
  463. static const FunctionInfo functions[] = {
  464. {0, nullptr, "LaunchProgram"},
  465. {1, nullptr, "TerminateProcess"},
  466. {2, nullptr, "TerminateProgram"},
  467. {4, nullptr, "GetShellEventHandle"},
  468. {5, nullptr, "GetShellEventInfo"},
  469. {6, nullptr, "TerminateApplication"},
  470. {7, nullptr, "PrepareLaunchProgramFromHost"},
  471. {8, nullptr, "LaunchApplication"},
  472. {9, nullptr, "LaunchApplicationWithStorageId"},
  473. {10, nullptr, "TerminateApplication2"},
  474. {11, nullptr, "GetRunningApplicationProcessId"},
  475. {12, nullptr, "SetCurrentApplicationRightsEnvironmentCanBeActive"},
  476. };
  477. // clang-format on
  478. RegisterHandlers(functions);
  479. }
  480. };
  481. class ISystemUpdateControl final : public ServiceFramework<ISystemUpdateControl> {
  482. public:
  483. explicit ISystemUpdateControl() : ServiceFramework{"ISystemUpdateControl"} {
  484. // clang-format off
  485. static const FunctionInfo functions[] = {
  486. {0, nullptr, "HasDownloaded"},
  487. {1, nullptr, "RequestCheckLatestUpdate"},
  488. {2, nullptr, "RequestDownloadLatestUpdate"},
  489. {3, nullptr, "GetDownloadProgress"},
  490. {4, nullptr, "ApplyDownloadedUpdate"},
  491. {5, nullptr, "RequestPrepareCardUpdate"},
  492. {6, nullptr, "GetPrepareCardUpdateProgress"},
  493. {7, nullptr, "HasPreparedCardUpdate"},
  494. {8, nullptr, "ApplyCardUpdate"},
  495. {9, nullptr, "GetDownloadedEulaDataSize"},
  496. {10, nullptr, "GetDownloadedEulaData"},
  497. {11, nullptr, "SetupCardUpdate"},
  498. {12, nullptr, "GetPreparedCardUpdateEulaDataSize"},
  499. {13, nullptr, "GetPreparedCardUpdateEulaData"},
  500. {14, nullptr, "SetupCardUpdateViaSystemUpdater"},
  501. {15, nullptr, "HasReceived"},
  502. {16, nullptr, "RequestReceiveSystemUpdate"},
  503. {17, nullptr, "GetReceiveProgress"},
  504. {18, nullptr, "ApplyReceivedUpdate"},
  505. {19, nullptr, "GetReceivedEulaDataSize"},
  506. {20, nullptr, "GetReceivedEulaData"},
  507. {21, nullptr, "SetupToReceiveSystemUpdate"},
  508. {22, nullptr, "RequestCheckLatestUpdateIncludesRebootlessUpdate"},
  509. };
  510. // clang-format on
  511. RegisterHandlers(functions);
  512. }
  513. };
  514. class NS_SU final : public ServiceFramework<NS_SU> {
  515. public:
  516. explicit NS_SU() : ServiceFramework{"ns:su"} {
  517. // clang-format off
  518. static const FunctionInfo functions[] = {
  519. {0, nullptr, "GetBackgroundNetworkUpdateState"},
  520. {1, &NS_SU::OpenSystemUpdateControl, "OpenSystemUpdateControl"},
  521. {2, nullptr, "NotifyExFatDriverRequired"},
  522. {3, nullptr, "ClearExFatDriverStatusForDebug"},
  523. {4, nullptr, "RequestBackgroundNetworkUpdate"},
  524. {5, nullptr, "NotifyBackgroundNetworkUpdate"},
  525. {6, nullptr, "NotifyExFatDriverDownloadedForDebug"},
  526. {9, nullptr, "GetSystemUpdateNotificationEventForContentDelivery"},
  527. {10, nullptr, "NotifySystemUpdateForContentDelivery"},
  528. {11, nullptr, "PrepareShutdown"},
  529. {16, nullptr, "DestroySystemUpdateTask"},
  530. {17, nullptr, "RequestSendSystemUpdate"},
  531. {18, nullptr, "GetSendSystemUpdateProgress"},
  532. };
  533. // clang-format on
  534. RegisterHandlers(functions);
  535. }
  536. private:
  537. void OpenSystemUpdateControl(Kernel::HLERequestContext& ctx) {
  538. LOG_DEBUG(Service_NS, "called");
  539. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  540. rb.Push(RESULT_SUCCESS);
  541. rb.PushIpcInterface<ISystemUpdateControl>();
  542. }
  543. };
  544. class NS_VM final : public ServiceFramework<NS_VM> {
  545. public:
  546. explicit NS_VM() : ServiceFramework{"ns:vm"} {
  547. // clang-format off
  548. static const FunctionInfo functions[] = {
  549. {1200, nullptr, "NeedsUpdateVulnerability"},
  550. {1201, nullptr, "UpdateSafeSystemVersionForDebug"},
  551. {1202, nullptr, "GetSafeSystemVersion"},
  552. };
  553. // clang-format on
  554. RegisterHandlers(functions);
  555. }
  556. };
  557. void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
  558. std::make_shared<NS>("ns:am2")->InstallAsService(service_manager);
  559. std::make_shared<NS>("ns:ec")->InstallAsService(service_manager);
  560. std::make_shared<NS>("ns:rid")->InstallAsService(service_manager);
  561. std::make_shared<NS>("ns:rt")->InstallAsService(service_manager);
  562. std::make_shared<NS>("ns:web")->InstallAsService(service_manager);
  563. std::make_shared<NS_DEV>()->InstallAsService(service_manager);
  564. std::make_shared<NS_SU>()->InstallAsService(service_manager);
  565. std::make_shared<NS_VM>()->InstallAsService(service_manager);
  566. std::make_shared<PL_U>(system)->InstallAsService(service_manager);
  567. }
  568. } // namespace Service::NS