Example #1
0
static const char *
str_ascii_term_trim (const char *text, int width)
{
    static char result[BUF_MEDIUM];
    size_t remain;
    char *actual;
    size_t pos = 0;
    size_t length;

    length = strlen (text);
    actual = result;
    remain = sizeof (result);

    if (width < (int)length)
    {
	if (width <= 3)
	{
	    memset (actual, '.', width);
	    actual += width;
	    remain -= width;
	}
	else
	{
	    memset (actual, '.', 3);
	    actual += 3;
	    remain -= 3;

	    pos += length - width + 3;

	    /* copy suffix of text */
	    for (; pos < length && remain > 1; pos++, actual++, remain--)
	    {
		actual[0] = isascii ((unsigned char) text[pos])
		    ? text[pos] : '?';
		actual[0] = g_ascii_isprint ((gchar) actual[0])
		    ? actual[0] : '.';
	    }
	}
    }
    else
    {
	/* copy all characters */
	for (; pos < length && remain > 1; pos++, actual++, remain--)
	{
	    actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
	    actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
	}
    }

    actual[0] = '\0';
    return result;
}
Example #2
0
static const char *
str_ascii_trunc (const char *text, int width)
{
    static char result[MC_MAXPATHLEN];
    int remain;
    char *actual;
    size_t pos = 0;
    size_t length;

    actual = result;
    remain = sizeof (result);
    length = strlen (text);

    if ((int) length > width)
    {
        /* copy prefix of text */
        for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
        {
            actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
            actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
        }

        if (remain <= 1)
            goto finally;
        actual[0] = '~';
        actual++;
        remain--;

        pos += length - width + 1;

        /* copy suffix of text */
        for (; pos < length && remain > 1; pos++, actual++, remain--)
        {
            actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
            actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
        }
    }
    else
    {
        /* copy all characters */
        for (; pos < length && remain > 1; pos++, actual++, remain--)
        {
            actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
            actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
        }
    }

finally:
    actual[0] = '\0';
    return result;
}
Example #3
0
static void
dissect_ftpdata(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
    proto_item *ti;
    int         data_length;
    gboolean    is_text = TRUE;
    gint        check_chars, i;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "FTP-DATA");

    col_add_fstr(pinfo->cinfo, COL_INFO, "FTP Data: %u bytes",
        tvb_reported_length(tvb));

    data_length = tvb_captured_length(tvb);

    ti = proto_tree_add_item(tree, proto_ftp_data, tvb, 0, -1, ENC_NA);

    /* Check the first few chars to see whether it looks like a text file or not */
    check_chars = MIN(10, data_length);
    for (i=0; i < check_chars; i++) {
        if (!g_ascii_isprint(tvb_get_guint8(tvb, i))) {
            is_text = FALSE;
            break;
        }
    }

    if (is_text) {
        /* Show as string, but don't format more text than will be displayed */
        proto_item_append_text(ti, " (%s)", tvb_format_text(tvb, 0, MIN(data_length, ITEM_LABEL_LENGTH)));
    }
    else {
        /* Assume binary, just show the number of bytes */
        proto_item_append_text(ti, " (%u bytes data)", data_length);
    }
}
Example #4
0
static void
gst_info_dump_mem_line (gchar * linebuf, gsize linebuf_size,
    const guint8 * mem, gsize mem_offset, gsize mem_size)
{
  gchar hexstr[50], ascstr[18], digitstr[4];

  if (mem_size > 16)
    mem_size = 16;

  hexstr[0] = '\0';
  ascstr[0] = '\0';

  if (mem != NULL) {
    guint i = 0;

    mem += mem_offset;
    while (i < mem_size) {
      ascstr[i] = (g_ascii_isprint (mem[i])) ? mem[i] : '.';
      g_snprintf (digitstr, sizeof (digitstr), "%02x ", mem[i]);
      g_strlcat (hexstr, digitstr, sizeof (hexstr));
      ++i;
    }
    ascstr[i] = '\0';
  }

  g_snprintf (linebuf, linebuf_size, "%08x: %-48.48s %-16.16s",
      (guint) mem_offset, hexstr, ascstr);
}
Example #5
0
/**
 * Creates the text lookup table.
 *
 * This should only need to be called once. The results could be made static to
 * eliminate the need to have lightmagic re-create this static table every time
 * the program runs, but the overhead is pretty minimal it's probably not worth it.
 *
 * Only ASCII is supported - there is no intention to support EBCDIC.
 */
static void make_text_lookup_table(void)
{
  memset(text_lookup_table, 0, sizeof(text_lookup_table));

  int i;

  for (i = 0; i < LUT_SIZE; i++)
  {
    // Formatting characters
    if ((i == ' ') || (i == '\r') || (i == '\n'))
    {
      text_lookup_table[i] |= LUT_TEXT_TEXT | LUT_TEXT_BASE64 | LUT_TEXT_BASE85 | LUT_TEXT_HEX;
    }
    // General text
    if ((g_ascii_isprint(i) || g_ascii_ispunct(i) || g_ascii_isspace(i)) != 0)
    {
      text_lookup_table[i] |= LUT_TEXT_TEXT;
    }
    // Base64
    if (isbase64(i) != 0)
    {
      text_lookup_table[i] |= LUT_TEXT_BASE64;
    }
    // Base85
    if (isbase85(i) != 0)
    {
      text_lookup_table[i] |= LUT_TEXT_BASE85;
    }
    // Hex digits
    if (isxdigit(i) != 0)
    {
      text_lookup_table[i] |= LUT_TEXT_HEX;
    }
  }
}
Example #6
0
static void
debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len)
{
    static GString *debug = NULL;
    const char *s;

    if (!debug)
        debug = g_string_sized_new (256);

    g_string_append (debug, prefix);
    g_string_append (debug, " '");

    s = buf;
    while (len--) {
        if (g_ascii_isprint (*s))
            g_string_append_c (debug, *s);
        else if (*s == '\r')
            g_string_append (debug, "<CR>");
        else if (*s == '\n')
            g_string_append (debug, "<LF>");
        else
            g_string_append_printf (debug, "\\%u", (guint8) (*s & 0xFF));

        s++;
    }

    g_string_append_c (debug, '\'');
    mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str);
    g_string_truncate (debug, 0);
}
Example #7
0
/**
 * udisks_daemon_util_hexdump:
 * @data: Pointer to data.
 * @len: Length of data.
 *
 * Utility function to generate a hexadecimal representation of @len
 * bytes of @data.
 *
 * Returns: A multi-line string. Free with g_free() when done using it.
 */
gchar *
udisks_daemon_util_hexdump (gconstpointer data, gsize len)
{
  const guchar *bdata = data;
  guint n, m;
  GString *ret;

  ret = g_string_new (NULL);
  for (n = 0; n < len; n += 16)
    {
      g_string_append_printf (ret, "%04x: ", n);

      for (m = n; m < n + 16; m++)
        {
          if (m > n && (m%4) == 0)
            g_string_append_c (ret, ' ');
          if (m < len)
            g_string_append_printf (ret, "%02x ", (guint) bdata[m]);
          else
            g_string_append (ret, "   ");
        }

      g_string_append (ret, "   ");

      for (m = n; m < len && m < n + 16; m++)
        g_string_append_c (ret, g_ascii_isprint (bdata[m]) ? bdata[m] : '.');

      g_string_append_c (ret, '\n');
    }

  return g_string_free (ret, FALSE);
}
Example #8
0
gchar *
utf8_escape_string(const gchar *str, gssize len)
{
  int i;
  gchar *res, *res_pos;

  /* Check if string is a valid UTF-8 string */
  if (g_utf8_validate(str, -1, NULL))
      return g_strndup(str, len);

  /* It contains invalid UTF-8 sequences --> treat input as a
   * string containing binary data; escape those chars that have
   * no ASCII representation */
  res = g_new(gchar, 4 * len + 1);
  res_pos = res;

  for (i = 0; (i < len) && str[i]; i++)
    {
      if (g_ascii_isprint(str[i]))
        *(res_pos++) = str[i];
      else
        res_pos += sprintf(res_pos, "\\x%02x", ((guint8)str[i]));
    }

  *(res_pos++) = '\0';

  return res;
}
Example #9
0
static void
dump_mem (guint8 * mem, guint size)
{
  guint i, j;
  GString *string = g_string_sized_new (50);
  GString *chars = g_string_sized_new (18);

  i = j = 0;
  while (i < size) {
    if (g_ascii_isprint (mem[i]))
      g_string_append_printf (chars, "%c", mem[i]);
    else
      g_string_append_printf (chars, ".");

    g_string_append_printf (string, "%02x ", mem[i]);

    j++;
    i++;

    if (j == 16 || i == size) {
      g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
          string->str, chars->str);
      g_string_set_size (string, 0);
      g_string_set_size (chars, 0);
      j = 0;
    }
  }
  g_string_free (string, TRUE);
  g_string_free (chars, TRUE);
}
Example #10
0
static gchar *
test_escape_data (const guchar *data,
                  gssize n_data)
{
  static const char HEXC[] = "0123456789ABCDEF";
  GString *result;
  gchar c;
  gsize i;
  guchar j;

  if (!data)
    return g_strdup ("NULL");

  result = g_string_sized_new (n_data * 2 + 1);
  for (i = 0; i < n_data; ++i)
    {
      c = data[i];
      if (g_ascii_isprint (c) && !strchr ("\n\r\v", c))
        {
          g_string_append_c (result, c);
        }
      else
        {
          g_string_append (result, "\\x");
          j = c >> 4 & 0xf;
          g_string_append_c (result, HEXC[j]);
          j = c & 0xf;
          g_string_append_c (result, HEXC[j]);
        }
    }

  return g_string_free (result, FALSE);
}
Example #11
0
static const char *
str_ascii_term_substring (const char *text, int start, int width)
{
    static char result[BUF_MEDIUM];
    size_t remain;
    char *actual;
    size_t length;

    actual = result;
    remain = sizeof (result);
    length = strlen (text);

    if (start < (int) length)
    {
        size_t pos;

        /* copy at most width characters from text from start */
        for (pos = start; pos < length && width > 0 && remain > 1;
                pos++, width--, actual++, remain--)
        {
            actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
            actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
        }
    }

    /* if text is shorter then width, add space to the end */
    for (; width > 0 && remain > 1; actual++, remain--, width--)
        actual[0] = ' ';

    actual[0] = '\0';
    return result;
}
Example #12
0
/*
 * XXX - for text printing, we probably want to wrap lines at 80 characters;
 * (PostScript printing is doing this already), and perhaps put some kind of
 * dingbat (to use the technical term) to indicate a wrapped line, along the
 * lines of what's done when displaying this in a window, as per Warren Young's
 * suggestion.
 */
static gboolean
follow_print_text(char *buffer, size_t nchars, gboolean is_from_server _U_,
          void *arg)
{
    print_stream_t *stream = (print_stream_t *)arg;
    size_t i;
    char *str;

    /* convert non printable characters */
    for (i = 0; i < nchars; i++) {
        if (buffer[i] == '\n' || buffer[i] == '\r')
            continue;
        if (! g_ascii_isprint(buffer[i])) {
            buffer[i] = '.';
        }
    }

    /* convert unterminated char array to a zero terminated string */
    str = (char *)g_malloc(nchars + 1);
    memcpy(str, buffer, nchars);
    str[nchars] = 0;
    print_line(stream, /*indent*/ 0, str);
    g_free(str);

    return TRUE;
}
Example #13
0
File: nroff.c Project: idispatch/mc
static gboolean
mcview_nroff_get_char (mcview_nroff_t * nroff, int *ret_val, off_t nroff_index)
{
    int c = 0;

#ifdef HAVE_CHARSET
    if (nroff->view->utf8)
    {
        if (!mcview_get_utf (nroff->view, nroff_index, &c, &nroff->char_length))
        {
            /* we need got symbol in any case */
            nroff->char_length = 1;
            if (!mcview_get_byte (nroff->view, nroff_index, &c) || !g_ascii_isprint (c))
                return FALSE;
        }
    }
    else
#endif
    {
        nroff->char_length = 1;
        if (!mcview_get_byte (nroff->view, nroff_index, &c))
            return FALSE;
    }

    *ret_val = c;

    return g_unichar_isprint (c);
}
Example #14
0
static const gchar *
gs_plugin_steam_token_kind_to_str (guint8 data)
{
	static gchar tmp[2] = { 0x00, 0x00 };

	if (data == GS_PLUGIN_STEAM_TOKEN_START)
		return "[SRT]";
	if (data == GS_PLUGIN_STEAM_TOKEN_STRING)
		return "[STR]";
	if (data == GS_PLUGIN_STEAM_TOKEN_INTEGER)
		return "[INT]";
	if (data == GS_PLUGIN_STEAM_TOKEN_END)
		return "[END]";

	/* guess */
	if (data == 0x03)
		return "[ETX]";
	if (data == 0x04)
		return "[EOT]";
	if (data == 0x05)
		return "[ENQ]";
	if (data == 0x06)
		return "[ACK]";
	if (data == 0x07)
		return "[BEL]";
	if (data == 0x09)
		return "[SMI]";

	/* printable */
	if (g_ascii_isprint (data)) {
		tmp[0] = (gchar) data;
		return tmp;
	}
	return "[?]";
}
Example #15
0
gboolean
follow_add_to_gtk_text(char *buffer, size_t nchars, gboolean is_from_server,
               void *arg)
{
    GtkWidget *text = (GtkWidget *)arg;
    GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
    GtkTextIter    iter;

    /*
     * have to convert non printable ASCII chars to '.' in order
     * to be able to see the data we *should* see
     * in the GtkText widget.
     */
    size_t i;

    for (i = 0; i < nchars; i++) {
        if (buffer[i] == '\n' || buffer[i] == '\r')
            continue;
        if (! g_ascii_isprint(buffer[i])) {
            buffer[i] = '.';
        }
    }

    gtk_text_buffer_get_end_iter(buf, &iter);
    if (is_from_server) {
        gtk_text_buffer_insert_with_tags(buf, &iter, buffer, (gint) nchars,
                         server_tag, NULL);
    } else {
        gtk_text_buffer_insert_with_tags(buf, &iter, buffer, (gint) nchars,
                         client_tag, NULL);
    }
    return TRUE;
}
static gchar*
path_get_from_event_aggrname(gridcluster_event_t *decoded_event, const gchar *basedir)
{
	gchar c, *s, aggr_name[1024];
	GByteArray *gba;

	bzero(aggr_name, sizeof(aggr_name));

	/* Decode and check there is an UEID in the event */
	if (!(gba = g_hash_table_lookup(decoded_event, GRIDCLUSTER_EVTFIELD_AGGRNAME))) {
		gchar *ueid = ueid_get_from_event(decoded_event);
		g_strlcpy(aggr_name, ueid, sizeof(aggr_name)-1);
		g_free(ueid);
	}
	else 
		g_memmove(aggr_name, gba->data, MIN(gba->len, sizeof(aggr_name)-1));

	/* Cannonify the aggr_name*/
	for (s=aggr_name; '\0'!=(c=*s) ;s++) {
		if (!g_ascii_isprint(c) || g_ascii_isspace(c) || c==G_DIR_SEPARATOR || c=='.')
			*s = '_';
	}

	/* Replace the aggregation name with its canonized form */
	gridcluster_event_add_string(decoded_event, GRIDCLUSTER_EVTFIELD_AGGRNAME, aggr_name);
	return g_strdup_printf("%s%c%s", basedir, G_DIR_SEPARATOR, aggr_name);
}
Example #17
0
static void extract_ssid(DBusMessageIter *value,
					struct supplicant_result *result)
{
	DBusMessageIter array;
	unsigned char *ssid;
	int ssid_len, i;

