From 56aedd6817ff58992272bca9a6bee86a6355a376 Mon Sep 17 00:00:00 2001 From: Daiyuu Nobori Date: Tue, 22 Feb 2022 19:37:29 +0100 Subject: [PATCH 1/2] Memory: Add LittleEndian16(), LittleEndian32() and LittleEndian64() --- src/Mayaqua/Memory.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Mayaqua/Memory.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/src/Mayaqua/Memory.c b/src/Mayaqua/Memory.c index 8e97f8c1..315f89c0 100644 --- a/src/Mayaqua/Memory.c +++ b/src/Mayaqua/Memory.c @@ -3373,6 +3373,48 @@ UINT64 Endian64(UINT64 src) } } +// Endian conversion 16bit +USHORT LittleEndian16(USHORT src) +{ + int x = 0x01000000; + if (*((char *)&x)) + { + return Swap16(src); + } + else + { + return src; + } +} + +// Endian conversion 32bit +UINT LittleEndian32(UINT src) +{ + int x = 0x01000000; + if (*((char *)&x)) + { + return Swap32(src); + } + else + { + return src; + } +} + +// Endian conversion 64bit +UINT64 LittleEndian64(UINT64 src) +{ + int x = 0x01000000; + if (*((char *)&x)) + { + return Swap64(src); + } + else + { + return src; + } +} + // 16bit swap USHORT Swap16(USHORT value) { diff --git a/src/Mayaqua/Memory.h b/src/Mayaqua/Memory.h index c2b7029b..8b39cd9d 100644 --- a/src/Mayaqua/Memory.h +++ b/src/Mayaqua/Memory.h @@ -199,6 +199,9 @@ UINT64 Swap64(UINT64 value); USHORT Endian16(USHORT src); UINT Endian32(UINT src); UINT64 Endian64(UINT64 src); +USHORT LittleEndian16(USHORT src); +UINT LittleEndian32(UINT src); +UINT64 LittleEndian64(UINT64 src); void EndianUnicode(wchar_t *str); BUF *NewBuf(); From 32a970f97667a73b8f956cf1cee9b9cc60dee46d Mon Sep 17 00:00:00 2001 From: Daiyuu Nobori Date: Tue, 22 Feb 2022 19:38:13 +0100 Subject: [PATCH 2/2] Admin.c: Fix wrong endianness in InRpcNodeInfo() and OutRpcNodeInfo() --- src/Cedar/Admin.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Cedar/Admin.c b/src/Cedar/Admin.c index 4ce38745..c881316e 100644 --- a/src/Cedar/Admin.c +++ b/src/Cedar/Admin.c @@ -14658,19 +14658,19 @@ void InRpcNodeInfo(NODE_INFO *t, PACK *p) PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName)); PackGetData2(p, "UniqueId", t->UniqueId, sizeof(t->UniqueId)); - t->ClientProductVer = PackGetInt(p, "ClientProductVer"); - t->ClientProductBuild = PackGetInt(p, "ClientProductBuild"); - t->ServerProductVer = PackGetInt(p, "ServerProductVer"); - t->ServerProductBuild = PackGetInt(p, "ServerProductBuild"); + t->ClientProductVer = LittleEndian32(PackGetInt(p, "ClientProductVer")); + t->ClientProductBuild = LittleEndian32(PackGetInt(p, "ClientProductBuild")); + t->ServerProductVer = LittleEndian32(PackGetInt(p, "ServerProductVer")); + t->ServerProductBuild = LittleEndian32(PackGetInt(p, "ServerProductBuild")); t->ClientIpAddress = PackGetIp32(p, "ClientIpAddress"); PackGetData2(p, "ClientIpAddress6", t->ClientIpAddress6, sizeof(t->ClientIpAddress6)); - t->ClientPort = PackGetInt(p, "ClientPort"); + t->ClientPort = LittleEndian32(PackGetInt(p, "ClientPort")); t->ServerIpAddress = PackGetIp32(p, "ServerIpAddress"); PackGetData2(p, "ServerIpAddress6", t->ServerIpAddress6, sizeof(t->ServerIpAddress6)); - t->ServerPort = PackGetInt(p, "ServerPort2"); + t->ServerPort = LittleEndian32(PackGetInt(p, "ServerPort2")); t->ProxyIpAddress = PackGetIp32(p, "ProxyIpAddress"); PackGetData2(p, "ProxyIpAddress6", t->ProxyIpAddress6, sizeof(t->ProxyIpAddress6)); - t->ProxyPort = PackGetInt(p, "ProxyPort"); + t->ProxyPort = LittleEndian32(PackGetInt(p, "ProxyPort")); } void OutRpcNodeInfo(PACK *p, NODE_INFO *t) { @@ -14691,19 +14691,19 @@ void OutRpcNodeInfo(PACK *p, NODE_INFO *t) PackAddStr(p, "HubName", t->HubName); PackAddData(p, "UniqueId", t->UniqueId, sizeof(t->UniqueId)); - PackAddInt(p, "ClientProductVer", t->ClientProductVer); - PackAddInt(p, "ClientProductBuild", t->ClientProductBuild); - PackAddInt(p, "ServerProductVer", t->ServerProductVer); - PackAddInt(p, "ServerProductBuild", t->ServerProductBuild); + PackAddInt(p, "ClientProductVer", LittleEndian32(t->ClientProductVer)); + PackAddInt(p, "ClientProductBuild", LittleEndian32(t->ClientProductBuild)); + PackAddInt(p, "ServerProductVer", LittleEndian32(t->ServerProductVer)); + PackAddInt(p, "ServerProductBuild", LittleEndian32(t->ServerProductBuild)); PackAddIp32(p, "ClientIpAddress", t->ClientIpAddress); PackAddData(p, "ClientIpAddress6", t->ClientIpAddress6, sizeof(t->ClientIpAddress6)); - PackAddInt(p, "ClientPort", t->ClientPort); + PackAddInt(p, "ClientPort", LittleEndian32(t->ClientPort)); PackAddIp32(p, "ServerIpAddress", t->ServerIpAddress); PackAddData(p, "ServerIpAddress6", t->ServerIpAddress6, sizeof(t->ServerIpAddress6)); - PackAddInt(p, "ServerPort2", t->ServerPort); + PackAddInt(p, "ServerPort2", LittleEndian32(t->ServerPort)); PackAddIp32(p, "ProxyIpAddress", t->ProxyIpAddress); PackAddData(p, "ProxyIpAddress6", t->ProxyIpAddress6, sizeof(t->ProxyIpAddress6)); - PackAddInt(p, "ProxyPort", t->ProxyPort); + PackAddInt(p, "ProxyPort", LittleEndian32(t->ProxyPort)); } // RPC_SESSION_STATUS