aboutsummaryrefslogtreecommitdiff
path: root/primedev/thirdparty/silver-bun/utils.cpp
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2024-03-04 00:01:32 +0000
committerGitHub <noreply@github.com>2024-03-04 01:01:32 +0100
commit4b0726d97788edff5d83476cb52057f409d623af (patch)
treedad38132c6353af708a71af8e795aa34a19b4b3a /primedev/thirdparty/silver-bun/utils.cpp
parente1eb2a6f4b858e903603226098861c3b62d5d1a4 (diff)
downloadNorthstarLauncher-4b0726d97788edff5d83476cb52057f409d623af.tar.gz
NorthstarLauncher-4b0726d97788edff5d83476cb52057f409d623af.zip
Update silver-bun to `72c74b4` (#664)
Bumps the vendored silver-bun library to the newest commit in upstream Co-authored-by: F1F7Y <filip.bartos07@proton.me> Co-authored-by: IcePixelx <41352111+IcePixelx@users.noreply.github.com>
Diffstat (limited to 'primedev/thirdparty/silver-bun/utils.cpp')
-rw-r--r--primedev/thirdparty/silver-bun/utils.cpp127
1 files changed, 127 insertions, 0 deletions
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<uint8_t> StringPatternToBytes(const char* szInput)
+ {
+ const char* pszPatternStart = const_cast<char*>(szInput);
+ const char* pszPatternEnd = pszPatternStart + strlen(szInput);
+ std::vector<uint8_t> vBytes;
+
+ for (const char* pszCurrentByte = pszPatternStart; pszCurrentByte < pszPatternEnd; ++pszCurrentByte)
+ {
+ vBytes.push_back(strtoul(pszCurrentByte, const_cast<char**>(&pszCurrentByte), 16));
+ }
+ return vBytes;
+ };
+
+ //----------------------------------------------------------------------------------------
+ // Purpose: For converting a string pattern with wildcards to an array of bytes.
+ //----------------------------------------------------------------------------------------
+ std::vector<int> PatternToBytes(const char* szInput)
+ {
+ const char* pszPatternStart = const_cast<char*>(szInput);
+ const char* pszPatternEnd = pszPatternStart + strlen(szInput);
+ std::vector<int> 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<char**>(&pszCurrentByte), 16));
+ }
+ }
+ return vBytes;
+ };
+
+ //----------------------------------------------------------------------------------------
+ // Purpose: For converting a string pattern with wildcards to an array of bytes and mask.
+ //----------------------------------------------------------------------------------------
+ std::pair<std::vector<uint8_t>, std::string> PatternToMaskedBytes(const char* szInput)
+ {
+ const char* pszPatternStart = const_cast<char*>(szInput);
+ const char* pszPatternEnd = pszPatternStart + strlen(szInput);
+
+ std::vector<uint8_t> 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<char**>(&pszCurrentByte), 16)));
+ svMask += 'x';
+ }
+ }
+ return make_pair(vBytes, svMask);
+ };
+
+ //----------------------------------------------------------------------------------------
+ // Purpose: For converting a string to an array of bytes.
+ //----------------------------------------------------------------------------------------
+ std::vector<int> StringToBytes(const char* szInput, bool bNullTerminator)
+ {
+ const char* pszStringStart = const_cast<char*>(szInput);
+ const char* pszStringEnd = pszStringStart + strlen(szInput);
+ std::vector<int> 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::vector<uint8_t>, std::string> StringToMaskedBytes(const char* szInput, bool bNullTerminator)
+ {
+ const char* pszStringStart = const_cast<char*>(szInput);
+ const char* pszStringEnd = pszStringStart + strlen(szInput);
+ std::vector<uint8_t> 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);
+ };
+}