mirror of
https://github.com/wavestone-cdt/EDRSandblast.git
synced 2026-06-08 16:37:12 +00:00
D3FC0N 30 release: Obj callbacks, firewalling, symbols w/ internet, and more
Co-authored-by: Maxime Meignan <maxime.meignan@wavestone.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
|
||||
--- Utility function to generate a random string.
|
||||
|
||||
*/
|
||||
|
||||
#include "StringUtils.h"
|
||||
|
||||
//BOOL isFullPath(IN TCHAR* filename) {
|
||||
// char c;
|
||||
//
|
||||
// if (filename[0] == filename[1] && filename[1] == TEXT('\\')) {
|
||||
// return TRUE;
|
||||
// }
|
||||
//
|
||||
// c = filename[0] | 0x20;
|
||||
// if (c < 97 || c > 122) {
|
||||
// return FALSE;
|
||||
// }
|
||||
//
|
||||
// c = filename[1];
|
||||
// if (c != ':') {
|
||||
// return FALSE;
|
||||
// }
|
||||
//
|
||||
// c = filename[2];
|
||||
// if (c != '\\') {
|
||||
// return FALSE;
|
||||
// }
|
||||
//
|
||||
// return TRUE;
|
||||
//}
|
||||
|
||||
VOID getUnicodeStringFromTCHAR(OUT PUNICODE_STRING unicodeString, IN WCHAR* wcharString) {
|
||||
unicodeString->Buffer = wcharString;
|
||||
unicodeString->Length = (WORD)_tcslen(unicodeString->Buffer) * sizeof(WCHAR);
|
||||
unicodeString->MaximumLength = unicodeString->Length + sizeof(WCHAR);
|
||||
}
|
||||
|
||||
BOOL srandDone = FALSE;
|
||||
|
||||
/*
|
||||
* Generates a "length"-long random alphanumeric string
|
||||
* Assumes the allocation is big enough to receive "length" chararcters (so is at least "length + 1" long)
|
||||
*/
|
||||
TCHAR* generateRandomString(TCHAR* str, size_t length) {
|
||||
if (!srandDone) {
|
||||
srand((unsigned int)time(0));
|
||||
srandDone = TRUE;
|
||||
}
|
||||
|
||||
const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
|
||||
if (length) {
|
||||
for (size_t n = 0; n < length; n++) {
|
||||
int key = rand() % (int)(sizeof charset - 1);
|
||||
str[n] = charset[key];
|
||||
}
|
||||
str[length] = '\0';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
TCHAR* allocAndGenerateRandomString(size_t length) {
|
||||
LPTSTR str = calloc(length + 1, sizeof(TCHAR));
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
generateRandomString(str, length);
|
||||
return str;
|
||||
}
|
||||
Reference in New Issue
Block a user