mirror of
https://github.com/vanhauser-thc/thc-hydra.git
synced 2025-08-14 10:37:27 -07:00
Added function to trim strings.
This commit is contained in:
parent
c466657496
commit
8ebbde3223
2 changed files with 24 additions and 0 deletions
23
hydra-mod.c
23
hydra-mod.c
|
@ -1285,3 +1285,26 @@ int hydra_memsearch(char *haystack, int hlen, char *needle, int nlen) {
|
|||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char * hydra_trim(char * str) {
|
||||
size_t len = strlen(str);
|
||||
char * str_ptr[] = {str, NULL};
|
||||
|
||||
// Truncate leading spaces
|
||||
for(; *str_ptr[0] == ' ' && len > 0; str_ptr[0]++)
|
||||
len--;
|
||||
|
||||
if(len == 0)
|
||||
return NULL;
|
||||
|
||||
// Truncate trailing spaces
|
||||
str_ptr[1] = str + len;
|
||||
for(; *str_ptr[1] == ' '; str_ptr[1]--)
|
||||
len--;
|
||||
*(str_ptr[1] + 1) = 0;
|
||||
|
||||
char * trimmed_str = strndup(str_ptr[0], len);
|
||||
free(str);
|
||||
|
||||
return trimmed_str;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ extern char *hydra_strcasestr(const char *haystack, const char *needle);
|
|||
extern void hydra_dump_data(unsigned char *buf, int len, char *text);
|
||||
extern int hydra_memsearch(char *haystack, int hlen, char *needle, int nlen);
|
||||
extern char *hydra_strrep(char *string, char *oldpiece, char *newpiece);
|
||||
extern char * hydra_trim(char * str);
|
||||
|
||||
#ifdef HAVE_PCRE
|
||||
int hydra_string_match(char *str, const char *regex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue