ns.cpp 37 KB

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