Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS/ES: Implement ES_DIGetTicketView #5002

Merged
merged 1 commit into from
Mar 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 31 additions & 4 deletions Source/Core/Core/IOS/ES/ES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,6 @@ IPCCommandResult ES::IOCtlV(const IOCtlVRequest& request)
return Sign(request);
case IOCTL_ES_GETBOOT2VERSION:
return GetBoot2Version(request);

// Unsupported functions
case IOCTL_ES_DIGETTICKETVIEW:
return DIGetTicketView(request);
case IOCTL_ES_GETOWNEDTITLECNT:
Expand Down Expand Up @@ -1458,10 +1456,39 @@ IPCCommandResult ES::GetBoot2Version(const IOCtlVRequest& request)

IPCCommandResult ES::DIGetTicketView(const IOCtlVRequest& request)
{
if (!request.HasNumberOfValidVectors(0, 1) || request.io_vectors[0].size != 0xd8)
if (!request.HasNumberOfValidVectors(1, 1) ||
request.io_vectors[0].size != sizeof(IOS::ES::TicketView))
{
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
}

// TODO: unimplemented.
const bool has_ticket_vector = request.in_vectors[0].size == 0x2A4;

// This ioctlv takes either a signed ticket or no ticket, in which case the ticket size must be 0.
if (!has_ticket_vector && request.in_vectors[0].size != 0)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);

std::vector<u8> view;

// If no ticket was passed in, IOS returns the ticket view for the current title.
// Of course, this returns -1017 if no title is active and no ticket is passed.
if (!has_ticket_vector)
{
if (!s_title_context.active)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);

view = s_title_context.ticket.GetRawTicketView(0);
}
else
{
std::vector<u8> ticket_bytes(request.in_vectors[0].size);
Memory::CopyFromEmu(ticket_bytes.data(), request.in_vectors[0].address, ticket_bytes.size());
const IOS::ES::TicketReader ticket{std::move(ticket_bytes)};

view = ticket.GetRawTicketView(0);
}

Memory::CopyToEmu(request.io_vectors[0].address, view.data(), view.size());
return GetDefaultReply(IPC_SUCCESS);
}

Expand Down