ns.cpp 30 KB

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