ns.cpp 33 KB

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