ns.cpp 29 KB

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