2021-12-25 22:36:38 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Internals
|
2022-01-04 11:53:54 +01:00
|
|
|
BOOL IsBadReadPtrV2(void* ptr);
|
2022-06-12 12:40:26 +02:00
|
|
|
BOOL FileExists(const fs::path& svFilePath);
|
2022-09-10 00:06:26 +02:00
|
|
|
BOOL FileEmpty(ifstream& pFile);
|
2021-12-25 22:36:38 +01:00
|
|
|
MODULEINFO GetModuleInfo(const char* szModule);
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2022-06-07 13:44:31 +02:00
|
|
|
// Debug
|
2021-12-25 22:36:38 +01:00
|
|
|
void DbgPrint(LPCSTR sFormat, ...);
|
2022-01-19 23:14:50 +01:00
|
|
|
void PrintLastError(void);
|
2023-04-02 21:51:15 +02:00
|
|
|
void HexDump(const char* szHeader, const char* szLogger, const void* pData, size_t nSize);
|
2022-04-10 19:59:34 +02:00
|
|
|
|
2022-08-13 12:39:57 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Char
|
|
|
|
char* StripTabsAndReturns(const char* pInBuffer, char* pOutBuffer, int nOutBufferSize);
|
|
|
|
char* StripQuotes(const char* pInBuffer, char* pOutBuffer, int nOutBufferSize);
|
|
|
|
|
2022-06-07 13:44:31 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// String
|
2022-11-13 23:44:30 +01:00
|
|
|
bool HasPartial(const string& svInput, const string& svPartial);
|
2022-06-07 13:44:31 +02:00
|
|
|
bool HasExtension(const string& svInput, const string& svExtension);
|
|
|
|
string GetExtension(const string& svInput, bool bReturnOriginal = false, bool bKeepDelimiter = false);
|
2022-05-30 01:50:21 +02:00
|
|
|
string RemoveExtension(const string& svInput);
|
|
|
|
|
2022-06-07 13:44:31 +02:00
|
|
|
bool HasFileName(const string& svInput, const string& svFileName);
|
2022-11-23 16:54:10 +01:00
|
|
|
string GetFileName(const string& svInput, bool bRemoveExtension = false, bool bWindows = false);
|
2022-06-02 01:55:41 +02:00
|
|
|
string RemoveFileName(const string& svInput, bool bWindows = false);
|
2022-05-30 01:50:21 +02:00
|
|
|
|
2022-12-27 02:28:43 +01:00
|
|
|
string CreateTimedFileName();
|
2023-05-10 00:05:38 +02:00
|
|
|
string CreateUUID();
|
2023-02-04 15:59:45 +01:00
|
|
|
void CreateDirectories(string svInput, string* pszOutput = nullptr, bool bWindows = false);
|
2022-12-27 02:28:43 +01:00
|
|
|
|
2022-04-10 19:59:34 +02:00
|
|
|
string ConvertToWinPath(const string& svInput);
|
2022-04-29 05:30:06 +02:00
|
|
|
string ConvertToUnixPath(const string& svInput);
|
2022-04-10 19:59:34 +02:00
|
|
|
|
2023-04-02 15:16:32 +02:00
|
|
|
bool IsEqualNoCase(const string& svInput, const string& svSecond);
|
2023-02-04 15:59:45 +01:00
|
|
|
bool IsValidBase64(const string& svInput, string* psvOutput = nullptr);
|
2023-04-02 15:16:32 +02:00
|
|
|
|
2022-04-10 19:59:34 +02:00
|
|
|
string Base64Encode(const string& svInput);
|
|
|
|
string Base64Decode(const string& svInput);
|
|
|
|
|
2022-05-30 01:50:21 +02:00
|
|
|
string UTF8Encode(const wstring& wsvInput);
|
2023-04-02 14:52:12 +02:00
|
|
|
//string UTF8Decode(const string& svInput);
|
2022-06-24 12:12:30 +02:00
|
|
|
size_t UTF8CharLength(const uint8_t cInput);
|
2023-04-09 23:34:06 +02:00
|
|
|
bool IsValidUTF8(const char* pszString);
|
2022-05-30 01:50:21 +02:00
|
|
|
|
2022-05-24 02:23:37 +02:00
|
|
|
bool StringIsDigit(const string& svInput);
|
2022-04-18 16:45:26 +02:00
|
|
|
bool CompareStringAlphabetically(const string& svA, const string& svB);
|
|
|
|
bool CompareStringLexicographically(const string& svA, const string& svB);
|
|
|
|
|
2022-04-10 19:59:34 +02:00
|
|
|
bool StringReplace(string& svInput, const string& svFrom, const string& svTo);
|
2022-06-02 01:55:41 +02:00
|
|
|
string StringReplaceC(const string& svInput, const string& svFrom, const string& svTo);
|
2022-04-10 19:59:34 +02:00
|
|
|
string StringEscape(const string& svInput);
|
|
|
|
string StringUnescape(const string& svInput);
|
2022-09-22 17:08:20 +02:00
|
|
|
size_t StringCount(const string& svInput, char cDelim);
|
2022-07-31 17:07:35 +02:00
|
|
|
vector<string> StringSplit(string svInput, char cDelim, size_t nMax = SIZE_MAX);
|
2022-05-10 23:32:44 +02:00
|
|
|
|
2022-11-11 01:17:11 +01:00
|
|
|
string& StringLTrim(string& svInput, const char* pszToTrim, bool bTrimBefore = false);
|
|
|
|
string& StringRTrim(string& svInput, const char* pszToTrim, bool bTrimAfter = false);
|
|
|
|
string& StringTrim(string& svInput, const char* pszToTrim, bool bTrimAll = false);
|
2022-10-20 12:29:21 +02:00
|
|
|
|
2022-12-22 21:44:38 +00:00
|
|
|
string FourCCToString(int n);
|
|
|
|
|
2022-06-27 14:48:03 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Bytes
|
2022-04-10 19:59:34 +02:00
|
|
|
vector<int> StringToBytes(const string& svInput, bool bNullTerminator);
|
2022-07-20 18:03:35 +02:00
|
|
|
pair<vector<uint8_t>, string> StringToMaskedBytes(const string& svInput, bool bNullTerminator);
|
2022-04-10 19:59:34 +02:00
|
|
|
vector<int> PatternToBytes(const string& svInput);
|
2022-06-26 17:45:54 +02:00
|
|
|
pair<vector<uint8_t>, string> PatternToMaskedBytes(const string& svInput);
|
2022-05-30 01:50:21 +02:00
|
|
|
vector<int> IntToDigits(int iValue);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-06-07 13:44:31 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Print
|
2022-05-10 23:36:01 +02:00
|
|
|
void PrintM128i8(__m128i in);
|
|
|
|
void PrintM128i16(__m128i in);
|
|
|
|
void PrintM128i32(__m128i in);
|
|
|
|
void PrintM128i64(__m128i in);
|
|
|
|
|
2022-08-13 12:39:57 +02:00
|
|
|
void AppendPrintf(char* pBuffer, size_t nBufSize, char const* pFormat, ...);
|
2022-05-10 23:32:44 +02:00
|
|
|
string PrintPercentageEscape(const string& svInput);
|
|
|
|
|
2023-03-13 21:34:09 +01:00
|
|
|
string FormatV(const char* szFormat, va_list args);
|
|
|
|
string Format(const char* szFormat, ...);
|
|
|
|
|
2023-04-08 13:32:34 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Array
|
|
|
|
template <typename Iter, typename Compare>
|
|
|
|
Iter ExtremeElementABS(Iter first, Iter last, Compare compare)
|
|
|
|
{
|
|
|
|
auto abs_compare = [compare](LONG a, LONG b)
|
|
|
|
{
|
|
|
|
return compare(abs(a), abs(b));
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::min_element(first, last, abs_compare);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Iter> // Return lowest element in array.
|
|
|
|
Iter MinElementABS(Iter first, Iter last)
|
|
|
|
{
|
|
|
|
return ExtremeElementABS(first, last, std::less<>());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Iter> // Return highest element in array.
|
|
|
|
Iter MaxElementABS(Iter first, Iter last)
|
|
|
|
{
|
|
|
|
return ExtremeElementABS(first, last, std::greater<>());
|
|
|
|
}
|
|
|
|
|
2023-04-16 11:55:57 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Net
|
|
|
|
int CompareIPv6(const IN6_ADDR& ipA, const IN6_ADDR& ipB);
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2022-08-31 02:15:54 +02:00
|
|
|
// Time
|
|
|
|
std::chrono::nanoseconds IntervalToDuration(const float flInterval);
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|