library/src/utility/BP-StringUtilities.cc
// encodes a buffer by using an imploding array of chr(dec)
encodes a buffer by using an imploding array of chr(dec)
encodes a buffer by using an imploding array of chr ( dec )
char * BP_GenPHPGadgetEncodeBufferAsImplodingArray(unsigned char * buff, size_t buff_size, P_BP_LINKL tq)
{
	if(!buff || !buff_size)
		return NULL;
	P_BP_LINKL tq_in = BP_CreateLinkL("intq", BP_FALSE);
	char *out_buff = NULL;
	tq_strdup(tq_in, "implode(array(", BPLN);
	size_t n = 0;
	for(; n < buff_size; n++)
	{
		BP_GenPHPGadgetEncodeUChar(buff[n], BP_PHP_GADGET_BUFFER_ENCODE_RANDOM_ASCII_CHR, tq_in);
		if((n+1) < buff_size)
			tq_strdup(tq_in, ",", BPLN);
	}
	tq_strdup(tq_in, "))", BPLN);
	BP_LinkLFlattenJoinStringElements(tq_in);
	if(tq)
		out_buff = tq_strdup(tq, (char *) tq_in->flat_buff, BPLN);
	else
		out_buff = bpstrdup((char *) tq_in->flat_buff);
	BP_DestroyLinkL(tq_in, BP_TRUE);
	return out_buff;
}
char * BP_GenPHPGadgetEncodeBufferAsImplodingArray ( unsigned char * buff , size_t buff_size , P_BP_LINKL tq ) { if ( ! buff || ! buff_size ) return NULL ; P_BP_LINKL tq_in = BP_CreateLinkL ( " " , BP_FALSE ) ; char * out_buff = NULL ; tq_strdup ( tq_in , " " , BPLN ) ; size_t n = 0 ; for ( ; n < buff_size ; n ++ ) { BP_GenPHPGadgetEncodeUChar ( buff [ n ] , BP_PHP_GADGET_BUFFER_ENCODE_RANDOM_ASCII_CHR , tq_in ) ; if ( ( n + 1 ) < buff_size ) tq_strdup ( tq_in , " " , BPLN ) ; } tq_strdup ( tq_in , " " , BPLN ) ; BP_LinkLFlattenJoinStringElements ( tq_in ) ; if ( tq ) out_buff = tq_strdup ( tq , ( char * ) tq_in -> flat_buff , BPLN ) ; else out_buff = bpstrdup ( ( char * ) tq_in -> flat_buff ) ; BP_DestroyLinkL ( tq_in , BP_TRUE ) ; return out_buff ; }
encodes a buffer by using an imploding array of chr(dec)
encodes a buffer by using an imploding array of chr ( dec )
// ensure we have a buffer and a buffer size // set tail queue allocator here // out buffer // add the front part of the string // encode the chars // add chunk as comma // add trailing parenthesis // flatten the tailqueue to create string // duplicate the generated flat buffer on the passed tq // and store it as the return buffer. // destroy the inner linkl // return the packed buffer