	dbus_message_iter_recurse(value, &array);
	dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);

	if (ssid_len < 1)
		return;

	if (ssid[0] == '\0')
		return;

	result->ssid = g_try_malloc(ssid_len);
	if (result->ssid == NULL)
		return;

	memcpy(result->ssid, ssid, ssid_len);
	result->ssid_len = ssid_len;

	result->name = g_try_malloc0(ssid_len + 1);
	if (result->name == NULL)
		return;

	for (i = 0; i < ssid_len; i++) {
		if (g_ascii_isprint(ssid[i]))
			result->name[i] = ssid[i];
		else
			result->name[i] = ' ';
	}
}
void
fb_util_debug_hexdump(FbDebugLevel level, const GByteArray *bytes,
                      const gchar *format, ...)
{
    gchar c;
    guint i;
    guint j;
    GString *gstr;
    va_list ap;

    static const gchar *indent = "  ";

    g_return_if_fail(bytes != NULL);

    if (format != NULL) {
        va_start(ap, format);
        fb_util_vdebug(level, format, ap);
        va_end(ap);
    }

    gstr = g_string_sized_new(80);

    for (i = 0; i < bytes->len; i += 16) {
        g_string_append_printf(gstr, "%s%08x  ", indent, i);

        for (j = 0; j < 16; j++) {
            if ((i + j) < bytes->len) {
                g_string_append_printf(gstr, "%02x ",
                                       bytes->data[i + j]);
            } else {
                g_string_append(gstr, "   ");
            }

            if (j == 7) {
                g_string_append_c(gstr, ' ');
            }
        }

        g_string_append(gstr, " |");

        for (j = 0; (j < 16) && ((i + j) < bytes->len); j++) {
            c = bytes->data[i + j];

            if (!g_ascii_isprint(c) || g_ascii_isspace(c)) {
                c = '.';
            }

            g_string_append_c(gstr, c);
        }

        g_string_append_c(gstr, '|');
        fb_util_debug(level, "%s", gstr->str);
        g_string_erase(gstr, 0, -1);
    }

    g_string_append_printf(gstr, "%s%08x", indent, i);
    fb_util_debug(level, "%s", gstr->str);
    g_string_free(gstr, TRUE);
}
Example #19
0
void g_debug_hexdump(const char *msg, const void *_s, size_t len) {
	GString *hex;
	size_t i;
	const unsigned char *s = _s;
		
       	hex = g_string_new(NULL);

	for (i = 0; i < len; i++) {
		if (i % 16 == 0) {
			g_string_append_printf(hex, "[%04"G_GSIZE_MODIFIER"x]  ", i);
		}
		g_string_append_printf(hex, "%02x", s[i]);

		if ((i + 1) % 16 == 0) {
			size_t j;
			g_string_append_len(hex, C("  "));
			for (j = i - 15; j <= i; j++) {
				g_string_append_c(hex, g_ascii_isprint(s[j]) ? s[j] : '.');
			}
			g_string_append_len(hex, C("\n  "));
		} else {
			g_string_append_c(hex, ' ');
		}
	}

	if (i % 16 != 0) {
		/* fill up the line */
		size_t j;

		for (j = 0; j < 16 - (i % 16); j++) {
			g_string_append_len(hex, C("   "));
		}

		g_string_append_len(hex, C(" "));
		for (j = i - (len % 16); j < i; j++) {
			g_string_append_c(hex, g_ascii_isprint(s[j]) ? s[j] : '.');
		}
	}

	g_debug("(%s) %"G_GSIZE_FORMAT" bytes:\n  %s", 
			msg, 
			len,
			hex->str);

	g_string_free(hex, TRUE);
}
Example #20
0
void ByteViewTab::copyHexTextDump(const guint8 *data_p, int data_len, bool append_text)
{
    QString clipboard_text;
    /* Write hex data for a line, then ascii data, then concatenate and add to buffer */
    QString hex_str, char_str;
    int i;
    bool end_of_line = true; /* Initial state is end of line */
    int byte_line_part_length;

    i = 0;
    while (i < data_len) {
        if(end_of_line) {
            hex_str += QString("%1  ").arg(i, 4, 16, QChar('0')); /* Offset - note that we _append_ here */
        }

        hex_str += QString(" %1").arg(*data_p, 2, 16, QChar('0'));
        if(append_text) {
            char_str += QString("%1").arg(g_ascii_isprint(*data_p) ? QChar(*data_p) : '.');
        }

        ++data_p;

        /* Look ahead to see if this is the end of the data */
        byte_line_part_length = (++i) % byte_line_length_;
        if(i >= data_len){
            /* End of data - need to fill in spaces in hex string and then do "end of line".
             *
             */
            if (append_text) {
                int fill_len = byte_line_part_length == 0 ?
                            0 : byte_line_length_ - byte_line_part_length;
                /* Add three spaces for each missing byte */
                hex_str += QString(fill_len * 3, ' ');
            }
            end_of_line = true;
        } else {
            end_of_line = (byte_line_part_length == 0);
        }

        if (end_of_line){
            /* End of line */
            clipboard_text += hex_str;
            if(append_text) {
                /* Two spaces between hex and text */
                clipboard_text += "  ";
                clipboard_text += char_str;
            }
            /* Setup ready for next line */
            hex_str = "\n";
            char_str.clear();
        }
    }

    if (!clipboard_text.isEmpty()) {
        qApp->clipboard()->setText(clipboard_text);
    }
}
Example #21
0
static gboolean
_compile_dot_notation_member_ref(const gchar *level, JSONDotNotationElem *elem)
{
  const gchar *p = level;

  if (!g_ascii_isprint(*p) || strchr(".[]", *p) != NULL)
    return FALSE;

  while (g_ascii_isprint(*p) && strchr(".[]", *p) == NULL)
    p++;

  if (*p != 0)
    return FALSE;

  elem->type = JS_MEMBER_REF;
  elem->member_ref.name = g_strdup(level);
  return TRUE;
}
static inline void sanitize_buffer(char *buffer, size_t nchars) {
    for (size_t i = 0; i < nchars; i++) {
        if (buffer[i] == '\n' || buffer[i] == '\r' || buffer[i] == '\t')
            continue;
        if (! g_ascii_isprint((guchar)buffer[i])) {
            buffer[i] = '.';
        }
    }
}
Example #23
0
void g_get_sql_sent(char * ret , const void * _s , int len)
{
  size_t i;
  const unsigned char *s = &(_s[4]);
  
  GString * sql = g_string_new(NULL);
  
  for (i = 0; i < len; i++) {  
	  if ((i + 1) % 16 == 0) {
		  size_t j;
		  for (j = i - 15; j <= i; j++) {  
			  if (g_ascii_isprint(s[j]))
			  {
				g_string_append_c(sql, s[j]);
			  }
		  }
	  }
  }
  
  if (i % 16 != 0) {
	  size_t j;
	  for (j = i - (len % 16); j < i; j++) {  
		  if (g_ascii_isprint(s[j]))
		  {
			g_string_append_c(sql, s[j]); 
		  }
	  }
  }
  
  if (sql->str[0] == '%' || 
  	sql->str[0] == '/' || 
  	sql->str[0] == '(' || 
  	sql->str[0] == '$')
  {
    (void)strcpy(ret , &(sql->str[1]));
  }
  else
  {
    (void)strcpy(ret , sql->str);
  }
  
  g_string_free(sql , TRUE);
}
Example #24
0
static gboolean
strn_isprint(const gchar *start, const gchar *end)
{
	while (start < end) {
		register gchar c = *(start++);
		if (!g_ascii_isprint(c) && !g_ascii_isspace(c) && c!='\n')
			return FALSE;
	}
	return TRUE;
}
Example #25
0
gchar *
cut_utils_inspect_memory (const void *memory, size_t size)
{
    const guchar *binary = memory;
    GString *buffer;
    size_t i, n_printable_characters;
    size_t max_size = 1024;

    if (memory == NULL || size == 0)
        return g_strdup("(null)");

    buffer = g_string_sized_new(size * strlen("0xXX") +
                                (size - 1) * strlen(" ") +
                                strlen(": ") +
                                size);
    max_size = MIN(size, max_size);
    n_printable_characters = 0;
    for (i = 0; i < max_size; i++) {
        g_string_append_printf(buffer, "0x%02x ", binary[i]);
        if (g_ascii_isprint(binary[i]))
            n_printable_characters++;
    }
    if (size > max_size)
        g_string_append(buffer, "... ");

    if (n_printable_characters >= max_size * 0.3) {
        g_string_overwrite(buffer, buffer->len - 1, ": ");
        for (i = 0; i < max_size; i++) {
            if (g_ascii_isprint(binary[i])) {
                g_string_append_c(buffer, binary[i]);
            } else {
                g_string_append_c(buffer, '.');
            }
        }
        if (size > max_size)
            g_string_append(buffer, "...");
    } else {
        g_string_truncate(buffer, buffer->len - 1);
    }

    return g_string_free(buffer, FALSE);
}
Example #26
0
/* check for valid path string */
static gboolean
is_valid_path(const char *path)
{
    const char *ptr;
    if(path[0] != '/')
        return FALSE;
    for(ptr=path+1; *ptr!='\0'; ptr++)
        if( (g_ascii_isprint(*ptr) == 0) || (strchr(invalid_path_chars, *ptr) != NULL) )
            return FALSE;
    return TRUE;
}
Example #27
0
void k12_ascii_dump(guint level, guint8 *buf, guint32 len, guint32 buf_offset) {
    guint32 i;

    if (debug_level < level) return;

    for (i = buf_offset; i < len; i++) {
        if (g_ascii_isprint(buf[i]) || buf[i] == '\n' || buf[i] == '\t')
            putc(buf[i], dbg_out);
        else if (buf[i] == '\0')
            fprintf(dbg_out, "(NUL)\n");
    }
}
Example #28
0
gboolean
is_ascii (const char *value)
{
	const char *p = value;

	while (*p) {
		if (!g_ascii_isprint (*p++))
			return FALSE;
	}
	return TRUE;

}
Example #29
0
static bool validate_ident(const char *ident)
{
	unsigned int i;

	if (!ident)
		return false;

	for (i = 0; i < strlen(ident); i++)
		if (!g_ascii_isprint(ident[i]))
			return false;

	return true;
}
Example #30
0
static gboolean allowed_chars(tvbuff_t *tvb)
{
    gint offset, len;
    guint8 val;

    len = tvb_captured_length(tvb);
    for (offset = 0; offset < len; offset++) {
        val = tvb_get_guint8(tvb, offset);
        if (!(g_ascii_isprint(val) || (val == 0x0a) || (val == 0x0d)))
            return (FALSE);
    }
    return (TRUE);
}