Esempio n. 1
0
void hexdump(unsigned char* buffer, unsigned int length) {
     int b=0, c=0;
     int s, rem;

     // b is a counter for the number of bytes (half the number of hex digits)

     printf("\n     PAYLOAD HEXDUMP:\n");
     while (b < length) {
	  printf("\n     %07x:", b);
	  for (; (b%16<15) && (b<length); b++) {
	       if (0 == b % 2)
		    printf(" ");
	       printf("%02hhx", buffer[b]);
	  }

	  if (b < length)
	       printf("%02hhx   ",  buffer[b++]);
	  else { // print a number of spaces to align the remaining text
	       rem = b % 16;
	       for (s=0; s < 44 - ((rem*2) + (rem/2) + 1); s++)
		    printf(" ");
	  }

	  for (;(c%16<15) && (c<length); c++) {
	       printf("%c", is_printable(buffer[c]));
	  }
	  if (c<length)
	       printf("%c", is_printable(buffer[c++]));
     }
}
Esempio n. 2
0
int put_string_in_buffer (text_message *buf, const Uint8 *str, int pos)
{
    int nr_free, nr_paste, ib, jb, nb;
    Uint8 ch;

    if (pos < 0 || pos > buf->len) return 0;
    if (str == NULL) return 0;

    // find out how many characters to paste
    nr_free = buf->size - pos - 1;
    nr_paste = 0;
    for (ib = 0; str[ib] && nr_paste < nr_free; ib++)
    {
        ch = str[ib];
        if (is_printable (ch) || ch == '\n')
            nr_paste++;
    }

    if (nr_paste == 0) {
        return 0;
    }

    // now move the characters right of the cursor (if any)
    nb = buf->len - pos;
    if (nb > nr_free - nr_paste)
        nb = nr_free - nr_paste;
    if (nb > 0)
    {
        for (ib = nb-1; ib >= 0; ib--)
            buf->data[pos+ib+nr_paste] = buf->data[pos+ib];
    }
    buf->data[pos+nb+nr_paste] = '\0';
    buf->len = pos+nb+nr_paste;

    // insert the pasted text
    jb = 0;
    for (ib = 0; str[ib]; ib++)
    {
        ch = str[ib];
        if (ch == '\n')
            ch = ' ';
        if (is_printable (ch))
        {
            buf->data[pos+jb] = ch;
            if (++jb >= nr_paste) break;
        }
    }

    return nr_paste;
}
Esempio n. 3
0
/**
 * Validate `len' bytes starting from `buf' as a proper base32 encoding
 * of a SHA1 hash, and write decoded value in `sha1'.
 * Also make sure that the SHA1 is not an improbable value.
 *
 * `n' is the node receiving the packet where we found the SHA1, so that we
 * may trace errors if needed.
 *
 * When `check_old' is true, check the encoding against an earlier version
 * of the base32 alphabet.
 *
 * @return TRUE if the SHA1 was valid and properly decoded, FALSE on error.
 */
bool
huge_sha1_extract32(const char *buf, size_t len, struct sha1 *sha1,
	const gnutella_node_t *n)
{
	if (len != SHA1_BASE32_SIZE || huge_improbable_sha1(buf, len))
		goto bad;

	if (SHA1_RAW_SIZE != base32_decode(sha1->data, sizeof sha1->data, buf, len))
		goto bad;

	/*
	 * Make sure the decoded value in `sha1' is "valid".
	 */

	if (huge_improbable_sha1(sha1->data, sizeof sha1->data)) {
		if (GNET_PROPERTY(share_debug)) {
			if (is_printable(buf, len)) {
				g_warning("%s has improbable SHA1 (len=%lu): %.*s, hex: %s",
					gmsg_node_infostr(n),
					(unsigned long) len,
					(int) MIN(len, (size_t) INT_MAX),
					buf, data_hex_str(sha1->data, sizeof sha1->data));
			} else
				goto bad;		/* SHA1 should be printable originally */
		}
		return FALSE;
	}

	return TRUE;

bad:
	if (GNET_PROPERTY(share_debug)) {
		if (is_printable(buf, len)) {
			g_warning("%s has bad SHA1 (len=%u): %.*s",
				gmsg_node_infostr(n),
				(unsigned) len,
				(int) MIN(len, (size_t) INT_MAX),
				buf);
		} else {
			g_warning("%s has bad SHA1 (len=%u)",
				gmsg_node_infostr(n), (unsigned) len);
			if (len)
				dump_hex(stderr, "Base32 SHA1", buf, len);
		}
	}

	return FALSE;
}
Esempio n. 4
0
static int xlog_3_helper(struct sip_msg* msg, char* fac, char* lev, char* frm, int mode)
{
	long level;
	int facility;
	xl_level_p xlp;
	pv_value_t value;

	xlp = (xl_level_p)lev;
	if(xlp->type==1)
	{
		if(pv_get_spec_value(msg, &xlp->v.sp, &value)!=0 
			|| value.flags&PV_VAL_NULL || !(value.flags&PV_VAL_INT))
		{
			LM_ERR("invalid log level value [%d]\n", value.flags);
			return -1;
		}
		level = (long)value.ri;
	} else {
		level = xlp->v.level;
	}
	facility = *(int*)fac;

	if(!is_printable((int)level))
		return 1;

	return xlog_helper(msg, (xl_msg_t*)frm, (int)level, mode, facility);
}
Esempio n. 5
0
/**
 * print log message to L_ERR level
 */
