library/src/buffer_analysis/ASCII/BP-BufferAnalysisASCII.cc
// Calculates ASCII strings which are found in the buffer, and stores them within the buffer analysis.  The
// extracted strings are stored within buff_analysis->ascii->strings structure stack, and the total number
// of strings is stored in analysis->ascii->strings_n.  You can navigate them by iterating through the stack
// indexes till you reatch strings_n-1 top.  This routine will automatically stack new results into the strings
// stack, so it can be called recursively for a variety of different line break sequences.  An example line break
// sequence could be like the following (null character break):
//
// unsigned char * line_break = "\x00";
// size_t          sequence_len = 1;
//
Calculates ASCII strings which are found in the buffer, and stores them within the buffer analysis.  The
extracted strings are stored within buff_analysis->ascii->strings structure stack, and the total number
of strings is stored in analysis->ascii->strings_n.  You can navigate them by iterating through the stack
indexes till you reatch strings_n-1 top.  This routine will automatically stack new results into the strings
stack, so it can be called recursively for a variety of different line break sequences.  An example line break
sequence could be like the following (null character break).

unsigned char * line_break = "\x00";
size_t          sequence_len = 1.
Calculates ASCII strings which are found in the buffer and stores them within the buffer analysis . The extracted strings are stored within buff_analysis - > ascii - > strings structure stack and the total number of strings is stored in analysis - > ascii - > strings_n . You can navigate them by iterating through the stack indexes till you reatch strings_n - 1 top . This routine will automatically stack new results into the strings stack so it can be called recursively for a variety of different line break sequences . An example line break sequence could be like the following ( null character break ) . unsigned char * line_break = " \ x00 " ; size_t sequence_len = 1 .
BP_ERROR_T BP_ExtractASCIIStringsFromAnalyzedBuffer
(
		P_BP_BUFFER_ANALYSIS                  buff_analysis,
		P_BP_ASCII_CHAR_FLAGS                 match_flags,
		BP_ASCII_CHARACTER_SEARCH_FLAG_VALUES match_flags_how,
		P_BP_ASCII_CHAR_FLAGS                 negative_match_flags,
		BP_ASCII_CHARACTER_SEARCH_FLAG_VALUES negative_match_flags_how,
		unsigned char *                       line_break_sequence,
		size_t                                line_break_sequence_n,
		unsigned char *                       restricted_chars,
		size_t                                restricted_chars_n,
		size_t                                minimum_string_length
)
{
	if(!buff_analysis)
		return ERR_FAILURE;
	if(!buff_analysis->ascii)
		return ERR_FAILURE;
	if(match_flags)
	if(!match_flags_how)
		return ERR_FAILURE;
	if(negative_match_flags)
	if(!negative_match_flags_how)
		return ERR_FAILURE;
	size_t n = 0;
	P_BP_ASCII_CHARACTER_MAP char_map = BP_CreateASCIICharacterMap();
	if(!char_map)
		return ERR_FAILURE;
	if(restricted_chars && restricted_chars_n)
	{
		for(n = 0; n < restricted_chars_n; n++)
		{
			char_map->ascii_chart[restricted_chars[n]].is_restricted = BP_TRUE;
		}
	}
	BP_FLAGS_T cmp_flags_pos = 0;
	BP_FLAGS_T cmp_flags_neg = 0;
	for(n = 0; n <= 0xff; n++)
	{
		cmp_flags_pos = BP_CompareASCIICharFlags(match_flags, &char_map->ascii_chart[n].flags);
		cmp_flags_neg = BP_CompareASCIICharFlags(negative_match_flags, &char_map->ascii_chart[n].flags);
		if(BP_FLAG_IS_SET(cmp_flags_pos, match_flags_how) && BP_FLAG_IS_SET(cmp_flags_neg, negative_match_flags_how))
		{
		}
		else
		{
			 if the flags aren't set ok, restrict this f-er
			char_map->ascii_chart[n].is_restricted = BP_TRUE;
			 printf("\n Marking: %s", char_map->ascii_chart[n].symbol_description);
		}
	}
	 %%% String Extraction Flags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	 these flags assist in the main extract loop by marking whether or
	 not certain conditions have been met.
	BP_BOOL line_break_hit      = BP_FALSE;
	BP_BOOL restricted_char_hit = BP_FALSE;
	BP_BOOL end_of_buffer_hit   = BP_FALSE;
	 %%% Now Walk Individual Characters and Match Appropriately %%%%
	 current character being analyzed
	unsigned char current_char = 0x00;
	 current start read position is the buffers first character
	unsigned char * current_read_start_position = buff_analysis->buffer;
	 this is the current read position
	size_t current_read_length = 0;
	 iterate through string
	for(n = 0; n < buff_analysis->buffer_n; n++)
	{
		 set current character from index
		current_char = buff_analysis->buffer[n];
		 check for bad read position first, always skip restricted characters
		 if the current read length is 0 bytes.
		if(!current_read_length)
		if(char_map->ascii_chart[current_char].is_restricted == BP_TRUE)
			continue;
		 The remainder of the buffer cannot be less than the length
		 of the user provided line break sequence.
		if(line_break_sequence && line_break_sequence_n)
		{
			 ensure that we have enough space left for a successful compare (prevents
			 out of bounds compares)
			if(( buff_analysis->buffer_n - n) < line_break_sequence_n)
				break;
			 compare the line break sequence
			if
			(
				memcmp(
						(void *)&buff_analysis->buffer[n],
						(void *) line_break_sequence,
						line_break_sequence_n
				) == 0
			)
			{
				line_break_hit = BP_TRUE;
			}
		}
		 if the character is restricted, mark it as such
		if(char_map->ascii_chart[current_char].is_restricted)
		{
				restricted_char_hit = BP_TRUE;
		}
		else
		{
				 increment the read length and continue the loop
				current_read_length++;
		}
		 store the string if the line break was hit
		if(line_break_hit == BP_TRUE || restricted_char_hit == BP_TRUE)
		{
			 if the string is of some particular defined length, add it to the buffer
			 analysis (works on reference, not duplication, to minimize space)
			if(current_read_length >= minimum_string_length)
			{
				 set the read start position
				current_read_start_position = &buff_analysis->buffer[n-current_read_length];
				 attempt to add string to analysis
				BP_AddASCIIStringToBufferAnalysis
				(
					buff_analysis,
					n-current_read_length,                        
					current_read_length,
					current_read_start_position,
					match_flags,
					match_flags_how,
					negative_match_flags,
					negative_match_flags_how
				);
				 now reset the current read length and continue the loop
				current_read_length = 0;
				line_break_hit      = BP_FALSE;
				restricted_char_hit = BP_FALSE;
				continue;
			}
			else
			{
				current_read_length = 0;
				current_read_start_position = &buff_analysis->buffer[n];
				line_break_hit      = BP_FALSE;
				restricted_char_hit = BP_FALSE;
				continue;
			}
		}
	}
	 destroy the character map before exit
	if(char_map)
		BP_DestroyASCIICharacterMap(char_map);
	 return indicating success
	return ERR_SUCCESS;
}
BP_ERROR_T BP_ExtractASCIIStringsFromAnalyzedBuffer ( P_BP_BUFFER_ANALYSIS buff_analysis , P_BP_ASCII_CHAR_FLAGS match_flags , BP_ASCII_CHARACTER_SEARCH_FLAG_VALUES match_flags_how , P_BP_ASCII_CHAR_FLAGS negative_match_flags , BP_ASCII_CHARACTER_SEARCH_FLAG_VALUES negative_match_flags_how , unsigned char * line_break_sequence , size_t line_break_sequence_n , unsigned char * restricted_chars , size_t restricted_chars_n , size_t minimum_string_length ) { if ( ! buff_analysis ) return ERR_FAILURE ; if ( ! buff_analysis -> ascii ) return ERR_FAILURE ; if ( match_flags ) if ( ! match_flags_how ) return ERR_FAILURE ; if ( negative_match_flags ) if ( ! negative_match_flags_how ) return ERR_FAILURE ; size_t n = 0 ; P_BP_ASCII_CHARACTER_MAP char_map = BP_CreateASCIICharacterMap ( ) ; if ( ! char_map ) return ERR_FAILURE ; if ( restricted_chars && restricted_chars_n ) { for ( n = 0 ; n < restricted_chars_n ; n ++ ) { char_map -> ascii_chart [ restricted_chars [ n ] ] . is_restricted = BP_TRUE ; } } BP_FLAGS_T cmp_flags_pos = 0 ; BP_FLAGS_T cmp_flags_neg = 0 ; for ( n = 0 ; n <= 0xff ; n ++ ) { cmp_flags_pos = BP_CompareASCIICharFlags ( match_flags , & char_map -> ascii_chart [ n ] . flags ) ; cmp_flags_neg = BP_CompareASCIICharFlags ( negative_match_flags , & char_map -> ascii_chart [ n ] . flags ) ; if ( BP_FLAG_IS_SET ( cmp_flags_pos , match_flags_how ) && BP_FLAG_IS_SET ( cmp_flags_neg , negative_match_flags_how ) ) { } else { char_map -> ascii_chart [ n ] . is_restricted = BP_TRUE ; } } BP_BOOL line_break_hit = BP_FALSE ; BP_BOOL restricted_char_hit = BP_FALSE ; BP_BOOL end_of_buffer_hit = BP_FALSE ; unsigned char current_char = 0x00 ; unsigned char * current_read_start_position = buff_analysis -> buffer ; size_t current_read_length = 0 ; for ( n = 0 ; n < buff_analysis -> buffer_n ; n ++ ) { current_char = buff_analysis -> buffer [ n ] ; if ( ! current_read_length ) if ( char_map -> ascii_chart [ current_char ] . is_restricted == BP_TRUE ) continue ; if ( line_break_sequence && line_break_sequence_n ) { if ( ( buff_analysis -> buffer_n - n ) < line_break_sequence_n ) break ; if ( memcmp ( ( void * ) & buff_analysis -> buffer [ n ] , ( void * ) line_break_sequence , line_break_sequence_n ) == 0 ) { line_break_hit = BP_TRUE ; } } if ( char_map -> ascii_chart [ current_char ] . is_restricted ) { restricted_char_hit = BP_TRUE ; } else { current_read_length ++ ; } if ( line_break_hit == BP_TRUE || restricted_char_hit == BP_TRUE ) { if ( current_read_length >= minimum_string_length ) { current_read_start_position = & buff_analysis -> buffer [ n - current_read_length ] ; BP_AddASCIIStringToBufferAnalysis ( buff_analysis , n - current_read_length , current_read_length , current_read_start_position , match_flags , match_flags_how , negative_match_flags , negative_match_flags_how ) ; current_read_length = 0 ; line_break_hit = BP_FALSE ; restricted_char_hit = BP_FALSE ; continue ; } else { current_read_length = 0 ; current_read_start_position = & buff_analysis -> buffer [ n ] ; line_break_hit = BP_FALSE ; restricted_char_hit = BP_FALSE ; continue ; } } } if ( char_map ) BP_DestroyASCIICharacterMap ( char_map ) ; return ERR_SUCCESS ; }
Calculates ASCII strings which are found in the buffer, and stores them within the buffer analysis.
Calculates ASCII strings which are found in the buffer and stores them within the buffer analysis .
// ensure we have a valid buffer analysis routine // if we have positive match flags ensure we have a setting as to // how to match them. // if we have negative match flags, ensure we have a setting // as to how to match them as well // create iterator for use as index in various loops below // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Mark Restricted Sets if Necessary %%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // the character map we'll be using must be created here (it is destroyed // before exit) // check to see if the user has indicated that they wish to check for // literal restricted characters.  This is done so that we don't have to // iterate through the string of restricted characters at each iteration, and // instead just lookup restricted characters within the array as additive // index operations (faster). // mark restricted characters // Compare flags (since the BP_CompareASCIICharFlags routine can set multiple // bits within flags_t, we have to ensure that thing are checked only for the // user provided bits. // how this works is that we walk each character in the ascii character // map/chart and mark flags that do not match those flags found within the // users provided match set. // reset compare flags // If flags are set ok, the character is unrestricted. // // if the flags aren't set ok, restrict this f-er // printf("\n Marking: %s", char_map->ascii_chart[n].symbol_description); // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% String Extraction Flags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // these flags assist in the main extract loop by marking whether or // not certain conditions have been met. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Now Walk Individual Characters and Match Appropriately %%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // current character being analyzed // current start read position is the buffers first character // this is the current read position // iterate through string // set current character from index // check for bad read position first, always skip restricted characters // if the current read length is 0 bytes. // The remainder of the buffer cannot be less than the length // of the user provided line break sequence. // ensure that we have enough space left for a successful compare (prevents // out of bounds compares) // compare the line break sequence // if the character is restricted, mark it as such // increment the read length and continue the loop // store the string if the line break was hit // if the string is of some particular defined length, add it to the buffer // analysis (works on reference, not duplication, to minimize space) // set the read start position // attempt to add string to analysis /* n is the current read position as iterated */ // now reset the current read length and continue the loop // destroy the character map before exit // return indicating success