ns.cpp 36 KB

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