From 69cc04a06dd32f47d1a369dc571074ee6d857ce9 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 6 Nov 2017 11:47:33 -0700 Subject: [PATCH 1/5] Services/AM: Fix warnings --- src/core/hle/service/am/am.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 3eb899bfa..7d29475d7 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -685,7 +685,7 @@ void GetNumContentInfos(Service::Interface* self) { } else { rb.Push(1); // Number of content infos plus one LOG_WARNING(Service_AM, "(STUBBED) called media_type=%u, title_id=0x%016" PRIx64, - media_type, title_id); + static_cast(media_type), title_id); } } @@ -793,7 +793,7 @@ void BeginImportProgram(Service::Interface* self) { Kernel::g_handle_table.Create(std::get>(sessions)) .Unwrap()); - LOG_WARNING(Service_AM, "(STUBBED) media_type=%u", media_type); + LOG_WARNING(Service_AM, "(STUBBED) media_type=%u", static_cast(media_type)); } void EndImportProgram(Service::Interface* self) { From ac2ee3035a54b4d14295ddd2035fb0b80c899a5b Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 6 Nov 2017 11:47:51 -0700 Subject: [PATCH 2/5] file_sys/cia_container: Fix warnings --- src/core/file_sys/cia_container.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/file_sys/cia_container.cpp b/src/core/file_sys/cia_container.cpp index 3ec9b4a33..ffd94cd8f 100644 --- a/src/core/file_sys/cia_container.cpp +++ b/src/core/file_sys/cia_container.cpp @@ -215,7 +215,7 @@ void CIAContainer::Print() const { LOG_DEBUG(Service_FS, "Ticket Size: 0x%08x bytes", GetTicketSize()); LOG_DEBUG(Service_FS, "TMD Size: 0x%08x bytes", GetTitleMetadataSize()); LOG_DEBUG(Service_FS, "Meta Size: 0x%08x bytes", GetMetadataSize()); - LOG_DEBUG(Service_FS, "Content Size: 0x%08x bytes\n", GetTotalContentSize()); + LOG_DEBUG(Service_FS, "Content Size: 0x%08" PRIx64 " bytes\n", GetTotalContentSize()); LOG_DEBUG(Service_FS, "Certificate Offset: 0x%08" PRIx64 " bytes", GetCertificateOffset()); LOG_DEBUG(Service_FS, "Ticket Offset: 0x%08" PRIx64 " bytes", GetTicketOffset()); From c6e43ae79d0708e63c0f07b199867daa4efa0be8 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 6 Nov 2017 11:50:53 -0700 Subject: [PATCH 3/5] Services/AM: Rename and adjust FindContentInfos for accuracy --- src/core/hle/service/am/am.cpp | 24 ++++++++++++++++++++---- src/core/hle/service/am/am.h | 5 +++-- src/core/hle/service/am/am_app.cpp | 2 +- src/core/hle/service/am/am_sys.cpp | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 7d29475d7..f94c47768 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -401,14 +401,28 @@ void GetNumPrograms(Service::Interface* self) { rb.Push(am_title_list[media_type].size()); } -void FindContentInfos(Service::Interface* self) { +void FindDLCContentInfos(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1002, 4, 4); // 0x10020104 auto media_type = static_cast(rp.Pop()); u64 title_id = rp.Pop(); u32 content_count = rp.Pop(); - VAddr content_requested_in = rp.PopMappedBuffer(); - VAddr content_info_out = rp.PopMappedBuffer(); + + size_t input_buffer_size, output_buffer_size; + IPC::MappedBufferPermissions input_buffer_perms, output_buffer_perms; + VAddr content_requested_in = rp.PopMappedBuffer(&input_buffer_size, &input_buffer_perms); + VAddr content_info_out = rp.PopMappedBuffer(&output_buffer_size, &output_buffer_perms); + + // Validate that only DLC TIDs are passed in + u32 tid_high = static_cast(title_id >> 32); + if (tid_high != TID_HIGH_DLC) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); + rb.Push(ResultCode(ErrCodes::InvalidTIDInList, ErrorModule::AM, + ErrorSummary::InvalidArgument, ErrorLevel::Usage)); + rb.PushMappedBuffer(content_requested_in, input_buffer_size, input_buffer_perms); + rb.PushMappedBuffer(content_info_out, output_buffer_size, output_buffer_perms); + return; + } std::vector content_requested(content_count); Memory::ReadBlock(content_requested_in, content_requested.data(), content_count * sizeof(u16)); @@ -440,8 +454,10 @@ void FindContentInfos(Service::Interface* self) { } } - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); rb.Push(RESULT_SUCCESS); + rb.PushMappedBuffer(content_requested_in, input_buffer_size, input_buffer_perms); + rb.PushMappedBuffer(content_info_out, output_buffer_size, output_buffer_perms); } void ListContentInfos(Service::Interface* self) { diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index b3b3a5b07..b8f1053b6 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -96,7 +96,8 @@ void ScanForAllTitles(); void GetNumPrograms(Service::Interface* self); /** - * AM::FindContentInfos service function + * AM::FindDLCContentInfos service function + * Explicitly checks that TID high value is 0004008C or an error is returned. * Inputs: * 1 : MediaType * 2-3 : u64, Title ID @@ -106,7 +107,7 @@ void GetNumPrograms(Service::Interface* self); * Outputs: * 1 : Result, 0 on success, otherwise error code */ -void FindContentInfos(Service::Interface* self); +void FindDLCContentInfos(Service::Interface* self); /** * AM::ListContentInfos service function diff --git a/src/core/hle/service/am/am_app.cpp b/src/core/hle/service/am/am_app.cpp index db85067d0..6dd93497a 100644 --- a/src/core/hle/service/am/am_app.cpp +++ b/src/core/hle/service/am/am_app.cpp @@ -10,7 +10,7 @@ namespace AM { const Interface::FunctionInfo FunctionTable[] = { {0x100100C0, GetNumContentInfos, "GetNumContentInfos"}, - {0x10020104, FindContentInfos, "FindContentInfos"}, + {0x10020104, FindDLCContentInfos, "FindDLCContentInfos"}, {0x10030142, ListContentInfos, "ListContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"}, {0x10050084, GetDLCTitleInfos, "GetDLCTitleInfos"}, diff --git a/src/core/hle/service/am/am_sys.cpp b/src/core/hle/service/am/am_sys.cpp index 7787fdfed..cb860653f 100644 --- a/src/core/hle/service/am/am_sys.cpp +++ b/src/core/hle/service/am/am_sys.cpp @@ -55,7 +55,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x002C0084, nullptr, "GetProgramInfosIgnorePlatform"}, {0x002D00C0, CheckContentRightsIgnorePlatform, "CheckContentRightsIgnorePlatform"}, {0x100100C0, GetNumContentInfos, "GetNumContentInfos"}, - {0x10020104, FindContentInfos, "FindContentInfos"}, + {0x10020104, FindDLCContentInfos, "FindDLCContentInfos"}, {0x10030142, ListContentInfos, "ListContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"}, {0x10050084, GetDLCTitleInfos, "GetDLCTitleInfos"}, From d854d4119a0766838359059b7cf405272dbdf7ff Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 6 Nov 2017 12:04:12 -0700 Subject: [PATCH 4/5] Services/AM: Rename and adjust ListContentInfos for accuracy --- src/core/hle/service/am/am.cpp | 22 +++++++++++++++++++--- src/core/hle/service/am/am.h | 5 +++-- src/core/hle/service/am/am_app.cpp | 2 +- src/core/hle/service/am/am_sys.cpp | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index f94c47768..c575dc478 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -460,13 +460,28 @@ void FindDLCContentInfos(Service::Interface* self) { rb.PushMappedBuffer(content_info_out, output_buffer_size, output_buffer_perms); } -void ListContentInfos(Service::Interface* self) { +void ListDLCContentInfos(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1003, 5, 2); // 0x10030142 + u32 content_count = rp.Pop(); auto media_type = static_cast(rp.Pop()); u64 title_id = rp.Pop(); u32 start_index = rp.Pop(); - VAddr content_info_out = rp.PopMappedBuffer(); + + size_t output_buffer_size; + IPC::MappedBufferPermissions output_buffer_perms; + VAddr content_info_out = rp.PopMappedBuffer(&output_buffer_size, &output_buffer_perms); + + // Validate that only DLC TIDs are passed in + u32 tid_high = static_cast(title_id >> 32); + if (tid_high != TID_HIGH_DLC) { + IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); + rb.Push(ResultCode(ErrCodes::InvalidTIDInList, ErrorModule::AM, + ErrorSummary::InvalidArgument, ErrorLevel::Usage)); + rb.Push(0); + rb.PushMappedBuffer(content_info_out, output_buffer_size, output_buffer_perms); + return; + } std::string tmd_path = GetTitleMetadataPath(media_type, title_id); @@ -494,9 +509,10 @@ void ListContentInfos(Service::Interface* self) { } } - IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); + IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); rb.Push(RESULT_SUCCESS); rb.Push(copied); + rb.PushMappedBuffer(content_info_out, output_buffer_size, output_buffer_perms); } void DeleteContents(Service::Interface* self) { diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index b8f1053b6..8a2887bcd 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -110,7 +110,8 @@ void GetNumPrograms(Service::Interface* self); void FindDLCContentInfos(Service::Interface* self); /** - * AM::ListContentInfos service function + * AM::ListDLCContentInfos service function + * Explicitly checks that TID high value is 0004008C or an error is returned. * Inputs: * 1 : Content count * 2 : MediaType @@ -121,7 +122,7 @@ void FindDLCContentInfos(Service::Interface* self); * 1 : Result, 0 on success, otherwise error code * 2 : Number of content infos returned */ -void ListContentInfos(Service::Interface* self); +void ListDLCContentInfos(Service::Interface* self); /** * AM::DeleteContents service function diff --git a/src/core/hle/service/am/am_app.cpp b/src/core/hle/service/am/am_app.cpp index 6dd93497a..4007e2d1c 100644 --- a/src/core/hle/service/am/am_app.cpp +++ b/src/core/hle/service/am/am_app.cpp @@ -11,7 +11,7 @@ namespace AM { const Interface::FunctionInfo FunctionTable[] = { {0x100100C0, GetNumContentInfos, "GetNumContentInfos"}, {0x10020104, FindDLCContentInfos, "FindDLCContentInfos"}, - {0x10030142, ListContentInfos, "ListContentInfos"}, + {0x10030142, ListDLCContentInfos, "ListDLCContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"}, {0x10050084, GetDLCTitleInfos, "GetDLCTitleInfos"}, {0x10060080, nullptr, "GetNumDataTitleTickets"}, diff --git a/src/core/hle/service/am/am_sys.cpp b/src/core/hle/service/am/am_sys.cpp index cb860653f..921221f39 100644 --- a/src/core/hle/service/am/am_sys.cpp +++ b/src/core/hle/service/am/am_sys.cpp @@ -56,7 +56,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x002D00C0, CheckContentRightsIgnorePlatform, "CheckContentRightsIgnorePlatform"}, {0x100100C0, GetNumContentInfos, "GetNumContentInfos"}, {0x10020104, FindDLCContentInfos, "FindDLCContentInfos"}, - {0x10030142, ListContentInfos, "ListContentInfos"}, + {0x10030142, ListDLCContentInfos, "ListDLCContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"}, {0x10050084, GetDLCTitleInfos, "GetDLCTitleInfos"}, {0x10060080, nullptr, "GetNumDataTitleTickets"}, From c07f1b275c6858adedb444d792f854472021912a Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 6 Nov 2017 17:49:39 -0700 Subject: [PATCH 5/5] Services/AM: Rename and readjust GetNumContentInfos for accuracy --- src/core/hle/service/am/am.cpp | 12 +++++++++++- src/core/hle/service/am/am.h | 6 ++++-- src/core/hle/service/am/am_app.cpp | 2 +- src/core/hle/service/am/am_sys.cpp | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index c575dc478..919a12962 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -701,11 +701,21 @@ void ListDataTitleTicketInfos(Service::Interface* self) { ticket_count, title_id, start_index, ticket_info_out); } -void GetNumContentInfos(Service::Interface* self) { +void GetDLCContentInfoCount(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1001, 3, 0); // 0x100100C0 auto media_type = static_cast(rp.Pop()); u64 title_id = rp.Pop(); + // Validate that only DLC TIDs are passed in + u32 tid_high = static_cast(title_id >> 32); + if (tid_high != TID_HIGH_DLC) { + IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); + rb.Push(ResultCode(ErrCodes::InvalidTID, ErrorModule::AM, ErrorSummary::InvalidArgument, + ErrorLevel::Usage)); + rb.Push(0); + return; + } + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); // No error diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 8a2887bcd..04493d943 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -22,6 +22,7 @@ namespace AM { namespace ErrCodes { enum { CIACurrentlyInstalling = 4, + InvalidTID = 31, EmptyCIA = 32, InvalidTIDInList = 60, InvalidCIAHeader = 104, @@ -204,7 +205,8 @@ void GetPatchTitleInfos(Service::Interface* self); void ListDataTitleTicketInfos(Service::Interface* self); /** - * AM::GetNumContentInfos service function + * AM::GetDLCContentInfoCount service function + * Explicitly checks that TID high value is 0004008C or an error is returned. * Inputs: * 0 : Command header (0x100100C0) * 1 : MediaType @@ -213,7 +215,7 @@ void ListDataTitleTicketInfos(Service::Interface* self); * 1 : Result, 0 on success, otherwise error code * 2 : Number of content infos plus one */ -void GetNumContentInfos(Service::Interface* self); +void GetDLCContentInfoCount(Service::Interface* self); /** * AM::DeleteTicket service function diff --git a/src/core/hle/service/am/am_app.cpp b/src/core/hle/service/am/am_app.cpp index 4007e2d1c..2be9582bb 100644 --- a/src/core/hle/service/am/am_app.cpp +++ b/src/core/hle/service/am/am_app.cpp @@ -9,7 +9,7 @@ namespace Service { namespace AM { const Interface::FunctionInfo FunctionTable[] = { - {0x100100C0, GetNumContentInfos, "GetNumContentInfos"}, + {0x100100C0, GetDLCContentInfoCount, "GetDLCContentInfoCount"}, {0x10020104, FindDLCContentInfos, "FindDLCContentInfos"}, {0x10030142, ListDLCContentInfos, "ListDLCContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"}, diff --git a/src/core/hle/service/am/am_sys.cpp b/src/core/hle/service/am/am_sys.cpp index 921221f39..a809ef4ca 100644 --- a/src/core/hle/service/am/am_sys.cpp +++ b/src/core/hle/service/am/am_sys.cpp @@ -54,7 +54,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x002B0142, nullptr, "ListExistingContentInfosSystem"}, {0x002C0084, nullptr, "GetProgramInfosIgnorePlatform"}, {0x002D00C0, CheckContentRightsIgnorePlatform, "CheckContentRightsIgnorePlatform"}, - {0x100100C0, GetNumContentInfos, "GetNumContentInfos"}, + {0x100100C0, GetDLCContentInfoCount, "GetDLCContentInfoCount"}, {0x10020104, FindDLCContentInfos, "FindDLCContentInfos"}, {0x10030142, ListDLCContentInfos, "ListDLCContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"},