t8-mod/source/shared-code/utilities/identity.cpp

108 lines
2.2 KiB
C++
Raw Normal View History

Squashed commit of the following: commit f44d146e4ac906ff898e8968c6857fd2280f6d20 Author: project-bo4 <127137346+project-bo4@users.noreply.github.com> Date: Thu May 11 13:39:29 2023 -0700 remove lpc package from repository commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu May 11 13:06:13 2023 -0700 generic improvements + added identity configuration + objectstore improvements + added battlenet 'US' servers to blocklist + some other minor improvements commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7 Author: project-bo4 <themanwithantidote@gmail.com> Date: Sat Mar 25 16:32:52 2023 -0700 lpc improvements + fix lpc issue with foreign languages(non-english) not being considered in listing + check lpc files pre-start and warn user if missing any of core items commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu Mar 23 12:45:56 2023 -0700 demonware improvements + handle object store uploadUserObject + silence bdUNK125 commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 13:43:56 2023 -0700 forgot to update names commit 217682dfb07b35f7a09399fb2698924bb7fe8b77 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 11:09:18 2023 -0700 upload lpc and update readme commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 10:53:43 2023 -0700 demonware emulator + demonware emulator + platform name and id + xxhash and picoproto - remove g_runframe hook -disable discovery(save time) + improvements to utils + add new resources
2023-05-11 16:50:11 -04:00
#include "identity.hpp"
2023-03-06 15:40:07 -05:00
#include "memory.hpp"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <intrin.h>
Squashed commit of the following: commit f44d146e4ac906ff898e8968c6857fd2280f6d20 Author: project-bo4 <127137346+project-bo4@users.noreply.github.com> Date: Thu May 11 13:39:29 2023 -0700 remove lpc package from repository commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu May 11 13:06:13 2023 -0700 generic improvements + added identity configuration + objectstore improvements + added battlenet 'US' servers to blocklist + some other minor improvements commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7 Author: project-bo4 <themanwithantidote@gmail.com> Date: Sat Mar 25 16:32:52 2023 -0700 lpc improvements + fix lpc issue with foreign languages(non-english) not being considered in listing + check lpc files pre-start and warn user if missing any of core items commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu Mar 23 12:45:56 2023 -0700 demonware improvements + handle object store uploadUserObject + silence bdUNK125 commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 13:43:56 2023 -0700 forgot to update names commit 217682dfb07b35f7a09399fb2698924bb7fe8b77 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 11:09:18 2023 -0700 upload lpc and update readme commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 10:53:43 2023 -0700 demonware emulator + demonware emulator + platform name and id + xxhash and picoproto - remove g_runframe hook -disable discovery(save time) + improvements to utils + add new resources
2023-05-11 16:50:11 -04:00
#include <lmcons.h>
2023-03-06 15:40:07 -05:00
2023-11-10 16:52:20 -05:00
namespace utilities::identity
2023-03-06 15:40:07 -05:00
{
namespace
{
#pragma warning(push)
#pragma warning(disable: 4200)
struct RawSMBIOSData
{
BYTE Used20CallingMethod;
BYTE SMBIOSMajorVersion;
BYTE SMBIOSMinorVersion;
BYTE DmiRevision;
DWORD Length;
BYTE SMBIOSTableData[];
};
typedef struct
{
BYTE type;
BYTE length;
WORD handle;
} dmi_header;
#pragma warning(pop)
std::vector<uint8_t> get_smbios_data()
{
DWORD size = 0;
std::vector<uint8_t> data{};
size = GetSystemFirmwareTable('RSMB', 0, nullptr, size);
data.resize(size);
GetSystemFirmwareTable('RSMB', 0, data.data(), size);
return data;
}
std::string parse_uuid(const uint8_t* data)
{
2023-11-10 16:52:20 -05:00
if (utilities::memory::is_set(data, 0, 16) || utilities::memory::is_set(data, -1, 16))
2023-03-06 15:40:07 -05:00
{
return {};
}
char uuid[16] = {0};
*reinterpret_cast<unsigned long*>(uuid + 0) =
_byteswap_ulong(*reinterpret_cast<const unsigned long*>(data + 0));
*reinterpret_cast<unsigned short*>(uuid + 4) =
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 4));
*reinterpret_cast<unsigned short*>(uuid + 6) =
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 6));
memcpy(uuid + 8, data + 8, 8);
return std::string(uuid, sizeof(uuid));
}
}
Squashed commit of the following: commit f44d146e4ac906ff898e8968c6857fd2280f6d20 Author: project-bo4 <127137346+project-bo4@users.noreply.github.com> Date: Thu May 11 13:39:29 2023 -0700 remove lpc package from repository commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu May 11 13:06:13 2023 -0700 generic improvements + added identity configuration + objectstore improvements + added battlenet 'US' servers to blocklist + some other minor improvements commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7 Author: project-bo4 <themanwithantidote@gmail.com> Date: Sat Mar 25 16:32:52 2023 -0700 lpc improvements + fix lpc issue with foreign languages(non-english) not being considered in listing + check lpc files pre-start and warn user if missing any of core items commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu Mar 23 12:45:56 2023 -0700 demonware improvements + handle object store uploadUserObject + silence bdUNK125 commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 13:43:56 2023 -0700 forgot to update names commit 217682dfb07b35f7a09399fb2698924bb7fe8b77 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 11:09:18 2023 -0700 upload lpc and update readme commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 10:53:43 2023 -0700 demonware emulator + demonware emulator + platform name and id + xxhash and picoproto - remove g_runframe hook -disable discovery(save time) + improvements to utils + add new resources
2023-05-11 16:50:11 -04:00
std::string get_sys_username()
{
char username[UNLEN + 1];
DWORD username_len = UNLEN + 1;
if (!GetUserNameA(username, &username_len))
{
return "N/A";
}
return std::string{ username, username_len - 1 };
}
std::string get_sys_uuid()
2023-03-06 15:40:07 -05:00
{
auto smbios_data = get_smbios_data();
auto* raw_data = reinterpret_cast<RawSMBIOSData*>(smbios_data.data());
auto* data = raw_data->SMBIOSTableData;
for (DWORD i = 0; i + sizeof(dmi_header) < raw_data->Length;)
{
auto* header = reinterpret_cast<dmi_header*>(data + i);
if (header->length < 4)
{
return {};
}
if (header->type == 0x01 && header->length >= 0x19)
{
return parse_uuid(data + i + 0x8);
}
i += header->length;
while ((i + 1) < raw_data->Length && *reinterpret_cast<uint16_t*>(data + i) != 0)
{
++i;
}
i += 2;
}
return {};
}
}