X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fdis%2Futil.c;h=f3fff1c77e7fa84615fc2ce9bd36bf6a85ea1ad1;hb=6f43af2ae166ea2820dcb7560c1b8afe05d1864e;hp=997f67fe2b77559f5cfb03b7f45c231b26ba2963;hpb=8cb994c635a19d242b2edc34a77d59a4c806e64b;p=mono.git diff --git a/mono/dis/util.c b/mono/dis/util.c index 997f67fe2b7..f3fff1c77e7 100644 --- a/mono/dis/util.c +++ b/mono/dis/util.c @@ -20,7 +20,7 @@ * Warning: returns static buffer. */ const char * -map (guint32 code, map_t *table) +map (guint32 code, dis_map_t *table) { int i; @@ -38,7 +38,7 @@ map (guint32 code, map_t *table) * Warning: returns static buffer. */ const char * -flags (guint32 code, map_t *table) +flags (guint32 code, dis_map_t *table) { static char buffer [1024]; int i; @@ -75,10 +75,48 @@ hex_dump (const char *buffer, int base, int count) for (i = 0; i < count; i++){ if (show_header) if ((i % 16) == 0) - printf ("\n0x%08x: ", (unsigned char) base + i); + printf ("\n0x%08X: ", (unsigned char) base + i); - printf ("%02x ", (unsigned char) (buffer [i])); + printf ("%02X ", (unsigned char) (buffer [i])); } fflush (stdout); } +char* +data_dump (const char *data, int len, const char* prefix) { + int i, j; + GString *str; + if (!len) + return g_strdup (" ()\n"); + str = g_string_new (" ("); + for (i = 0; i + 15 < len; i += 16) { + if (i == 0) + g_string_sprintfa (str, "\n"); + g_string_sprintfa (str, "%s", prefix); + for (j = 0; j < 16; ++j) + g_string_sprintfa (str, "%02X ", (unsigned char) (data [i + j])); + g_string_sprintfa (str, i == len - 16? ") // ": " // "); + for (j = 0; j < 16; ++j) + g_string_sprintfa (str, "%c", data [i + j] >= 32 && data [i + j] <= 126? data [i + j]: '.'); + g_string_sprintfa (str, "\n"); + } + if (i == len) + return g_string_free (str, FALSE); + if (len > 16) + g_string_sprintfa (str, "%s", prefix); + j = i; + for (; i < len; ++i) + g_string_sprintfa (str, "%02X ", (unsigned char) (data [i])); + if (len > 16) { + /* align */ + int count = 16 - (len % 16); + for (i = 0; i < count; ++i) + g_string_sprintfa (str, " "); + } + g_string_sprintfa (str, ") // "); + for (i = j; i < len; ++i) + g_string_sprintfa (str, "%c", data [i] >= 32 && data [i] <= 126? data [i]: '.'); + g_string_sprintfa (str, "\n"); + return g_string_free (str, FALSE); +} +