Merge pull request #5650 from leoetlino/check-contents

IOS/ES: Add some sanity checks to ImportTitleDone
This commit is contained in:
shuffle2 2017-06-21 20:13:44 -07:00 committed by GitHub
commit 09edd62cce
3 changed files with 26 additions and 2 deletions

View File

@ -61,6 +61,11 @@ bool Content::IsShared() const
return (type & 0x8000) != 0; return (type & 0x8000) != 0;
} }
bool Content::IsOptional() const
{
return (type & 0x4000) != 0;
}
SignedBlobReader::SignedBlobReader(const std::vector<u8>& bytes) : m_bytes(bytes) SignedBlobReader::SignedBlobReader(const std::vector<u8>& bytes) : m_bytes(bytes)
{ {
} }

View File

@ -83,6 +83,7 @@ static_assert(sizeof(TMDHeader) == 0x1e4, "TMDHeader has the wrong size");
struct Content struct Content
{ {
bool IsShared() const; bool IsShared() const;
bool IsOptional() const;
u32 id; u32 id;
u16 index; u16 index;
u16 type; u16 type;

View File

@ -350,7 +350,25 @@ IPCCommandResult ES::ImportContentEnd(Context& context, const IOCtlVRequest& req
ReturnCode ES::ImportTitleDone(Context& context) ReturnCode ES::ImportTitleDone(Context& context)
{ {
if (!context.title_import.tmd.IsValid()) if (!context.title_import.tmd.IsValid() || context.title_import.content_id != 0xFFFFFFFF)
return ES_EINVAL;
// Make sure all listed, non-optional contents have been imported.
const u64 title_id = context.title_import.tmd.GetTitleId();
const std::vector<IOS::ES::Content> contents = context.title_import.tmd.GetContents();
const IOS::ES::SharedContentMap shared_content_map{Common::FROM_SESSION_ROOT};
const bool has_all_required_contents =
std::all_of(contents.cbegin(), contents.cend(), [&](const IOS::ES::Content& content) {
if (content.IsOptional())
return true;
if (content.IsShared())
return shared_content_map.GetFilenameFromSHA1(content.sha1).has_value();
return File::Exists(Common::GetTitleContentPath(title_id, Common::FROM_SESSION_ROOT) +
StringFromFormat("%08x.app", content.id));
});
if (!has_all_required_contents)
return ES_EINVAL; return ES_EINVAL;
if (!WriteImportTMD(context.title_import.tmd)) if (!WriteImportTMD(context.title_import.tmd))
@ -359,7 +377,7 @@ ReturnCode ES::ImportTitleDone(Context& context)
if (!FinishImport(context.title_import.tmd)) if (!FinishImport(context.title_import.tmd))
return ES_EIO; return ES_EIO;
INFO_LOG(IOS_ES, "ImportTitleDone: title %016" PRIx64, context.title_import.tmd.GetTitleId()); INFO_LOG(IOS_ES, "ImportTitleDone: title %016" PRIx64, title_id);
context.title_import.tmd.SetBytes({}); context.title_import.tmd.SetBytes({});
return IPC_SUCCESS; return IPC_SUCCESS;
} }