ns.cpp 36 KB

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