![]() |
Lucciefr
Lua code caving, injection and exploration framework
|
string utilities, low-level string operations More...
Macros | |
#define | DEFAULT_ASCII_MINLEN 2 |
default value for minimum string length that is_ascii() and is_utf16() will use if you pass a negative min_len | |
Functions | |
bool | strew (const char *str, const char *what) |
string ends with | |
bool | wstrew (const wchar_t *str, const wchar_t *what) |
wide string ends with | |
bool | strsw (const char *str, const char *what) |
string starts with | |
bool | wstrsw_ic (const wchar_t *str, const wchar_t *what) |
wide string starts with | |
bool | streq (const char *str, const char *what) |
string equals | |
bool | streq_ic (const char *str, const char *what) |
case-insensitive string equals | |
const char * | strstr_ic (const char *haystack, const char *needle) |
case-insensitive substring match | |
int | rtrim_len (const char *s, size_t *len) |
A helper function for "right trim" (removal of trailing whitepace). More... | |
int | ltrim_ofs (const char *s, size_t *len) |
A helper function for "left trim" (removal of leading whitepace). More... | |
int | strcmp_safe (const char *a, const char *b) |
"Lua-safe" string comparison (strcmp wrapper), protects against NULL pointers | |
int | strcasecmp_safe (const char *a, const char *b) |
"Lua-safe" string comparison, ignores case (strcasecmp wrapper) | |
char * | repeat_char (const char c, int n) |
construct a string that repeats a char n times. More... | |
char * | repeat_string (const char *str, int n) |
construct a string that repeats another string n times. More... | |
bool | is_ascii (unsigned char *data, int min_len) |
test for valid strings (consisting only of ASCII chars) with a given minimum length More... | |
bool | is_utf16 (wchar_t *data, int min_len) |
test for valid wide strings (consisting only of ASCII wide chars) More... | |
int | hextoi (const char *str) |
A primitive version of "hex to integer", similar to strtol(str, NULL, 16) . More... | |
int32_t | hash_str_djb (const char *key, size_t length, size_t step) |
DJB string hash function. More... | |
int32_t | hash_wstr_djb (const wchar_t *key, size_t length, size_t step) |
DJB hash function for wide strings. | |
int32_t | hash_str_sdbm (const char *key, size_t length, size_t step) |
sdbm string hash function. More... | |
int32_t | hash_wstr_sdbm (const wchar_t *key, size_t length, size_t step) |
sdbm hash function for wide strings | |
int32_t | hash_str_elf (const char *key, size_t length, size_t step) |
ELF hash. More... | |
int32_t | hash_wstr_elf (const wchar_t *key, size_t length, size_t step) |
ELF hash function for wide strings. More... | |
int32_t | hash_str_mulAdd (int32_t init, int32_t factor, const char *key, size_t length, size_t step) |
multiplicative string hash functions, using "add" operation | |
int32_t | hash_wstr_mulAdd (int32_t init, int32_t factor, const wchar_t *key, size_t length, size_t step) |
multiplicative wide string hash functions, using "add" operation | |
int32_t | hash_str_mulXor (int32_t init, int32_t factor, const char *key, size_t length, size_t step) |
multiplicative string hash functions, using "xor" operation | |
int32_t | hash_wstr_mulXor (int32_t init, int32_t factor, const wchar_t *key, size_t length, size_t step) |
multiplicative wide string hash functions, using "xor" operation | |
int32_t | hash_str_xorMul (int32_t init, int32_t factor, const char *key, size_t length, size_t step) |
string hash functions, using (FNV-1a style) "xor before mul" | |
int32_t | hash_wstr_xorMul (int32_t init, int32_t factor, const wchar_t *key, size_t length, size_t step) |
wide string hash functions, using (FNV-1a style) "xor before mul" | |
String formatting | |
General-purpose "print to string" routines. vformatmsg() and formatmsg() are "printf-style" functions that return a formatted message string.
Their low-level counterparts vformatmsg_len() and formatmsg_len() return the resulting string length (excluding the terminating NUL) instead, and therefore require an additional | |
#define | DEFAULT_FORMATMSG_SIZE 512 |
default allocation size for string formatting | |
int | vformatmsg_len (char **msg, const char *fmt, va_list ap) |
Function to create a string according to format string fmt while using arguments from vararg list ap . More... | |
char * | vformatmsg (const char *fmt, va_list ap) |
Return a string according to format string fmt , using arguments from vararg list ap . More... | |
int | formatmsg_len (char **msg, const char *fmt,...) |
Vararg wrapper for vformatmsg_len(). More... | |
char * | formatmsg (const char *fmt,...) |
Vararg wrapper for vformatmsg(). Returns formatted string. | |
string utilities, low-level string operations
*_ic
functions are case-insensitive ("ignore case") int formatmsg_len | ( | char ** | msg, |
const char * | fmt, | ||
... | |||
) |
Vararg wrapper for vformatmsg_len().
Assigns to *msg
, and returns resulting string length.
int32_t hash_str_djb | ( | const char * | key, |
size_t | length, | ||
size_t | step | ||
) |
DJB string hash function.
see e.g. http://stackoverflow.com/questions/1579721/why-are-5381-and-33-so-important-in-the-djb2-algorithm (and the links there)
int32_t hash_str_elf | ( | const char * | key, |
size_t | length, | ||
size_t | step | ||
) |
ELF hash.
The published hash algorithm used in the UNIX ELF format for object files.
It's basically a PJW hash variant (see e.g. [1], pp. 434-438)
int32_t hash_str_sdbm | ( | const char * | key, |
size_t | length, | ||
size_t | step | ||
) |
sdbm string hash function.
int32_t hash_wstr_elf | ( | const wchar_t * | key, |
size_t | length, | ||
size_t | step | ||
) |
ELF hash function for wide strings.
int hextoi | ( | const char * | str | ) |
A primitive version of "hex to integer", similar to strtol(str, NULL, 16)
.
(This function simply ignores any non-hexadecimal chars.)
bool is_ascii | ( | unsigned char * | data, |
int | min_len | ||
) |
test for valid strings (consisting only of ASCII chars) with a given minimum length
data | (string) data to test |
min_len | minimum length required. if you pass min_len < 0 , uses DEFAULT_ASCII_MINLEN instead |
false
if the string interpretation of data
contains invalid chars or has insufficient length, true
otherwise bool is_utf16 | ( | wchar_t * | data, |
int | min_len | ||
) |
test for valid wide strings (consisting only of ASCII wide chars)
int ltrim_ofs | ( | const char * | s, |
size_t * | len | ||
) |
A helper function for "left trim" (removal of leading whitepace).
The function returns an offset into the string that would skip the leading chars. len
is optional input specifying the string length - if NULL
, strlen(s)
is used.
char* repeat_char | ( | const char | c, |
int | n | ||
) |
construct a string that repeats a char n
times.
(The string gets calloc()
ed, you are responsible for calling free()
on the result later.)
char* repeat_string | ( | const char * | str, |
int | n | ||
) |
construct a string that repeats another string n
times.
(The string gets calloc()
ed, you are responsible for calling free()
on the result later.)
int rtrim_len | ( | const char * | s, |
size_t * | len | ||
) |
A helper function for "right trim" (removal of trailing whitepace).
The function returns the new length of the string without the trailing chars. len
is optional input specifying the string length - if NULL
, strlen(s)
is used.
char* vformatmsg | ( | const char * | fmt, |
va_list | ap | ||
) |
Return a string according to format string fmt
, using arguments from vararg list ap
.
int vformatmsg_len | ( | char ** | msg, |
const char * | fmt, | ||
va_list | ap | ||
) |
Function to create a string according to format string fmt
while using arguments from vararg list ap
.
Assigns to *msg
accordingly, and returns resulting string length.