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
This commit is contained in:
project-bo4
2023-05-11 13:50:11 -07:00
parent 7e2d784c22
commit 354d022967
98 changed files with 5460 additions and 87 deletions

View File

@ -563,6 +563,46 @@ namespace utils::cryptography
return string::dump_hex(hash, "");
}
std::string md5::compute(const std::string& data, const bool hex)
{
return compute(cs(data.data()), data.size(), hex);
}
std::string md5::compute(const uint8_t* data, const size_t length, const bool hex)
{
uint8_t buffer[16] = { 0 };
hash_state state;
md5_init(&state);
md5_process(&state, data, ul(length));
md5_done(&state, buffer);
std::string hash(cs(buffer), sizeof(buffer));
if (!hex) return hash;
return string::dump_hex(hash, "");
}
uint32_t xxh32::compute(const std::string& data)
{
return compute(cs(data.data()), data.size());
}
uint32_t xxh32::compute(const uint8_t* data, const size_t length)
{
return XXHash32::hash(data, length, 0);
}
uint64_t xxh64::compute(const std::string& data)
{
return compute(cs(data.data()), data.size());
}
uint64_t xxh64::compute(const uint8_t* data, const size_t length)
{
return XXHash64::hash(data, length, 0);
}
std::string base64::encode(const uint8_t* data, const size_t len)
{
std::string result;

View File

@ -2,6 +2,8 @@
#include <string>
#include <tomcrypt.h>
#include <xxhash32.h>
#include <xxhash64.h>
namespace utils::cryptography
{
@ -96,6 +98,24 @@ namespace utils::cryptography
std::string compute(const uint8_t* data, size_t length, bool hex = false);
}
namespace md5
{
std::string compute(const std::string& data, bool hex = false);
std::string compute(const uint8_t* data, size_t length, bool hex = false);
}
namespace xxh32
{
uint32_t compute(const std::string& data);
uint32_t compute(const uint8_t* data, size_t length);
}
namespace xxh64
{
uint64_t compute(const std::string& data);
uint64_t compute(const uint8_t* data, size_t length);
}
namespace base64
{
std::string encode(const uint8_t* data, size_t len);

View File

@ -1,11 +1,12 @@
#include "smbios.hpp"
#include "identity.hpp"
#include "memory.hpp"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <intrin.h>
#include <lmcons.h>
namespace utils::smbios
namespace utils::identity
{
namespace
{
@ -61,7 +62,19 @@ namespace utils::smbios
}
}
std::string get_uuid()
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()
{
auto smbios_data = get_smbios_data();
auto* raw_data = reinterpret_cast<RawSMBIOSData*>(smbios_data.data());

View File

@ -0,0 +1,9 @@
#pragma once
#include <string>
namespace utils::identity
{
std::string get_sys_username();
std::string get_sys_uuid();
}

View File

@ -78,6 +78,14 @@ namespace utils::io
return false;
}
std::string file_name(const std::string& path)
{
const auto pos = path.find_last_of('/');
if (pos == std::string::npos) return path;
return path.substr(pos + 1);
}
size_t file_size(const std::string& file)
{
if (file_exists(file))
@ -94,6 +102,13 @@ namespace utils::io
return 0;
}
time_t file_timestamp(const std::string& file)
{
const auto time = std::chrono::clock_cast<std::chrono::system_clock>(std::filesystem::last_write_time(file));
return std::chrono::system_clock::to_time_t(time);
}
bool create_directory(const std::string& directory)
{
return std::filesystem::create_directories(directory);
@ -115,6 +130,8 @@ namespace utils::io
for (auto& file : std::filesystem::directory_iterator(directory))
{
if (std::filesystem::is_directory(file.path())) continue;
files.push_back(file.path().generic_string());
}

View File

@ -12,7 +12,9 @@ namespace utils::io
bool write_file(const std::string& file, const std::string& data, bool append = false);
bool read_file(const std::string& file, std::string* data);
std::string read_file(const std::string& file);
std::string file_name(const std::string& path);
size_t file_size(const std::string& file);
time_t file_timestamp(const std::string& file);
bool create_directory(const std::string& directory);
bool directory_exists(const std::string& directory);
bool directory_is_empty(const std::string& directory);

View File

@ -0,0 +1,184 @@
#include "json_config.hpp"
#include "io.hpp"
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
namespace utils::json_config
{
rapidjson::Document json_doc{};
std::string file_name = "project-bo4.json";
namespace
{
bool read_json_config()
{
std::string json_data{};
if (!io::read_file(file_name, &json_data)) return false;
json_doc.Parse(json_data);
if (json_doc.HasParseError()) {
return false;
}
return true;
}
bool write_json_config()
{
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
json_doc.Accept(writer);
std::string json_data(buffer.GetString(), buffer.GetLength());
if (!io::write_file(file_name, json_data)) return false;
return true;
}
}
rapidjson::Document& get_json_document()
{
static bool json_initialized = false;
if (!json_initialized)
{
if (!read_json_config()) {
json_doc = rapidjson::Document(rapidjson::kObjectType);
}
json_initialized = true;
}
/*if (json_doc != NULL) */return json_doc;
}
rapidjson::Value& get_json_section(const char* szSection)
{
rapidjson::Document& doc = get_json_document();
if (!doc.HasMember(szSection))
{
doc.AddMember(rapidjson::StringRef(szSection), rapidjson::kObjectType, doc.GetAllocator());
}
rapidjson::Value& section = doc[szSection];
if (!section.IsObject()) section.SetObject();
return section;
}
std::string ReadString(const char* szSection, const char* szKey, const std::string& strDefaultValue)
{
rapidjson::Document& doc = get_json_document();
rapidjson::Value& section = get_json_section(szSection);
if (!section.HasMember(szKey)) {
section.AddMember(rapidjson::StringRef(szKey), strDefaultValue, doc.GetAllocator());
}
else if (!section[szKey].IsString()) {
section[szKey].SetString(strDefaultValue, doc.GetAllocator());
}
else {
return section[szKey].GetString();
}
write_json_config();
return section[szKey].GetString();
}
void WriteString(const char* szSection, const char* szKey, const std::string& strValue)
{
rapidjson::Document& doc = get_json_document();
rapidjson::Value& section = get_json_section(szSection);
if (!section.HasMember(szKey)) {
section.AddMember(rapidjson::StringRef(szKey), strValue, doc.GetAllocator());
}
else {
section[szKey].SetString(strValue, doc.GetAllocator());
}
write_json_config();
}
unsigned int ReadUnsignedInteger(const char* szSection, const char* szKey, unsigned int iDefaultValue)
{
rapidjson::Document& doc = get_json_document();
rapidjson::Value& section = get_json_section(szSection);
if (!section.HasMember(szKey)) {
section.AddMember(rapidjson::StringRef(szKey), iDefaultValue, doc.GetAllocator());
}
else if (!section[szKey].IsUint()) {
section[szKey].SetUint(iDefaultValue);
}
else {
return section[szKey].GetUint();
}
write_json_config();
return section[szKey].GetUint();
}
int ReadInteger(const char* szSection, const char* szKey, int iDefaultValue)
{
return static_cast<int>(ReadUnsignedInteger(szSection, szKey, static_cast<unsigned int>(iDefaultValue)));
}
void WriteUnsignedInteger(const char* szSection, const char* szKey, unsigned int iValue)
{
rapidjson::Document& doc = get_json_document();
rapidjson::Value& section = get_json_section(szSection);
if (!section.HasMember(szKey)) {
section.AddMember(rapidjson::StringRef(szKey), iValue, doc.GetAllocator());
}
else {
section[szKey].SetUint(iValue);
}
write_json_config();
}
void WriteInteger(const char* szSection, const char* szKey, int iValue)
{
ReadUnsignedInteger(szSection, szKey, static_cast<unsigned int>(iValue));
}
bool ReadBoolean(const char* szSection, const char* szKey, bool bolDefaultValue)
{
rapidjson::Document& doc = get_json_document();
rapidjson::Value& section = get_json_section(szSection);
if (!section.HasMember(szKey)) {
section.AddMember(rapidjson::StringRef(szKey), bolDefaultValue, doc.GetAllocator());
}
else if (!section[szKey].IsBool()) {
section[szKey].SetBool(bolDefaultValue);
}
else {
return section[szKey].GetBool();
}
write_json_config();
return section[szKey].GetBool();
}
void WriteBoolean(const char* szSection, const char* szKey, bool bolValue)
{
rapidjson::Document& doc = get_json_document();
rapidjson::Value& section = get_json_section(szSection);
if (!section.HasMember(szKey)) {
section.AddMember(rapidjson::StringRef(szKey), bolValue, doc.GetAllocator());
}
else {
section[szKey].SetBool(bolValue);
}
write_json_config();
}
}

View File

@ -0,0 +1,17 @@
#pragma once
#include <string>
namespace utils::json_config
{
std::string ReadString(const char* szSection, const char* szKey, const std::string& strDefaultValue);
void WriteString(const char* szSection, const char* szKey, const std::string& strValue);
unsigned int ReadUnsignedInteger(const char* szSection, const char* szKey, unsigned int iDefaultValue);
void WriteUnsignedInteger(const char* szSection, const char* szKey, unsigned int iValue);
int ReadInteger(const char* szSection, const char* szKey, int iDefaultValue);
void WriteInteger(const char* szSection, const char* szKey, int iValue);
bool ReadBoolean(const char* szSection, const char* szKey, bool bolDefaultValue);
void WriteBoolean(const char* szSection, const char* szKey, bool bolValue);
}

View File

@ -1,8 +0,0 @@
#pragma once
#include <string>
namespace utils::smbios
{
std::string get_uuid();
}

View File

@ -34,6 +34,23 @@ namespace utils::string
return elems;
}
std::vector<std::string> split(const std::string& s, const std::string& delim)
{
size_t pos_start = 0, pos_end, delim_len = delim.length();
std::string token;
std::vector<std::string> elems;
while ((pos_end = s.find(delim, pos_start)) != std::string::npos) {
token = s.substr(pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
elems.push_back(token);
}
elems.push_back(s.substr(pos_start));
return elems;
}
std::string to_lower(std::string text)
{
std::transform(text.begin(), text.end(), text.begin(), [](const char input)

View File

@ -81,6 +81,7 @@ namespace utils::string
const char* va(const char* fmt, ...);
std::vector<std::string> split(const std::string& s, char delim);
std::vector<std::string> split(const std::string& s, const std::string& delim);
std::string to_lower(std::string text);
std::string to_upper(std::string text);