static int xlog_1_helper(struct sip_msg* msg, char* frm, char* str2, int mode, int facility)
{
	if(!is_printable(L_ERR))
		return 1;

	return xlog_helper(msg, (xl_msg_t*)frm, L_ERR, mode, facility);
}
Esempio n. 6
0
char *strip_ctrl_codes (char *s)
{
    char *w; /* Current position where the stripped data is written */
    char *r; /* Current position where the original data is read */

    if (!s)
	return 0;

    for (w = s, r = s; *r; ) {
	if (*r == ESC_CHAR) {
	    /* Skip the control sequence's arguments */ ;
	    if (*(++r) == '[') {
		/* strchr() matches trailing binary 0 */
		while (*(++r) && strchr ("0123456789;?", *r));
	    }

	    /*
	     * Now we are at the last character of the sequence.
	     * Skip it unless it's binary 0.
	     */
	    if (*r)
		r++;
	    continue;
	}

	if (is_printable(*r))
	    *w++ = *r;
	++r;
    }
    *w = 0;
    return s;
}
Esempio n. 7
0
static int _process_chunk(QSP_ARG_DECL  Image_File *ifp, Wav_Chunk_Hdr *wch_p)
{
	// See what kind of chunk it is...
	if( !strncmp(wch_p->wch_label,"fmt ",4) ){
fprintf(stderr,"format chunk seen!\n");
		return read_format_chunk(ifp,wch_p);
	} else if( !strncmp(wch_p->wch_label,"data",4) ){
fprintf(stderr,"data chunk seen!\n");
		if( read_data_chunk(ifp,wch_p) != 0 )
			return -1;
		return 1;	// special return val for data chunk
	} else if( !strncmp(wch_p->wch_label,"LIST",4) ){
fprintf(stderr,"list chunk seen!\n");
		return ignore_chunk(ifp,wch_p);
	} else {
		char s[5];
		strncpy(s,wch_p->wch_label,4);
		s[4]=0;

		if( is_printable(s) ){
			sprintf(ERROR_STRING,
	"read_next_chunk_header (%s):  unrecognized chunk label \"%s\"!?\n",
				ifp->if_name,s);
			warn(ERROR_STRING);
		} else {
			wav_error("unprintable chunk label",ifp);
		}
		// should read the chunk data!?
		return 0;
	}
}
Esempio n. 8
0
File: rasc.c Progetto: 111X/radare
int hexpair2bin(const char *arg) // (0A) => 10 || -1 (on error)
{
	unsigned char *ptr;
	unsigned char c = '\0';
	unsigned char d = '\0';
	unsigned int  j = 0;

	for (ptr = (unsigned char *)arg; ;ptr = ptr + 1) {
		if (ptr[0]==' '||ptr[0]=='\t'||ptr[0]=='\n'||ptr[0]=='\r')
			continue;
		if (!is_printable(ptr[0]))
			continue;
		if (ptr[0]=='\0'||ptr[0]==' ' || j==2)
			break;
		d = c;
		if (hex2int(&c, ptr[0]) == 0) {
			fprintf(stderr, "Invalid hexa string at char '%c'.\n", ptr[0]);
			return -1;
		}
		c |= d;
		if (j++ == 0) c <<= 4;
	}

	return (int)c;
}
Esempio n. 9
0
/*
 * Remove the middle part of the string to fit given length.
 * Use "~" to show where the string was truncated.
 * Return static buffer, no need to free() it.
 */
