library/src/utility/BP-StringUtilities.cc
// Reasonable, is a term I defined.  This means that the string contains only printable characters, and optionally, newlines.  I use this
// routine to do quick checks on user input strings, so that I can make determinations on whether or not the strings should be usable.  This
// relies on the buffer analysis capability of the library to work.  Again, this is a quick use routine that I personally use, and isn't
// something forced upon you.  You can use the buffer analysis capability directly if you prefer.
Reasonable, is a term I defined.  This means that the string contains only printable characters, and optionally, newlines.  I use this
routine to do quick checks on user input strings, so that I can make determinations on whether or not the strings should be usable.  This
relies on the buffer analysis capability of the library to work.  Again, this is a quick use routine that I personally use, and isn't
something forced upon you.  You can use the buffer analysis capability directly if you prefer.
Reasonable is a term I defined . This means that the string contains only printable characters and optionally newlines . I use this routine to do quick checks on user input strings so that I can make determinations on whether or not the strings should be usable . This relies on the buffer analysis capability of the library to work . Again this is a quick use routine that I personally use and isn ' t something forced upon you . You can use the buffer analysis capability directly if you prefer .
BP_BOOL BP_StringIsReasonablePrintableString
(
		char *  string_to_analyze,
		size_t  len,
		BP_BOOL allow_newlines,
		BP_BOOL allow_carriage_returns
)
{
	if(!string_to_analyze || !len)
		return BP_FALSE;
	if(!bpstrlen(string_to_analyze))
		return BP_FALSE;
	size_t char_iter = 0;
	for(; char_iter < len; char_iter++)
	{
		if(!string_to_analyze[char_iter])
		{
			return BP_FALSE;
		}
		if(isalnum(string_to_analyze[char_iter]))
			continue;
		switch(string_to_analyze[char_iter])
		{
			case ' ':
			case '\t':
			case '!':
			case '@':
			case '#':
			case '$':
			case '%':
			case '^':
			case '&':
			case '*':
			case '(':
			case ')':
			case '_':
			case '+':
			case '=':
			case '-':
			case '~':
			case '`':
			case '<':
			case '>':
			case ',':
			case '.':
			case '?':
			case '/':
			case '\\':
			case '"':
			case '\'':
			case ':':
			case ';':
			case '{':
			case '[':
			case ']':
			case '}':
			case '|':
				continue;
			case '\n':
				if(allow_newlines)
					continue;
				else
				{
					return BP_FALSE;
				}
			case '\r':
				if(allow_carriage_returns)
					continue;
				else
				{
					return BP_FALSE;
				}
				break;
			default:
				return BP_FALSE;
		}
	}
	return BP_TRUE;
}
BP_BOOL BP_StringIsReasonablePrintableString ( char * string_to_analyze , size_t len , BP_BOOL allow_newlines , BP_BOOL allow_carriage_returns ) { if ( ! string_to_analyze || ! len ) return BP_FALSE ; if ( ! bpstrlen ( string_to_analyze ) ) return BP_FALSE ; size_t char_iter = 0 ; for ( ; char_iter < len ; char_iter ++ ) { if ( ! string_to_analyze [ char_iter ] ) { return BP_FALSE ; } if ( isalnum ( string_to_analyze [ char_iter ] ) ) continue ; switch ( string_to_analyze [ char_iter ] ) { case ' ' : case ' \t ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' \\ ' : case ' ' : case ' \' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : continue ; case ' \n ' : if ( allow_newlines ) continue ; else { return BP_FALSE ; } case ' \r ' : if ( allow_carriage_returns ) continue ; else { return BP_FALSE ; } break ; default : return BP_FALSE ; } } return BP_TRUE ; }
Reasonable, is a term I defined.
Reasonable is a term I defined .
// ensure we have a string to analyze and a length // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% New Refactored Analyzer (no-heap usage/fast as possible) %%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // iterate through string // ensure position is not null // __asm("int3"); // printf("\n [+] The bad char is: at index %u --> %.02x", char_iter, string_to_analyze[char_iter]); // if it's not alphanumeric continue // !@#$%^&*()_+=-~`<>,.?/"':;{[]}\| // switch on allowed chars (long but fastest pathing) // process newlines // printf("\n [+] The bad char is: %.02x", string_to_analyze[char_iter]); // process carriage returns // printf("\n [+] The bad char is: %.02x", string_to_analyze[char_iter]); // return false if we don't have any matches //printf("\n [+] The bad char is: %.02x", string_to_analyze[char_iter]); // return indicating success