2 * util.c: Assorted utilities for the dissasembler
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc (http://www.ximian.com)
17 * @code: code to lookup in table
18 * @table: table to decode code
20 * Warning: returns static buffer.
23 map (guint32 code, dis_map_t *table)
27 for (i = 0; table [i].str != NULL; i++)
28 if (table [i].code == code)
30 return "invalid-flags";
36 * @table: table to decode bitfield
38 * Warning: returns static buffer.
41 flags (guint32 code, dis_map_t *table)
43 static char buffer [1024];
48 for (i = 0; table [i].str != NULL; i++)
49 if (table [i].code & code) {
52 strcat (buffer, table [i].str);
60 * @buffer: pointer to buffer to dump
61 * @base: numbering base to use
62 * @count: number of bytes to dump
65 hex_dump (const char *buffer, int base, int count)
75 for (i = 0; i < count; i++){
78 printf ("\n0x%08X: ", (unsigned char) base + i);
80 printf ("%02X ", (unsigned char) (buffer [i]));
86 data_dump (const char *data, int len, const char* prefix) {
90 return g_strdup (" ()\n");
91 str = g_string_new (" (");
92 for (i = 0; i + 15 < len; i += 16) {
94 g_string_sprintfa (str, "\n");
95 g_string_sprintfa (str, "%s", prefix);
96 for (j = 0; j < 16; ++j)
97 g_string_sprintfa (str, "%02X ", (unsigned char) (data [i + j]));
98 g_string_sprintfa (str, i == len - 16? ") // ": " // ");
99 for (j = 0; j < 16; ++j)
100 g_string_sprintfa (str, "%c", data [i + j] >= 32 && data [i + j] <= 126? data [i + j]: '.');
101 g_string_sprintfa (str, "\n");
104 return g_string_free (str, FALSE);
106 g_string_sprintfa (str, "%s", prefix);
109 g_string_sprintfa (str, "%02X ", (unsigned char) (data [i]));
112 int count = 16 - (len % 16);
113 for (i = 0; i < count; ++i)
114 g_string_sprintfa (str, " ");
116 g_string_sprintfa (str, ") // ");
117 for (i = j; i < len; ++i)
118 g_string_sprintfa (str, "%c", data [i] >= 32 && data [i] <= 126? data [i]: '.');
119 g_string_sprintfa (str, "\n");
120 return g_string_free (str, FALSE);