mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-12-25 09:54:15 +08:00
completely refactor the serialization of AppTicketGC
+ avoid any magical numbers as much as possible & calculate the required size via sizeof() + use a macro to serialize a single field & increment the pointer at the same time + added some more debug statements
This commit is contained in:
parent
342d0a27b5
commit
e379220e16
78
dll/auth.h
78
dll/auth.h
@ -71,22 +71,70 @@ private:
|
|||||||
public:
|
public:
|
||||||
std::vector<uint8_t> Serialize()
|
std::vector<uint8_t> Serialize()
|
||||||
{
|
{
|
||||||
|
const uint64_t steam_id = id.ConvertToUint64();
|
||||||
|
|
||||||
|
// must be 52
|
||||||
|
constexpr size_t total_size =
|
||||||
|
sizeof(STEAM_APPTICKET_GCLen) +
|
||||||
|
sizeof(GCToken) +
|
||||||
|
sizeof(steam_id) +
|
||||||
|
sizeof(ticketGenDate) +
|
||||||
|
sizeof(STEAM_APPTICKET_SESSIONLEN) +
|
||||||
|
sizeof(one) +
|
||||||
|
sizeof(two) +
|
||||||
|
sizeof(ExternalIP) +
|
||||||
|
sizeof(InternalIP) +
|
||||||
|
sizeof(TimeSinceStartup) +
|
||||||
|
sizeof(TicketGeneratedCount);
|
||||||
|
|
||||||
|
// check the size at compile time, we must ensure the correct size
|
||||||
|
#ifndef EMU_RELEASE_BUILD
|
||||||
|
static_assert(
|
||||||
|
total_size == 52,
|
||||||
|
"AUTH::AppTicketGC::SER calculated size of serialized data != 52 bytes, your compiler has some incorrect sizes"
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PRINT_DEBUG(
|
||||||
|
"AUTH::AppTicketGC::SER Token:\n"
|
||||||
|
" GCToken: %I64u\n"
|
||||||
|
" user steam_id: %I64u\n"
|
||||||
|
" ticketGenDate: %u\n"
|
||||||
|
" ExternalIP: 0x%08X, InternalIP: 0x%08X\n"
|
||||||
|
" TimeSinceStartup: %u, TicketGeneratedCount: %u\n"
|
||||||
|
" SER size = %zu\n",
|
||||||
|
|
||||||
|
GCToken,
|
||||||
|
steam_id,
|
||||||
|
ticketGenDate,
|
||||||
|
ExternalIP, InternalIP,
|
||||||
|
TimeSinceStartup, TicketGeneratedCount,
|
||||||
|
total_size
|
||||||
|
);
|
||||||
|
|
||||||
std::vector<uint8_t> buffer;
|
std::vector<uint8_t> buffer;
|
||||||
uint8_t* pBuffer;
|
buffer.resize(total_size);
|
||||||
buffer.resize(52);
|
|
||||||
pBuffer = buffer.data();
|
uint8_t* pBuffer = buffer.data();
|
||||||
PRINT_DEBUG("AppTicketGC: Token: %I64u Startup: %u count: %u", GCToken, TimeSinceStartup, TicketGeneratedCount);
|
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = STEAM_APPTICKET_GCLen; pBuffer += 4;
|
#define SER_VAR(v) \
|
||||||
*reinterpret_cast<uint64_t*>(pBuffer) = GCToken; pBuffer += 8;
|
*reinterpret_cast<std::remove_const<decltype(v)>::type *>(pBuffer) = v; \
|
||||||
*reinterpret_cast<uint64_t*>(pBuffer) = id.ConvertToUint64(); pBuffer += 8;
|
pBuffer += sizeof(v)
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = ticketGenDate; pBuffer += 4;
|
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = STEAM_APPTICKET_SESSIONLEN; pBuffer += 4;
|
SER_VAR(STEAM_APPTICKET_GCLen);
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = one; pBuffer += 4;
|
SER_VAR(GCToken);
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = two; pBuffer += 4;
|
SER_VAR(steam_id);
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = ExternalIP; pBuffer += 4;
|
SER_VAR(ticketGenDate);
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = InternalIP; pBuffer += 4;
|
SER_VAR(STEAM_APPTICKET_SESSIONLEN);
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = TimeSinceStartup; pBuffer += 4;
|
SER_VAR(one);
|
||||||
*reinterpret_cast<uint32_t*>(pBuffer) = TicketGeneratedCount; pBuffer += 4;
|
SER_VAR(two);
|
||||||
|
SER_VAR(ExternalIP);
|
||||||
|
SER_VAR(InternalIP);
|
||||||
|
SER_VAR(TimeSinceStartup);
|
||||||
|
SER_VAR(TicketGeneratedCount);
|
||||||
|
|
||||||
|
#undef SER_VAR
|
||||||
|
|
||||||
#ifndef EMU_RELEASE_BUILD
|
#ifndef EMU_RELEASE_BUILD
|
||||||
// we nedd a live object until the printf does its job, hence this special handling
|
// we nedd a live object until the printf does its job, hence this special handling
|
||||||
auto str = uint8_vector_to_hex_string(buffer);
|
auto str = uint8_vector_to_hex_string(buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user