From 4b0726d97788edff5d83476cb52057f409d623af Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 4 Mar 2024 00:01:32 +0000 Subject: Update silver-bun to `72c74b4` (#664) Bumps the vendored silver-bun library to the newest commit in upstream Co-authored-by: F1F7Y Co-authored-by: IcePixelx <41352111+IcePixelx@users.noreply.github.com> --- primedev/thirdparty/silver-bun/utils.cpp | 127 +++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 primedev/thirdparty/silver-bun/utils.cpp (limited to 'primedev/thirdparty/silver-bun/utils.cpp') diff --git a/primedev/thirdparty/silver-bun/utils.cpp b/primedev/thirdparty/silver-bun/utils.cpp new file mode 100644 index 00000000..6f7b397e --- /dev/null +++ b/primedev/thirdparty/silver-bun/utils.cpp @@ -0,0 +1,127 @@ +#include "utils.h" + +namespace Utils +{ + //---------------------------------------------------------------------------------------- + // Purpose: For converting a string pattern to an array of bytes. Doesnt support wildcards + //---------------------------------------------------------------------------------------- + std::vector StringPatternToBytes(const char* szInput) + { + const char* pszPatternStart = const_cast(szInput); + const char* pszPatternEnd = pszPatternStart + strlen(szInput); + std::vector vBytes; + + for (const char* pszCurrentByte = pszPatternStart; pszCurrentByte < pszPatternEnd; ++pszCurrentByte) + { + vBytes.push_back(strtoul(pszCurrentByte, const_cast(&pszCurrentByte), 16)); + } + return vBytes; + }; + + //---------------------------------------------------------------------------------------- + // Purpose: For converting a string pattern with wildcards to an array of bytes. + //---------------------------------------------------------------------------------------- + std::vector PatternToBytes(const char* szInput) + { + const char* pszPatternStart = const_cast(szInput); + const char* pszPatternEnd = pszPatternStart + strlen(szInput); + std::vector vBytes; + + for (const char* pszCurrentByte = pszPatternStart; pszCurrentByte < pszPatternEnd; ++pszCurrentByte) + { + if (*pszCurrentByte == '?') + { + ++pszCurrentByte; + if (*pszCurrentByte == '?') + { + ++pszCurrentByte; // Skip double wildcard. + } + vBytes.push_back(-1); // Push the byte back as invalid. + } + else + { + vBytes.push_back(strtoul(pszCurrentByte, const_cast(&pszCurrentByte), 16)); + } + } + return vBytes; + }; + + //---------------------------------------------------------------------------------------- + // Purpose: For converting a string pattern with wildcards to an array of bytes and mask. + //---------------------------------------------------------------------------------------- + std::pair, std::string> PatternToMaskedBytes(const char* szInput) + { + const char* pszPatternStart = const_cast(szInput); + const char* pszPatternEnd = pszPatternStart + strlen(szInput); + + std::vector vBytes; + std::string svMask; + + for (const char* pszCurrentByte = pszPatternStart; pszCurrentByte < pszPatternEnd; ++pszCurrentByte) + { + if (*pszCurrentByte == '?') + { + ++pszCurrentByte; + if (*pszCurrentByte == '?') + { + ++pszCurrentByte; // Skip double wildcard. + } + vBytes.push_back(0); // Push the byte back as invalid. + svMask += '?'; + } + else + { + vBytes.push_back(uint8_t(strtoul(pszCurrentByte, const_cast(&pszCurrentByte), 16))); + svMask += 'x'; + } + } + return make_pair(vBytes, svMask); + }; + + //---------------------------------------------------------------------------------------- + // Purpose: For converting a string to an array of bytes. + //---------------------------------------------------------------------------------------- + std::vector StringToBytes(const char* szInput, bool bNullTerminator) + { + const char* pszStringStart = const_cast(szInput); + const char* pszStringEnd = pszStringStart + strlen(szInput); + std::vector vBytes; + + for (const char* pszCurrentByte = pszStringStart; pszCurrentByte < pszStringEnd; ++pszCurrentByte) + { + // Dereference character and push back the byte. + vBytes.push_back(*pszCurrentByte); + } + + if (bNullTerminator) + { + vBytes.push_back('\0'); + } + return vBytes; + }; + + //---------------------------------------------------------------------------------------- + // Purpose: For converting a string to an array of masked bytes. + //---------------------------------------------------------------------------------------- + std::pair, std::string> StringToMaskedBytes(const char* szInput, bool bNullTerminator) + { + const char* pszStringStart = const_cast(szInput); + const char* pszStringEnd = pszStringStart + strlen(szInput); + std::vector vBytes; + std::string svMask; + + for (const char* pszCurrentByte = pszStringStart; pszCurrentByte < pszStringEnd; ++pszCurrentByte) + { + // Dereference character and push back the byte. + vBytes.push_back(*pszCurrentByte); + svMask += 'x'; + } + + if (bNullTerminator) + { + vBytes.push_back(0x0); + svMask += 'x'; + } + return make_pair(vBytes, svMask); + }; +} -- cgit v1.2.3