const char *
name_trunc (const char *txt, int trunc_len)
{
    static char x[MC_MAXPATHLEN + MC_MAXPATHLEN];
    int txt_len;
    char *p;

    if ((size_t) trunc_len > sizeof (x) - 1) {
	trunc_len = sizeof (x) - 1;
    }
    txt_len = strlen (txt);
    if (txt_len <= trunc_len) {
	strcpy (x, txt);
    } else {
	int y = (trunc_len / 2) + (trunc_len % 2);
	strncpy (x, txt, y);
	strncpy (x + y, txt + txt_len - (trunc_len / 2), trunc_len / 2);
	x[y] = '~';
    }
    x[trunc_len] = 0;
    for (p = x; *p; p++)
	if (!is_printable (*p))
	    *p = '?';
    return x;
}
void print_subs(int log_level)
{
	r_subscription *s;
	int i;
#ifdef SER_MOD_INTERFACE
	if (!is_printable(log_level))
#else		
	if (debug<log_level)
#endif	
		return; /* to avoid useless calls when nothing will be printed */

	LOG(log_level,ANSI_GREEN"INF:"M_NAME":----------  Subscription list begin ---------\n");
	for(i=0;i<subscriptions_hash_size;i++){
		subs_lock(i);
		s = subscriptions[i].head;
		r_act_time();
		while(s){
			LOG(log_level,ANSI_GREEN"INF:"M_NAME":[%4u]\tP: <"ANSI_BLUE"%.*s"ANSI_GREEN"> D:["ANSI_CYAN"%5d"ANSI_GREEN"] E:["ANSI_MAGENTA"%5d"ANSI_GREEN"] Att:[%2d]\n",
				s->hash,s->req_uri.len,s->req_uri.s,s->duration,(int)(s->expires-time_now),s->attempts_left);
			s = s->next;			
		}
		subs_unlock(i);
	}
	LOG(log_level,ANSI_GREEN"INF:"M_NAME":----------  Subscription list end -----------\n");	
}
Esempio n. 11
0
bool
huge_tth_extract32(const char *buf, size_t len, struct tth *tth,
	const gnutella_node_t *n)
{
	if (len != TTH_BASE32_SIZE)
		goto bad;

	if (TTH_RAW_SIZE != base32_decode(tth->data, sizeof tth->data, buf, len))
		goto bad;

	return TRUE;

bad:
	if (GNET_PROPERTY(share_debug)) {
		if (is_printable(buf, len)) {
			g_warning("%s has bad TTH (len=%u): %.*s",
				gmsg_node_infostr(n),
				(unsigned) len,
				(int) MIN(len, (size_t) INT_MAX),
				buf);
		} else {
			g_warning("%s has bad TTH (len=%u",
				gmsg_node_infostr(n), (unsigned) len);
			if (len)
				dump_hex(stderr, "Base32 TTH", buf, len);
		}
	}
	return FALSE;
}
Esempio n. 12
0
int xlog_2(struct sip_msg* msg, char* lev, char* frm)
{
	int log_len;
	long level;
	xl_level_p xlp;
	pv_value_t value;

	xlp = (xl_level_p)lev;
	if(xlp->type==1)
	{
		if(pv_get_spec_value(msg, &xlp->v.sp, &value)!=0
			|| value.flags&PV_VAL_NULL || !(value.flags&PV_VAL_INT))
		{
			LM_ERR("invalid log level value [%d]\n", value.flags);
			return -1;
		}
		level = (long)value.ri;
	} else {
		level = xlp->v.level;
	}

	if(!is_printable((int)level))
		return 1;

	log_len = xlog_buf_size;

	if(xl_print_log(msg, (pv_elem_t*)frm, &log_len)<0)
		return -1;

	/* log_buf[log_len] = '\0'; */
	LM_GEN1((int)level, "%.*s", log_len, log_buf);

	return 1;
}
Esempio n. 13
0
void
tty_print_anychar (int c)
{
    char str[6 + 1];

    if (c > 255)
    {
        int res = g_unichar_to_utf8 (c, str);
        if (res == 0)
        {
            str[0] = '.';
            str[1] = '\0';
        }
        else
        {
            str[res] = '\0';
        }
        SLsmg_write_string ((char *) str_term_form (str));
    }
    else
    {
        if (!is_printable (c))
            c = '.';
        SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
    }
}
Esempio n. 14
0
void siplua_log(int lev, const char *format, ...)
{
  va_list ap;
  char *ret;
  int priority;

  if (!format)
    return;
  if (!(is_printable(lev) | lua_user_debug))
    return;
  va_start(ap, format);
  vasprintf(&ret, format, ap);
  va_end(ap);
  LM_GEN1(lev, "siplua: %s", ret);
  if (lua_user_debug)
    {
      switch (lev)
	{
	case L_ALERT: priority = LOG_ALERT; break;
	case L_CRIT: priority = LOG_CRIT; break;
	case L_ERR: priority = LOG_ERR; break;
	case L_WARN: priority = LOG_WARNING; break;
	case L_NOTICE: priority = LOG_NOTICE; break;
	case L_INFO: priority = LOG_INFO; break;
	case L_DBG: priority = LOG_DEBUG; break;
	default: /* should not happen, no execution path permits it */
	  priority = LOG_ERR;
	}
      syslog(LOG_USER | priority, "siplua: %s", ret);
    }
  free(ret);
}
Esempio n. 15
0
static int
is_last(Consptr cons)
{
     while (cons = CDR(cons)) 
	  if (is_printable(cons))
	       return 0;
     return 1;
}
Esempio n. 16
0
int my_str_isprintable(char *str)
{
	while(*str && is_printable(*str))
	{
		str = str + 1;
	}
	return (*str == '\0');
}
Esempio n. 17
0
void key_press(int key) {
  if (is_modifier(key))
    report_modifier_add(key);
  else if (is_printable(key))
    report_key_add(asciimap[key]);
  else
    report_key_add(key);
}
Esempio n. 18
0
static int
is_last(struct linked_list_entry *p)
{
     while ((p = p->next))
	  if (is_printable(p))
	       return 0;
     return 1;
}
Esempio n. 19
0
char* get_constant_name(classfile* cf, int index){
    assert(index - 1< cf->constant_pool_count);
    char* to_return = (char*) cf->constant_pool[index - 1]->info;
    if(is_printable(to_return, cf->constant_pool[index - 1]->cp_length))
	return to_return;
    else
	return UNPRINTABLE;
}
Esempio n. 20
0
void key_release(int key) {
  if (is_modifier(key))
    report_modifier_remove(key);
  else if (is_printable(key))
    report_key_remove(asciimap[key]);
  else
    report_key_remove(key);
}
Esempio n. 21
0
char read_try_get_char( void) {
    char c;

    /* If buffer is empty. */
    if(READ_TRY_GET_CHAR(&c) != EC_SUCCESS) return '\0';

    /* If not printable. */
    if( is_printable(c) != EC_TRUE ) return '\0';

    return c;
}
Esempio n. 22
0
void print_constant(cp_info* cp, FILE* out){
    if(is_printable((char*) cp->info, cp->cp_length)){
    	for(int i = 0; i < cp->cp_length; i++){
    	    fputc(cp->info[i], out);
    	}
    } else {
	fprintf(out, "(%d) ", cp->cp_length);
	for(int i = 0; i < cp->cp_length; i++){
	    fprintf(out, "%02x ", cp->info[i]);
	}
    }
}
Esempio n. 23
0
static gboolean
mcview_isprint (const WView * view, int c)
{
#ifdef HAVE_CHARSET
    if (!view->utf8)
        c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
    return g_unichar_isprint (c);
#else
    (void) view;
    /* TODO this is very-very buggy by design: ticket 3257 comments 0-1 */
    return is_printable (c);
#endif /* HAVE_CHARSET */
}
Esempio n. 24
0
File: ord.c Progetto: Sun42/exam
int	count_word(char *str)
{
  int	cpt;
  int	i;
  int	flag;

  
  flag = i = cpt = 0;
  while (*str)		
    {
      if (is_printable())
      str++;
    }
  return (cpt);
}
Esempio n. 25
0
static int type_str(unsigned long value, void *arg)
{
	unsigned long types;
	types = *((unsigned long *)arg);
	if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
					types &= ~B_ASN1_PRINTABLESTRING;
	if((types & B_ASN1_IA5STRING) && (value > 127))
					types &= ~B_ASN1_IA5STRING;
	if((types & B_ASN1_T61STRING) && (value > 0xff))
					types &= ~B_ASN1_T61STRING;
	if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
					types &= ~B_ASN1_BMPSTRING;
	if(!types) return -1;
	*((unsigned long *)arg) = types;
	return 1;
}
Esempio n. 26
0
int xdbg(struct sip_msg* msg, char* frm, char* str2)
{
	int log_len;

	if(!is_printable(L_DBG))
		return 1;

	log_len = xlog_buf_size;

	if(xl_print_log(msg, (pv_elem_t*)frm, &log_len)<0)
		return -1;

	/* log_buf[log_len] = '\0'; */
	LM_GEN1(L_DBG, "%.*s", log_len, log_buf);

	return 1;
}
Esempio n. 27
0
File: search.c Progetto: 111X/radare
static int radare_tsearch_callback(struct _tokenizer *t, int i, ut64 where)
{
	char flag_name[128];
	ut64 off = config.seek;

	if (align != 0 && where%align != 0)
		return 1;

	if (search_count && nhit >= search_count)
		return 1;

	nhit++;
	radare_flag_name (flag_name, i, nhit);

	radare_seek(where, SEEK_SET);
	radare_read(0);
	if (search_flag)
		flag_set(flag_name, where, 0);

	if (search_cmdhit && search_cmdhit[0]!='\0') {
		char *cmdhit = strdup(search_cmdhit);
		radare_seek(where, SEEK_SET);
		setenv("KEYWORD", search_last_keyword, 1); // XXX this is not last-keyword!! must array this!
		radare_cmd(cmdhit, 0);
		free(cmdhit);
		radare_controlc();
	}

	if (search_verbose) {
		u8 *ptr = config.block; //+(where-config.seek)-3;
		cons_printf("%03d  0x%08llx  %s ", nhit, where, flag_name);
		for(i=0;i<20;i++) {
			if (is_printable(ptr[i]))
				cons_printf("%c", ptr[i]);
		}
		cons_printf("\n");
	} 
	//D { fprintf(stderr, "\r%d\n", nhit); fflush(stderr); }

	fflush(stdout);
	config.seek = off;

	return 0;
}
Esempio n. 28
0
void dump_data_section(void) {
    ui32 col = 0;
    unsigned char *tmp = &memspace[DATA_SECTION_START];
    unsigned char *end = &memspace[DATA_SECTION_START + DATA_SECTION_SIZE];
    unsigned char data, *start = tmp;
    for (; start != end; ++start, ++col) {
        data = *start;
        if (col == 19) {
            printf("\n");
            col = 0;
        }
        if (is_printable(data)) {
            printf("%2c ", data);
        }
        else {
            printf("%02x ", data);
        }
    }
    printf("\n");
}
/**
 * Logs the list of peers
 * @param level - log level to print to
 */
