library/src/datastructures/BP-BufferUtilities.cc
// retrieves shellcode styled hexidecimal, (Style should be C
retrieves shellcode styled hexidecimal, (Style should be C
retrieves shellcode styled hexidecimal ( Style should be C
char * GetBufferToStyle(char *buff, char *buffName, int len, int style)
{
	int i = 0;
	char *retBuff = (char *) bpmalloc(len+10000);
	memset(retBuff, 0x00, len+10000);
	if(len <= 0)
		return NULL;
	switch(style)
	{
		case SC_C_STYLE:
			sprintf(&retBuff[strlen(retBuff)], "char %s[] = \"", buffName);
			break;			
		case SC_C_STYLE_UNSIGNED:
			sprintf(&retBuff[strlen(retBuff)], "unsigned char %s[] = \"", buffName);
			break;			
		case SC_PERL_ARGV:			
			sprintf(&retBuff[strlen(retBuff)], "`perl -e 'print(\"");
			break;
		case SC_PERL_SCALAR:			
			sprintf(&retBuff[strlen(retBuff)],"$%s = \"", buffName);
			break;
		default:
			return NULL;
	}
     for(i = 0; i <=len; i++)
     {
            sprintf(&retBuff[strlen(retBuff)], "\\x%.2x", (unsigned char) buff[i]);
     }
	 switch(style)
	 {
		case SC_C_STYLE:
			sprintf(&retBuff[strlen(retBuff)], "\";");
			break;			
		case SC_C_STYLE_UNSIGNED:
			sprintf(&retBuff[strlen(retBuff)], "\";");
			break;			
		case SC_PERL_ARGV:			
			sprintf(&retBuff[strlen(retBuff)], "\");'`");
			break;
		case SC_PERL_SCALAR:			
			sprintf(&retBuff[strlen(retBuff)], "\";");
			break;
		default:
			return NULL;
	}
   	sprintf(&retBuff[strlen(retBuff)], "\n");
	return retBuff;
}
char * GetBufferToStyle ( char * buff , char * buffName , int len , int style ) { int i = 0 ; char * retBuff = ( char * ) bpmalloc ( len + 10000 ) ; memset ( retBuff , 0x00 , len + 10000 ) ; if ( len <= 0 ) return NULL ; switch ( style ) { case SC_C_STYLE : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " , buffName ) ; break ; case SC_C_STYLE_UNSIGNED : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " , buffName ) ; break ; case SC_PERL_ARGV : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " ) ; break ; case SC_PERL_SCALAR : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " , buffName ) ; break ; default : return NULL ; } for ( i = 0 ; i <= len ; i ++ ) { sprintf ( & retBuff [ strlen ( retBuff ) ] , " \\ " , ( unsigned char ) buff [ i ] ) ; } switch ( style ) { case SC_C_STYLE : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " ) ; break ; case SC_C_STYLE_UNSIGNED : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " ) ; break ; case SC_PERL_ARGV : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " ) ; break ; case SC_PERL_SCALAR : sprintf ( & retBuff [ strlen ( retBuff ) ] , " \" " ) ; break ; default : return NULL ; } sprintf ( & retBuff [ strlen ( retBuff ) ] , " \n " ) ; return retBuff ; }
retrieves shellcode styled hexidecimal, (Style should be C
retrieves shellcode styled hexidecimal ( Style should be C
// signed char buffer  style // unsigned char buffer style // `perl -e 'print("");'` style // perl $var = "" style // signed char buffer  style // unsigned char buffer style // `perl -e 'print("");'` style // perl $var = "" style // add trailing newline // return the ret buffer