NCM services: Difference between revisions

No edit summary
No edit summary
Line 70: Line 70:
If the supplied [[#StorageId|StorageID]] is 1 (Host), a different set of internal functions is used to handle these commands. In this more restricted set of functions, GetControlNcaPath is stubbed and only returns error 0x608.
If the supplied [[#StorageId|StorageID]] is 1 (Host), a different set of internal functions is used to handle these commands. In this more restricted set of functions, GetControlNcaPath is stubbed and only returns error 0x608.


The Get* commands load the [[Filesystem_services|ContentPath]] from linked-lists' [[#Location_List_Entry|entries]] in memory using the input TitleID. When the command fails to find an entry for the specified TitleID, 0x408 is returned for GetProgramNcaPath and 0xA08 is returned for the rest.
The Get* commands load the [[Filesystem_services|ContentPath]] from linked-lists' [[#Location_List_Entry|entries]] in memory using the input [[#ProgramId]]. When the command fails to find an entry for the specified [[#ProgramId]], 0x408 is returned for GetProgramNcaPath and 0xA08 is returned for the rest.


The Set* commands always return 0 and add a new entry to the list. If a matching entry is found, it's removed first.
The Set* commands always return 0 and add a new entry to the list. If a matching entry is found, it's removed first.


==== ResolveProgramPath ====
==== ResolveProgramPath ====
Takes an u64 '''TitleID''' and a C descriptor. Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].
Takes an u64 [[#ProgramId]] and a C descriptor. Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].


==== RedirectProgramPath ====
==== RedirectProgramPath ====
Takes an u64 '''TitleID''' and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].
Takes an u64 [[#ProgramId]] and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].


Inserts a new [[#Location_List_Entry|entry]] with '''flag''' set to 0.
Inserts a new [[#Location_List_Entry|entry]] with '''flag''' set to 0.


==== ResolveApplicationControlPath ====
==== ResolveApplicationControlPath ====
Takes an u64 '''TitleID''' and a C descriptor. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].
Takes an u64 [[#ApplicationId]] and a C descriptor. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].


==== ResolveApplicationHtmlDocumentPath====
==== ResolveApplicationHtmlDocumentPath====
Takes an u64 '''TitleID''' and a C descriptor. Used for [[NCA_Content_FS#NCA-type4|NCA-type4]].
Takes an u64 [[#ApplicationId]] and a C descriptor. Used for [[NCA_Content_FS#NCA-type4|NCA-type4]].


==== ResolveDataPath ====
==== ResolveDataPath ====
Takes an u64 '''TitleID''' and a C descriptor. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].
Takes an u64 [[#ApplicationId]] and a C descriptor. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].


==== RedirectApplicationControlPath ====
==== RedirectApplicationControlPath ====
Takes an u64 '''TitleID''' and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].
Takes an u64 [[#ApplicationId]] and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].


[9.0.0+] Now takes an additional 8-bytes of input.
[9.0.0+] Now takes an additional 8-bytes of input.
Line 99: Line 99:


==== RedirectApplicationHtmlDocumentPath ====
==== RedirectApplicationHtmlDocumentPath ====
Takes an u64 '''TitleID''' and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type4|NCA-type4]].
Takes an u64 [[#ApplicationId]] and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type4|NCA-type4]].


[9.0.0+] Now takes an additional 8-bytes of input.
[9.0.0+] Now takes an additional 8-bytes of input.
Line 106: Line 106:


==== ResolveApplicationLegalInformationPath ====
==== ResolveApplicationLegalInformationPath ====
Takes an u64 '''TitleID''' and a C descriptor. Used for [[NCA_Content_FS#NCA-type5|NCA-type5]].
Takes an u64 [[#ApplicationId]] and a C descriptor. Used for [[NCA_Content_FS#NCA-type5|NCA-type5]].


==== RedirectApplicationLegalInformationPath ====
==== RedirectApplicationLegalInformationPath ====
Takes an u64 '''TitleID''' and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type5|NCA-type5]].
Takes an u64 [[#ApplicationId]] and a X descriptor with a [[Filesystem_services#ContentPath|ContentPath]]. Used for [[NCA_Content_FS#NCA-type5|NCA-type5]].


[9.0.0+] Now takes an additional 8-bytes of input.
[9.0.0+] Now takes an additional 8-bytes of input.
Line 129: Line 129:


==== EraseProgramRedirection ====
==== EraseProgramRedirection ====
Takes an u64 '''TitleID'''. Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].
Takes an u64 [[#ProgramnId]]. Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].


Removes the [[#Location_List_Entry|entry]] that matches the input TitleID.
Removes the [[#Location_List_Entry|entry]] that matches the input ProgramId.


==== EraseApplicationControlRedirection ====
==== EraseApplicationControlRedirection ====
Takes an u64 '''TitleID'''. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].
Takes an u64 [[#ApplicationId]]. Used for [[NCA_Content_FS#NCA-type3|NCA-type3]].


Removes the [[#Location_List_Entry|entry]] that matches the input TitleID.
Removes the [[#Location_List_Entry|entry]] that matches the input ApplicationId.


==== EraseApplicationHtmlDocumentRedirection ====
==== EraseApplicationHtmlDocumentRedirection ====
Takes an u64 '''TitleID'''. Used for [[NCA_Content_FS#NCA-type4|NCA-type4]].
Takes an u64 [[#ApplicationId]]. Used for [[NCA_Content_FS#NCA-type4|NCA-type4]].


Removes the [[#Location_List_Entry|entry]] that matches the input TitleID.
Removes the [[#Location_List_Entry|entry]] that matches the input ApplicationId.


==== EraseApplicationLegalInformationRedirection ====
==== EraseApplicationLegalInformationRedirection ====
Takes an u64 '''TitleID'''. Used for [[NCA_Content_FS#NCA-type5|NCA-type5]].
Takes an u64 [[#ApplicationId]]. Used for [[NCA_Content_FS#NCA-type5|NCA-type5]].


Removes the [[#Location_List_Entry|entry]] that matches the input TitleID.
Removes the [[#Location_List_Entry|entry]] that matches the input ApplicationId.


==== ResolveProgramPathForDebug ====
==== ResolveProgramPathForDebug ====
Line 173: Line 173:
This is "nn::lr::IRegisteredLocationResolver".
This is "nn::lr::IRegisteredLocationResolver".


This works like [[#ILocationResolver]], but only two types of NCA paths can be gotten/set. In addition, each type has a fallback path that can be set for a single title ID at a time.
This works like [[#ILocationResolver]], but only two types of NCA paths can be gotten/set. In addition, each type has a fallback path that can be set for a single [[#ProgramId]] at a time.


{| class="wikitable" border="1"
{| class="wikitable" border="1"
Line 179: Line 179:
! Cmd || Name || Arguments || Notes
! Cmd || Name || Arguments || Notes
|-
|-
| 0 || ResolveProgramPath || u64 TitleID + C descriptor || Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].
| 0 || ResolveProgramPath || u64 [[#ProgramId]] + C descriptor || Used for [[NCA_Content_FS#NCA-type1|NCA-type1]].
|-
|-
| 1 || RegisterProgramPath || u64 TitleID + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. || Sets the Type 0 fallback TID and path to the provided arguments.
| 1 || RegisterProgramPath || u64 [[#ProgramId]] + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. || Sets the Type 0 fallback TID and path to the provided arguments.
|-
|-
| 2 || UnregisterProgramPath || u64 TitleID || If the Type 0 fallback TID is == argument TID, unregisters the fallback path. Otherwise, noop.
| 2 || UnregisterProgramPath || u64 [[#ProgramId]] || If the Type 0 fallback TID is == argument TID, unregisters the fallback path. Otherwise, noop.
|-
|-
| 3 || RedirectProgramPath || u64 TitleID + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. ||
| 3 || RedirectProgramPath || u64 [[#ProgramId]] + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. ||
|-
|-
| 4 || [2.0.0+] ResolveHtmlDocumentPath || u64 TitleID + C descriptor ||
| 4 || [2.0.0+] ResolveHtmlDocumentPath || u64 [[#ProgramId]] + C descriptor ||
|-
|-
| 5 || [2.0.0+] RegisterHtmlDocumentPath || u64 TitleID + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. || Sets the Type 1 fallback TID and path to the provided arguments.
| 5 || [2.0.0+] RegisterHtmlDocumentPath || u64 [[#ProgramId]] + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. || Sets the Type 1 fallback TID and path to the provided arguments.
|-
|-
| 6 || [2.0.0+] UnregisterHtmlDocumentPath || u64 TitleID || If the Type 1 fallback TID is == argument TID, unregisters the fallback path. Otherwise, noop.
| 6 || [2.0.0+] UnregisterHtmlDocumentPath || u64 [[#ProgramId]] || If the Type 1 fallback TID is == argument TID, unregisters the fallback path. Otherwise, noop.
|-
|-
| 7 || [2.0.0+] RedirectHtmlDocumentPath || u64 TitleID + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. ||
| 7 || [2.0.0+] RedirectHtmlDocumentPath || u64 [[#ProgramId]] + X descriptor [[Filesystem_services#ContentPath|ContentPath]] [9.0.0+] Now takes an additional 8-bytes of input. ||
|-
|-
| 8 || [7.0.0+] Refresh || No input/output. ||  
| 8 || [7.0.0+] Refresh || No input/output. ||  
|-
|-
| 9 || [9.0.0+] RefreshExcluding || Type-5 buffer || Unofficial name. Refreshes entries excluding those with application title ids contained in the buffer.
| 9 || [9.0.0+] RefreshExcluding || Type-5 buffer || Unofficial name. Refreshes entries excluding those with application ProgramIds contained in the buffer.
|}
|}


Line 207: Line 207:
! Cmd || Name || Arguments || Notes
! Cmd || Name || Arguments || Notes
|-
|-
| 0 || ResolveAddOnContentPath || u64 TitleID + C descriptor ||  
| 0 || ResolveAddOnContentPath || u64 [[#ProgramId]] + C descriptor ||  
|-
|-
| 1 || RegisterAddOnContentStorage || [[#StorageId|StorageID]] + u64 TitleID [9.0.0+] Now takes an additional u64 TitleID for the owner application. ||  
| 1 || RegisterAddOnContentStorage || [[#StorageId|StorageID]] + u64 [[#ProgramId]] [9.0.0+] Now takes an additional u64 [[#ApplicationId]] for the owner application. ||  
|-
|-
| 2 || UnregisterAllAddOnContentPath || None || Clears all registered titles here.
| 2 || UnregisterAllAddOnContentPath || None || Clears all registered titles here.
Line 215: Line 215:
| 3 || [9.0.0+] [[#RefreshApplicationAddOnContent]] || Type-5 buffer || Unofficial name
| 3 || [9.0.0+] [[#RefreshApplicationAddOnContent]] || Type-5 buffer || Unofficial name
|-
|-
| 4 || [9.0.0+] [[#UnregisterApplicationAddOnContent]] || u64 TitleID || Unofficial name
| 4 || [9.0.0+] [[#UnregisterApplicationAddOnContent]] || u64 [[#ProgramId]] || Unofficial name
|}
|}


==== RefreshApplicationAddOnContent ====
==== RefreshApplicationAddOnContent ====
Takes an type-5 buffer containing application title ids. Unregisters entries with application ids absent from the input buffer.
Takes an type-5 buffer containing an array of [[#ApplicationId]]. Unregisters entries with IDs absent from the input buffer.


==== UnregisterApplicationAddOnContent====
==== UnregisterApplicationAddOnContent====
Takes an u64 '''TitleID''' for the application to unregister add on content entries for.
Takes an u64 [[#ApplicationId]] for the application to unregister add on content entries for.


=== Location List Entry ===
=== Location List Entry ===
Line 235: Line 235:
| 0x8 || 0x8|| Pointer to next entry
| 0x8 || 0x8|| Pointer to next entry
|-
|-
| 0x10 || 0x8|| TitleID
| 0x10 || 0x8|| [[#ProgramId]]
|-
|-
| 0x18 || 0x300 || [[Filesystem_services|ContentPath]]
| 0x18 || 0x300 || [[#Path]]
|-
|-
| 0x318 || 0x4 || Flag
| 0x318 || 0x4 || Flag
Line 400: Line 400:
| 5 || List || Takes a type-6 buffer to write [[#ContentMetaKey|Content Meta Key]]s to, a u32 [[#ContentMetaType|Content Meta Type]], a u64 TID, a u64 TID_LOW, and u64 TID_HIGH. Writes into the buffer all Content Meta Keys with low <= record->title_id <= high, and record->type == type. Returns s32 numEntriesTotal, numEntriesWritten. Additionally requires record->title_id == TID, if record->type is Application, Patch, Add-On, or Delta, otherwise, you can pass 0 for type to ignore the type and list them all in the range.
| 5 || List || Takes a type-6 buffer to write [[#ContentMetaKey|Content Meta Key]]s to, a u32 [[#ContentMetaType|Content Meta Type]], a u64 TID, a u64 TID_LOW, and u64 TID_HIGH. Writes into the buffer all Content Meta Keys with low <= record->title_id <= high, and record->type == type. Returns s32 numEntriesTotal, numEntriesWritten. Additionally requires record->title_id == TID, if record->type is Application, Patch, Add-On, or Delta, otherwise, you can pass 0 for type to ignore the type and list them all in the range.
|-
|-
| 6 || GetLatestContentMetaKey || Takes a u64 title id, and returns the [[#ContentMetaKey|Content Meta Key]] with the highest version field for that title id.
| 6 || GetLatestContentMetaKey || Takes a u64 [[#ProgramId]], and returns the [[#ContentMetaKey|Content Meta Key]] with the highest version field for that ProgramId.
|-
|-
| 7 || [[#ListApplication]] ||
| 7 || [[#ListApplication]] ||
Line 412: Line 412:
| 11 || GetRequiredSystemVersion || Takes a [[#ContentMetaKey|Content Meta Key]], and returns u32 from ContentRecords + 16 (only if the content meta key has type Application or Patch).
| 11 || GetRequiredSystemVersion || Takes a [[#ContentMetaKey|Content Meta Key]], and returns u32 from ContentRecords + 16 (only if the content meta key has type Application or Patch).
|-
|-
| 12 || GetPatchId || Takes a [[#ContentMetaKey|Content Meta Key]], and returns the update title id for that record.
| 12 || GetPatchId || Takes a [[#ContentMetaKey|Content Meta Key]], and returns the update [[#ProgramId]] for that record.
|-
|-
| 13 || DisableForcibly ||  Closes the meta database, and causes all future IPC commands to the current session to return error 0xDC05.
| 13 || DisableForcibly ||  Closes the meta database, and causes all future IPC commands to the current session to return error 0xDC05.
Line 463: Line 463:
         out_buf[i] = 0
         out_buf[i] = 0


=== StorageId ===
=== ContentId ===
This is "nn::ncm::ContentId".
 
This is a 0x10-byte entry. This is originally from the hex portion of "<hex>.nca" directory-names from this storage FS(like [[SD_Filesystem|SD]]).
 
The ContentId is the same as the first 0x10-bytes from the calculated SHA256 hash, from hashing the entire output from [[#ReadContentIdFile]].
 
=== PlaceHolderId ===
This is "nn::ncm::PlaceHolderId".
 
This is the same as [[#ContentId]], except this is for placeholder content and originates from [[#GeneratePlaceHolderId]].
 
== ProgramId ==
This is "nn::ncm::ProgramId" or "nn::ncm::SystemProgramId".
 
This is an u64 ID bound to a [[Title_list#System_Modules|program]].
 
== DataId ==
This is "nn::ncm::DataId" or "nn::ncm::SystemDataId".
 
This is an u64 ID bound to a [[Title_list#System_Data_Archives|data archive]].
 
== ApplicationId ==
This is "nn::ncm::ApplicationId".
 
This is an u64 ID bound to an [[Title_list#System_Applications|application]].
 
== StorageId ==
This is "nn::ncm::StorageId". Enum, sizeof() == sizeof(u8).
This is "nn::ncm::StorageId". Enum, sizeof() == sizeof(u8).


Line 491: Line 518:
nn::ncm::IsUniqueStorage returns true for != None && != Any.
nn::ncm::IsUniqueStorage returns true for != None && != Any.


=== ContentId ===
== RightsId ==
This is "nn::ncm::ContentId".
This is "nn::ncm::RightsId". This is a 0x10-byte struct. [3.0.0+] This is a 0x18-byte struct.
 
{| class="wikitable" border="1"
|-
! Offset
! Size
! Description
|-
| 0x0 || 0x10 || FS Rights ID
|-
| 0x10 || 0x1 || [3.0.0+] key_generation
|-
| 0x11 || 0x7 || [3.0.0+] Padding
|}


This is a 0x10-byte entry. This is originally from the hex portion of "<hex>.nca" directory-names from this storage FS(like [[SD_Filesystem|SD]]).
== ProgramLocation ==
This is "nn::ncm::ProgramLocation".


The ContentId is the same as the first 0x10-bytes from the calculated SHA256 hash, from hashing the entire output from [[#ReadContentIdFile]].
{| class="wikitable" border="1"
|-
! Offset
! Size
! Description
|-
| 0x0 || 0x8 || [[#ProgramId]]
|-
| 0x8 || 0x1 || [[#StorageId]]
|-
| 0x9 || 0x7 || Padding
|}


=== PlaceHolderId ===
== Path ==
This is "nn::ncm::PlaceHolderId".
This is "nn::ncm::Path".


This is the same as [[#ContentId]], except this is for placeholder content and originates from [[#GeneratePlaceHolderId]].
This is a 0x300-byte structure, which contains a [[Filesystem_services#ContentPath|Content Path]].


== ContentInstallType ==
== ContentInstallType ==
Line 571: Line 623:
| 0x0  
| 0x0  
| 0x8  
| 0x8  
| Title id
| [[#ProgramId]]
|-
|-
| 0x8  
| 0x8  
Line 579: Line 631:
| 0xC  
| 0xC  
| 0x1  
| 0x1  
| [[#ContentMetaType|Content Meta Type]]
| [[#ContentMetaType]]
|-
|-
| 0xD  
| 0xD  
| 0x1  
| 0x1  
| [[#ContentInstallType|Content Install Type]]
| [[#ContentInstallType]]
|-
|-
| 0xE  
| 0xE  
| 0x2  
| 0x2  
| Padding
| Padding
|}
== ProgramId ==
This is "nn::ncm::ProgramId" or "nn::ncm::SystemProgramId".
This is an u64 ID bound to a [[Title_list#System_Modules|program]].
== DataId ==
This is "nn::ncm::DataId" or "nn::ncm::SystemDataId".
This is an u64 ID bound to a [[Title_list#System_Data_Archives|data archive]].
== ApplicationId ==
This is "nn::ncm::ApplicationId".
This is an u64 ID bound to an [[Title_list#System_Applications|application]].
== ProgramLocation ==
This is "nn::ncm::ProgramLocation".
{| class="wikitable" border="1"
|-
! Offset
! Size
! Description
|-
| 0x0 || 0x8 || titleID
|-
| 0x8 || 0x1 || [[#StorageId|storageID]]
|-
| 0x9 || 0x7 || Padding
|}
== Path ==
This is "nn::ncm::Path".
This is a 0x300-byte structure, which contains a [[Filesystem_services#ContentPath|Content Path]].
== RightsId ==
This is "nn::ncm::RightsId". This is a 0x10-byte struct. [3.0.0+] This is a 0x18-byte struct.
{| class="wikitable" border="1"
|-
! Offset
! Size
! Description
|-
| 0x0 || 0x10 || FS Rights ID
|-
| 0x10 || 0x1 || [3.0.0+] key_generation
|-
| 0x11 || 0x7 || [3.0.0+] Padding
|}
|}