Ejemplo n.º 1
0
str
new_str(const char* fmt, va_list args)
{
	char* c;
	str s;
	reg x, xl, sl;
	reg i, ls = 0, la = 0;
	for (i = 0; fmt[i]; ++i) la += (fmt[i] == '%' ? 1 : 0);
	str retval = blank(0);
	ls = 0;
	for (i = 0; fmt[i]; ++i) {
		if (fmt[i] == '%')
			switch (fmt[++i]) {
			case 'c':
				c = va_arg(args,char*);
				sl = strlen(c);
				memcpy(&retval->data[ls],c,sl);
				ls += sl;
				break;
			case 's':
				s = va_arg(args,str);
				memcpy(&retval->data[ls],s->data,s->length);
				ls += s->length;
				break;
			case 'd':
			case 'i':
				x = va_arg(args,reg);
				xl = int_len(x);
				int_print(&retval->data[ls],x,xl);
				ls += xl;
				break;
			case 'p':
			case 'x':
				c = va_arg(args,char*);
				xl = hex_len((reg)c);
				hex_print(&retval->data[ls],(reg)c,xl);
				ls += xl;
				break;
			case 'h':
				x  = va_arg(args,reg);
				xl = hex_len(x);
				hex_print(&retval->data[ls],x,xl);
				ls += xl;
				break;
			default:
				++ls;
			}
		else retval->data[ls++] = fmt[i];
	}
Ejemplo n.º 2
0
static void join_print_po(struct packet_object *po)
{
   int ret;
   
   /* check if the object exists */
   if (wdg_conndata == NULL || wdg_join == NULL)
      return;

   /* if not focused don't refresh it */
   if (!(wdg_conndata->flags & WDG_OBJ_FOCUSED))
      return;
   
   /* check the regex filter */
   if (GBL_OPTIONS->regex && 
       regexec(GBL_OPTIONS->regex, (const char*)po->DATA.disp_data, 0, NULL, 0) != 0) {
      return;
   }
   
   /* use the global to reuse the same memory region */
   SAFE_REALLOC(dispbuf, hex_len(po->DATA.disp_len) * sizeof(u_char) + 1);
      
   /* format the data */
   ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf);
   dispbuf[ret] = 0;
        
   if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1))
      wdg_scroll_print(wdg_join, EC_COLOR_JOIN1, "%s", dispbuf);
   else
      wdg_scroll_print(wdg_join, EC_COLOR_JOIN2, "%s", dispbuf);
}
Ejemplo n.º 3
0
static void split_print_po(struct packet_object *po)
{
   int ret;
   
   /* if not open don't refresh it */
   if (!data_window)
      return;
   
   /* check the regex filter */
   if (GBL_OPTIONS->regex && 
       regexec(GBL_OPTIONS->regex, po->DATA.disp_data, 0, NULL, 0) != 0) {
      return;
   }
   
   /* use the global to reuse the same memory region */
   SAFE_REALLOC(dispbuf, hex_len(po->DATA.disp_len) * sizeof(u_char) + 1);
      
   /* format the data */
   ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf);
   dispbuf[ret] = 0;
        
   if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1))
      gtkui_data_print(1, dispbuf, 0);
   else
      gtkui_data_print(2, dispbuf, 0);
}
Ejemplo n.º 4
0
/* 
 * convert a buffer to a hex notation
 *
 * the string  "HTTP/1.1 304 Not Modified" becomes:
 * 
 * 0000: 4854 5450 2f31 2e31 2033 3034 204e 6f74  HTTP/1.1 304 Not
 * 0010: 204d 6f64 6966 6965 64                    Modified
 */
