mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-17 03:14:34 +01:00
NpAuth: Return the ticket param asked for, and write only what fits of a ticket
sceNpAuthGetTicketParam started reading after the body section, so it copied the footer, and it concatenated the params before the one asked for instead of returning that one. Like JPCSP, it now walks the params from the start of the body and returns the value of the requested one (ints and dates converted to PSP endianness, strings up to 255 bytes). sceNpAuthGetTicket wrote its whole 248 byte ticket whatever the buffer length. It now copies what fits, and still returns the ticket's size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f6118a7978
commit
adba2ed1af
1 file changed
+56
-34
+56
-34
@@ -431,14 +431,13 @@ int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length) {
|
||||
return hleLogError(Log::sceNet, SCE_NP_AUTH_ERROR_UNKNOWN, "Missing npOnlineId");
|
||||
}
|
||||
|
||||
int result = length;
|
||||
// Built here, then copied once we know it fits.
|
||||
u8 staging[512]{};
|
||||
// Built here and copied out, since the buffer can be shorter than the ticket.
|
||||
u8 ticketBuf[0xF0 + sizeof(SceNpTicketHeader)]{};
|
||||
SceNpTicket ticket = {};
|
||||
// Dummy Login ticket returned as Login response. Dummy ticket contents were taken from https://www.psdevwiki.com/ps3/X-I-5-Ticket
|
||||
ticket.header.version = TICKET_VER_2_1;
|
||||
ticket.header.size = 0xF0; // size excluding the header
|
||||
u8 *buf = staging + sizeof(ticket);
|
||||
u8 *buf = ticketBuf + sizeof(ticket);
|
||||
int ofs = 0;
|
||||
ofs += writeTicketParam(buf, PARAM_TYPE_STRING_ASCII, "\x4c\x47\x56\x3b\x81\x39\x4a\x22\xd8\x6b\xc1\x57\x71\x6e\xfd\xb8\xab\x63\xcc\x51", 20); // 20 random letters, token key or SceNpSignature?
|
||||
ofs += writeTicketU32Param(buf + ofs, PARAM_TYPE_INT, 0x0100); // a flags?
|
||||
@@ -464,24 +463,23 @@ int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length) {
|
||||
ofs += writeTicketParam(buf + ofs, PARAM_TYPE_NULL);
|
||||
ticket.section.type = SECTION_TYPE_BODY;
|
||||
ticket.section.size = ofs;
|
||||
memcpy(staging, &ticket, sizeof(SceNpTicket));
|
||||
memcpy(ticketBuf, &ticket, sizeof(SceNpTicket));
|
||||
SceNpTicketSection footer = { SECTION_TYPE_FOOTER, 32 }; // footer section? ie. 32-bytes on version 2.1 containing 4-chars ASCII + 20-chars ASCII
|
||||
memcpy(buf + ofs, &footer, sizeof(SceNpTicketSection));
|
||||
ofs += sizeof(footer);
|
||||
ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "\x34\xcd\x3c\xa9", 4);
|
||||
ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "\x3a\x4b\x42\x66\x92\xda\x6b\x7c\xb7\x4c\xe8\xd9\x4f\x2b\x77\x15\x91\xb8\xa4\xa9", 20); // 20 random letters, token key or SceNpSignature?
|
||||
// includes Language list? (36 zero bytes, staging is zeroed)
|
||||
const u32 total = (u32)sizeof(ticket) + ofs + 36;
|
||||
_dbg_assert_(total <= sizeof(staging));
|
||||
// includes Language list? (36 zero bytes, left by the initializer)
|
||||
_dbg_assert_(sizeof(ticket) + ofs + 36 == sizeof(ticketBuf));
|
||||
|
||||
// The whole ticket gets written, even if length is shorter.
|
||||
if (!Memory::IsValidRange(bufferAddr, std::max(length, total))) {
|
||||
// Like JPCSP's real ticket path, copy what fits.
|
||||
if (!Memory::IsValidRange(bufferAddr, length)) {
|
||||
return hleLogError(Log::sceNet, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid buffer");
|
||||
}
|
||||
Memory::Memset(bufferAddr, 0, length, "NpAuthGetTicket");
|
||||
Memory::Memcpy(bufferAddr, staging, total, "NpAuthGetTicket");
|
||||
Memory::Memcpy(bufferAddr, ticketBuf, std::min(length, (u32)sizeof(ticketBuf)), "NpAuthGetTicket");
|
||||
|
||||
result = ticket.header.size + sizeof(ticket.header); // dummy ticket is 248 bytes
|
||||
const int result = (int)sizeof(ticketBuf); // dummy ticket is 248 bytes
|
||||
|
||||
return hleLogWarning(Log::sceNet, result);
|
||||
}
|
||||
@@ -538,29 +536,53 @@ int sceNpAuthGetTicketParam(u32 ticketBufPtr, int ticketLen, int paramNum, u32 b
|
||||
return hleLogError(Log::sceNet, SCE_NP_MANAGER_ERROR_INVALID_ARGUMENT, "invalid ticket");
|
||||
}
|
||||
|
||||
const SceNpTicket *ticket = (const SceNpTicket *)Memory::GetPointerUnchecked(ticketBufPtr);
|
||||
const u32 ticketEnd = ticketBufPtr + ticketLen;
|
||||
u32 inbuf = ticketBufPtr;
|
||||
inbuf += sizeof(ticket->header);
|
||||
inbuf += ticket->section.size + sizeof(ticket->section);
|
||||
u32 outbuf = bufferPtr;
|
||||
for (int i = 0; i < paramNum; i++) {
|
||||
// Only copy params that are inside the ticket and fit in the output.
|
||||
if (inbuf < ticketBufPtr || inbuf + sizeof(SceNpTicketParamData) > ticketEnd)
|
||||
break;
|
||||
const SceNpTicketParamData *ticketParam = (const SceNpTicketParamData *)Memory::GetPointerUnchecked(inbuf);
|
||||
u32 sz = (u32)sizeof(SceNpTicketParamData) + ticketParam->length;
|
||||
if (sz > ticketEnd - inbuf || sz > PARAM_BUFFER_MAX_SIZE - (outbuf - bufferPtr))
|
||||
break;
|
||||
Memory::MemcpyUnchecked(outbuf, inbuf, sz);
|
||||
DEBUG_LOG(Log::sceNet, "%s - Param #%d: Type = %04x, Length = %u", __FUNCTION__, i, static_cast<unsigned int>(ticketParam->type), static_cast<unsigned int>(ticketParam->length));
|
||||
outbuf += sz;
|
||||
inbuf += sz;
|
||||
if (outbuf - bufferPtr >= PARAM_BUFFER_MAX_SIZE || inbuf - ticketBufPtr >= (u32)ticketLen)
|
||||
break;
|
||||
}
|
||||
// Like JPCSP: the params follow the header and the body section delimiter, and only the value of
|
||||
// the one asked for is returned.
|
||||
const u32 ticketEnd = ticketBufPtr + (u32)ticketLen;
|
||||
u32 inbuf = ticketBufPtr + (u32)sizeof(SceNpTicket);
|
||||
for (int i = 0; ; i++) {
|
||||
if (inbuf + sizeof(SceNpTicketParamData) > ticketEnd || !Memory::IsValidRange(inbuf, sizeof(SceNpTicketParamData))) {
|
||||
return hleLogWarning(Log::sceNet, 0, "Ticket ends before param %d", paramNum);
|
||||
}
|
||||
SceNpTicketParamData param;
|
||||
Memory::Memcpy(¶m, inbuf, sizeof(param));
|
||||
const u32 valuePtr = inbuf + (u32)sizeof(param);
|
||||
const u32 length = param.length;
|
||||
inbuf = valuePtr + length;
|
||||
if (i < paramNum) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return hleLogWarning(Log::sceNet, 0);
|
||||
if (inbuf > ticketEnd || !Memory::IsValidRange(valuePtr, length)) {
|
||||
return hleLogWarning(Log::sceNet, 0, "Param %d runs past the ticket", paramNum);
|
||||
}
|
||||
DEBUG_LOG(Log::sceNet, "%s - Param #%d: Type = %04x, Length = %u", __FUNCTION__, paramNum, (u32)param.type, length);
|
||||
switch ((u16)param.type) {
|
||||
case PARAM_TYPE_INT:
|
||||
if (length >= 4) {
|
||||
u32_be value;
|
||||
Memory::Memcpy(&value, valuePtr, sizeof(value));
|
||||
Memory::WriteUnchecked_U32(value, bufferPtr);
|
||||
}
|
||||
break;
|
||||
case PARAM_TYPE_LONG:
|
||||
case PARAM_TYPE_DATE:
|
||||
if (length >= 8) {
|
||||
u64_be value;
|
||||
Memory::Memcpy(&value, valuePtr, sizeof(value));
|
||||
Memory::WriteUnchecked_U64(value, bufferPtr);
|
||||
}
|
||||
break;
|
||||
case PARAM_TYPE_STRING:
|
||||
case PARAM_TYPE_STRING_ASCII:
|
||||
// At most 255 bytes, leaving the terminator from the clear above.
|
||||
Memory::Memcpy(bufferPtr, valuePtr, std::min(length, PARAM_BUFFER_MAX_SIZE - 1), "NpAuthGetTicketParam");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return hleLogDebug(Log::sceNet, 0);
|
||||
}
|
||||
}
|
||||
|
||||
const HLEFunction sceNpAuth[] = {
|
||||
|
||||
Reference in new issue
Block a user