3 * Assorted utilities for the disassembler
6 * Miguel de Icaza (miguel@ximian.com)
8 * (C) 2001 Ximian, Inc (http://www.ximian.com)
16 #include "mono/utils/mono-compiler.h"
17 #include "mono/utils/mono-math.h"
20 * \param code code to lookup in table
21 * \param table table to decode code
23 * Warning: returns static buffer.
26 map (guint32 code
, dis_map_t
*table
)
30 for (i
= 0; table
[i
].str
!= NULL
; i
++)
31 if (table
[i
].code
== code
)
33 return "invalid-flags";
37 * \param code bitfield
38 * \param table table to decode bitfield
40 * Warning: returns static buffer.
43 flags (guint32 code
, dis_map_t
*table
)
45 static char buffer
[1024];
50 for (i
= 0; code
&& table
[i
].str
!= NULL
; i
++)
51 if (table
[i
].code
& code
) {
52 code
&= ~table
[i
].code
;
53 strcat (buffer
, table
[i
].str
);
57 sprintf (buffer
+ strlen (buffer
), "unknown-flag-%2x ", code
);
64 * @buffer: pointer to buffer to dump
65 * @base: numbering base to use
66 * @count: number of bytes to dump
69 hex_dump (const char *buffer
, int base
, int count
)
79 for (i
= 0; i
< count
; i
++){
82 printf ("\n0x%08X: ", (unsigned char) base
+ i
);
84 printf ("%02X ", (unsigned char) (buffer
[i
]));
90 data_dump (const char *data
, int len
, const char* prefix
) {
94 return g_strdup (" ()\n");
95 str
= g_string_new (" (");
96 for (i
= 0; i
+ 15 < len
; i
+= 16) {
98 g_string_append_printf (str
, "\n");
99 g_string_append_printf (str
, "%s", prefix
);
100 for (j
= 0; j
< 16; ++j
)
101 g_string_append_printf (str
, "%02X ", (unsigned char) (data
[i
+ j
]));
102 g_string_append_printf (str
, i
== len
- 16? ") // ": " // ");
103 for (j
= 0; j
< 16; ++j
)
104 g_string_append_printf (str
, "%c", data
[i
+ j
] >= 32 && data
[i
+ j
] <= 126? data
[i
+ j
]: '.');
105 g_string_append_printf (str
, "\n");
108 return g_string_free (str
, FALSE
);
110 g_string_append_printf (str
, "%s", prefix
);
113 g_string_append_printf (str
, "%02X ", (unsigned char) (data
[i
]));
116 int count
= 16 - (len
% 16);
117 for (i
= 0; i
< count
; ++i
)
118 g_string_append_printf (str
, " ");
120 g_string_append_printf (str
, ") // ");
121 for (i
= j
; i
< len
; ++i
)
122 g_string_append_printf (str
, "%c", data
[i
] >= 32 && data
[i
] <= 126? data
[i
]: '.');
123 g_string_append_printf (str
, "\n");
124 return g_string_free (str
, FALSE
);