int hex_format(const u_char *buf, size_t len, u_char *dst)
{
   u_int i, j, jm, c;
   int dim = 0;
   char tmp[10];



   /* some sanity checks */
   if (len == 0 || buf == NULL) {
      strncpy((char*)dst, "", 1);
      return 0;
   }

   /* empty the string */
   memset(dst, 0, hex_len(len));

   for (i = 0; i < len; i += HEX_CHAR_PER_LINE) {
           dim += snprintf(tmp, 7, "%04x: ", i);
           strncat(dst, tmp, 7);

           jm = len - i;
           jm = jm > HEX_CHAR_PER_LINE ? HEX_CHAR_PER_LINE : jm;

           for (j = 0; j < jm; j++) {
                   if ((j % 2) == 1) {
                     dim += snprintf(tmp, 4, "%02x ", buf[i+j]);
                     strncat(dst, tmp, 4);
                   } else {
                        dim += snprintf(tmp, 3, "%02x", buf[i+j]);
                        strncat(dst, tmp, 3);

                   }
           }
           for (; j < HEX_CHAR_PER_LINE; j++) {
                   if ((j % 2) == 1) {
                      strcat((char*)dst, "   ");
		      dim += 3;
                   } else {
                      strcat((char*)dst, "  ");
		      dim += 2;
                   }
           }
           strcat((char*)dst, " ");
           dim++;

           for (j = 0; j < jm; j++) {
                  c = buf[i+j];
                   c = isprint(c) ? c : '.';
                   dim += snprintf(tmp, 2, "%c" , c);
                   strncat(dst, tmp, 2);
           }

           strcat((char*)dst, "\n");
 	   dim++;
   }

   return dim + 1;
}
Ejemplo n.º 5
0
str
hex_str(reg i)
{
	reg l = hex_len(i);
	str retval = blank(l);
	hex_print(retval->data,i,l);
	return retval;
}
Ejemplo n.º 6
0
void text_print_packet(struct packet_object *po)
{
   /* 
    * keep it static so it is always the same
    * memory region used for this operation
    */
   static u_char *tmp = NULL;
   int ret;

   /* don't display the packet */
   if (GBL_OPTIONS->quiet)
      return;
   
   /* 
    * if the regex does not match, the packet is not interesting 
    *
    * should we put this after the format function ?
    * in this way we can match e.t.t.e.r.c.a.p in TEXT mode with
    * the "ettercap" regex
    */
   if (GBL_OPTIONS->regex && 
       regexec(GBL_OPTIONS->regex, po->DATA.disp_data, 0, NULL, 0) != 0) {
      return;
   }
               
   /* 
    * prepare the buffer,
    * the max length is hex_fomat
    * so use its length for the buffer
    */
   SAFE_REALLOC(tmp, hex_len(po->DATA.disp_len) * sizeof(u_char));

   /* 
    * format the packet with the function set by the user
    */
   ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, tmp);

   /* print the headers */
   display_headers(po);
   
   /* print it */
   write(fileno(stdout), tmp, ret);

   printf("\n");
}     
Ejemplo n.º 7
0
int hex_format(const u_char *buf, size_t len, u_char *dst)
{
   u_int i, j, jm, c;
   int dim = 0;
  
   /* some sanity checks */
   if (len == 0 || buf == NULL) {
      strncpy(dst, "", 1);
      return 0;
   }
  
   /* empty the string */
   memset(dst, 0, hex_len(len));
   
   for (i = 0; i < len; i += HEX_CHAR_PER_LINE) {
           snprintf(dst, strlen(dst)+5, "%s %04x: ", dst, i );
           jm = len - i;
           jm = jm > HEX_CHAR_PER_LINE ? HEX_CHAR_PER_LINE : jm;

           for (j = 0; j < jm; j++) {
                   if ((j % 2) == 1) {
                      snprintf(dst, strlen(dst) + 3, "%s%02x ", dst, (u_char) buf[i+j]);
                   } else {
                      snprintf(dst, strlen(dst)+3, "%s%02x", dst, (u_char) buf[i+j]);
                   }
           }
           for (; j < HEX_CHAR_PER_LINE; j++) {
                   if ((j % 2) == 1) {
                      strcat(dst, "   ");
                   } else {
                      strcat(dst, "  ");
                   }
           } 
           strcat(dst, " ");

           for (j = 0; j < jm; j++) {
                   c = (u_char) buf[i+j];
                   c = isprint(c) ? c : '.';
                   dim = snprintf(dst, strlen(dst)+1, "%s%c", dst, c);
           }
           strcat(dst, "\n");
   }

   return dim + 1;
}
Ejemplo n.º 8
0
static void join_print(u_char *text, size_t len, struct ip_addr *L3_src)
{
   int ret;
   
   /* check the regex filter */
   if (GBL_OPTIONS->regex && 
       regexec(GBL_OPTIONS->regex, (const char*)text, 0, NULL, 0) != 0) {
      return;
   }
   
   /* use the global to reuse the same memory region */
   SAFE_REALLOC(dispbuf, hex_len(len) * sizeof(u_char) + 1);
   
   /* format the data */
   ret = GBL_FORMAT(text, len, dispbuf);
   dispbuf[ret] = 0;
   
   if (!ip_addr_cmp(L3_src, &curr_conn->L3_addr1))
      wdg_scroll_print(wdg_join, EC_COLOR_JOIN1, "%s", dispbuf);
   else
      wdg_scroll_print(wdg_join, EC_COLOR_JOIN2, "%s", dispbuf);
}
Ejemplo n.º 9
0
static void split_print(u_char *text, size_t len, struct ip_addr *L3_src)
{
   int ret;
   
   /* check the regex filter */
   if (GBL_OPTIONS->regex && 
       regexec(GBL_OPTIONS->regex, text, 0, NULL, 0) != 0) {
      return;
   }

   /* use the global to reuse the same memory region */
   SAFE_REALLOC(dispbuf, hex_len(len) * sizeof(u_char) + 1);
   
   /* format the data */
   ret = GBL_FORMAT(text, len, dispbuf);
   dispbuf[ret] = 0;

   if (!ip_addr_cmp(L3_src, &curr_conn->L3_addr1))
      gtkui_data_print(1, dispbuf, 0);
   else
      gtkui_data_print(2, dispbuf, 0);
}