void log_peer_list(int level)
{
	/* must have lock on peer_list_lock when calling this!!! */
	peer *p;
	int i;
#ifdef SER_MOD_INTERFACE
	if (!is_printable(level))
#else		
	if (debug<level)
#endif
		return;
	
	LOG(level,"--- Peer List: ---\n");
	for(p = peer_list->head;p;p = p->next){
		LOG(level,ANSI_GREEN" S["ANSI_YELLOW"%s"ANSI_GREEN"] "ANSI_BLUE"%.*s:%d"ANSI_GREEN" D["ANSI_RED"%c"ANSI_GREEN"]\n",dp_states[p->state],p->fqdn.len,p->fqdn.s,p->port,p->is_dynamic?'X':' ');
		for(i=0;i<p->applications_cnt;i++)
			LOG(level,ANSI_YELLOW"\t [%d,%d]"ANSI_GREEN"\n",p->applications[i].id,p->applications[i].vendor);
	}
	LOG(level,"------------------\n");		 
}
Esempio n. 30
0
std::string find_key(const std::string &cipher)
{
	for (char a = 'a'; a <= 'z'; a++) {
		for (char b = 'a'; b <= 'z'; b++) {
			for (char c = 'a'; c <= 'z'; c++) {
				std::string s(1, a); s += b; s += c;
				std::string xord = xor_str(cipher, s);
				if (!is_printable(xord)) continue;
				// Some common words
				if (xord.find("the") != std::string::npos &&
						xord.find("in") != std::string::npos &&
						xord.find("of") != std::string::npos &&
						xord.find("and") != std::string::npos) {
					return xord;
				}
			}
		}
	}
	return "";
}