#include <string.h>
#include <ctype.h>
#include <glib.h>
+#include <math.h>
#include "meta.h"
#include "util.h"
#include "get.h"
{ MONO_TYPE_R4 , "float32" },
{ MONO_TYPE_R8 , "float64" },
{ MONO_TYPE_STRING , "string" },
- { MONO_TYPE_TYPEDBYREF , "TypedByRef" },
+ { MONO_TYPE_TYPEDBYREF , "typedref" },
{ MONO_TYPE_I , "native int" },
{ MONO_TYPE_U , "native unsigned int" },
{ MONO_TYPE_OBJECT , "object" },
return result;
}
+static char*
+dis_stringify_variant_type (MonoMarshalVariant variant)
+{
+ switch (variant) {
+ case MONO_VARIANT_EMPTY:
+ return g_strdup ("");
+ case MONO_VARIANT_NULL:
+ return g_strdup ("null");
+ case MONO_VARIANT_I2:
+ return g_strdup ("int16");
+ case MONO_VARIANT_I4:
+ return g_strdup ("int32");
+ case MONO_VARIANT_R4:
+ return g_strdup ("float32");
+ case MONO_VARIANT_R8:
+ return g_strdup ("float64");
+ case MONO_VARIANT_CY:
+ return g_strdup ("currency");
+ case MONO_VARIANT_DATE:
+ return g_strdup ("date");
+ case MONO_VARIANT_BSTR:
+ return g_strdup ("bstr");
+ case MONO_VARIANT_DISPATCH:
+ return g_strdup ("idispatch");
+ case MONO_VARIANT_ERROR:
+ return g_strdup ("error");
+ case MONO_VARIANT_BOOL:
+ return g_strdup ("bool");
+ case MONO_VARIANT_VARIANT:
+ return g_strdup ("variant");
+ case MONO_VARIANT_UNKNOWN:
+ return g_strdup ("iunknown");
+ case MONO_VARIANT_DECIMAL:
+ return g_strdup ("decimal");
+ case MONO_VARIANT_I1:
+ return g_strdup ("int8");
+ case MONO_VARIANT_UI1:
+ return g_strdup ("unsigned int8");
+ case MONO_VARIANT_UI2:
+ return g_strdup ("unsigned int16");
+ case MONO_VARIANT_UI4:
+ return g_strdup ("unsigned int32");
+ case MONO_VARIANT_I8:
+ return g_strdup ("int64");
+ case MONO_VARIANT_UI8:
+ return g_strdup ("unsigned int64");
+ case MONO_VARIANT_INT:
+ return g_strdup ("int");
+ case MONO_VARIANT_UINT:
+ return g_strdup ("unsigned int");
+ case MONO_VARIANT_VOID:
+ return g_strdup ("void");
+ case MONO_VARIANT_HRESULT:
+ return g_strdup ("hresult");
+ case MONO_VARIANT_PTR:
+ return g_strdup ("*");
+ case MONO_VARIANT_SAFEARRAY:
+ return g_strdup ("safearray");
+ case MONO_VARIANT_CARRAY:
+ return g_strdup ("carray");
+ case MONO_VARIANT_USERDEFINED:
+ return g_strdup ("userdefined");
+ case MONO_VARIANT_LPSTR:
+ return g_strdup ("lpstr");
+ case MONO_VARIANT_LPWSTR:
+ return g_strdup ("lpwstr");
+ case MONO_VARIANT_RECORD:
+ return g_strdup ("record");
+ case MONO_VARIANT_FILETIME:
+ return g_strdup ("filetime");
+ case MONO_VARIANT_BLOB:
+ return g_strdup ("blob");
+ case MONO_VARIANT_STREAM:
+ return g_strdup ("stream");
+ case MONO_VARIANT_STORAGE:
+ return g_strdup ("storage");
+ case MONO_VARIANT_STREAMED_OBJECT:
+ return g_strdup ("streamed_object");
+ case MONO_VARIANT_STORED_OBJECT:
+ return g_strdup ("stored_object");
+ case MONO_VARIANT_BLOB_OBJECT:
+ return g_strdup ("blob_object");
+ case MONO_VARIANT_CF:
+ return g_strdup ("cf");
+ case MONO_VARIANT_CLSID:
+ return g_strdup ("clsid");
+ case MONO_VARIANT_VECTOR:
+ /* FIXME: output: <v_type> vector */
+ return g_strdup ("vector");
+ case MONO_VARIANT_ARRAY:
+ /* FIXME: output: <v_type> [ ] */
+ return g_strdup ("[]");
+ case MONO_VARIANT_BYREF:
+ /* FIXME: output: <v_type> & */
+ return g_strdup ("&");
+ default:
+ return g_strdup ("unknown");
+ }
+}
+
static char*
dis_stringify_native_type (MonoMarshalNative native)
{
}
}
-static char*
+char*
dis_stringify_marshal_spec (MonoMarshalSpec *spec)
{
switch (spec->native) {
case MONO_NATIVE_BYVALTSTR:
- return g_strdup_printf ("fixed sysstring [%d]", spec->data.array_data.num_elem);
+ return g_strdup_printf (" marshal (fixed sysstring [%d])", spec->data.array_data.num_elem);
case MONO_NATIVE_BYVALARRAY:
- return g_strdup_printf ("fixed array [%d]", spec->data.array_data.num_elem);
+ return g_strdup_printf (" marshal (fixed array [%d])", spec->data.array_data.num_elem);
case MONO_NATIVE_LPARRAY: {
- char *elem_type, *elems;
+ char *elem_type, *elems, *ret;
guint32 num_elem = spec->data.array_data.num_elem;
guint32 param_num = spec->data.array_data.param_num;
elems = g_strdup_printf ("+ %d", param_num);
else
elems = g_strdup_printf ("%d + %d", num_elem, param_num);
-
- return g_strdup_printf ("%s[%s]", elem_type, elems);
+
+ ret = g_strdup_printf (" marshal (%s[%s])", elem_type, elems);
+ g_free (elem_type);
+ g_free (elems);
+ return ret;
}
- default:
- return dis_stringify_native_type (spec->native);
+ case MONO_NATIVE_SAFEARRAY: {
+ char *elem_type = NULL, *ret;
+
+ if (spec->data.safearray_data.elem_type != 0)
+ elem_type = dis_stringify_variant_type (spec->data.safearray_data.elem_type);
+ ret = g_strdup_printf (" marshal (safearray %s)", elem_type ? elem_type : "");
+
+ g_free (elem_type);
+ return ret;
+ }
+ default: {
+ char *native_type, *ret;
+ native_type = dis_stringify_native_type (spec->native);
+ ret = g_strdup_printf (" marshal (%s)", native_type);
+ g_free (native_type);
+ return ret;
+ }
}
}
{
guint32 cols [MONO_METHOD_SIZE];
guint32 pcols [MONO_PARAM_SIZE];
- guint32 param_index = 0;
- const char *name = "";
+ guint32 param_index = 0, next_param_index = 0;
+ gboolean has_param_row;
+ const char *name = "", *method_name = "";
int free_method = 0;
char *retval, *esname;
char *type = NULL;
- char *marshal_info = NULL;
+ char *marshal_info = NULL, *ret_marshal_info = NULL;
char *gen_param = NULL;
GString *result = g_string_new ("");
+ GString *result_ret = g_string_new ("");
MonoGenericContainer *container = NULL;
- int i;
+ int i, start;
g_assert (method || methoddef_row);
mono_metadata_decode_row (&m->tables [MONO_TABLE_METHOD], methoddef_row -1, cols, MONO_METHOD_SIZE);
if (fully_qualified)
type = get_typedef (m, mono_metadata_typedef_from_method (m, methoddef_row));
- name = mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]);
+ method_name = mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]);
param_index = cols [MONO_METHOD_PARAMLIST];
if (!method) {
const char *sig = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
if (container && container->is_method)
gen_param = get_generic_param (m, container);
- }
-
- retval = dis_stringify_param (m, method->ret);
- if (method->hasthis)
- g_string_append (result, "instance ");
- g_string_append (result, map (method->call_convention, call_conv_type_map));
- g_string_sprintfa (result, " %s ", retval);
- if (type) {
- char *estype = get_escaped_name (type);
- g_string_sprintfa (result, "%s::", estype);
- g_free (estype);
- }
- esname = get_escaped_name (name);
- g_string_append (result, esname);
- g_free (esname);
- if (gen_param) {
- g_string_append (result, gen_param);
- g_free (gen_param);
- }
- g_string_append (result, " (");
- g_free (retval);
- for (i = 0; i < method->param_count; ++i) {
- if (param_index && param_index <= m->tables [MONO_TABLE_PARAM].rows) {
+
+ if (methoddef_row < m->tables [MONO_TABLE_METHOD].rows) {
+ mono_metadata_decode_row (&m->tables [MONO_TABLE_METHOD], methoddef_row, cols, MONO_METHOD_SIZE);
+ next_param_index = cols [MONO_METHOD_PARAMLIST];
+ } else {
+ next_param_index = m->tables [MONO_TABLE_PARAM].rows + 1;
+ }
+ }
+
+ start = method->hasthis ? 0 : 1;
+ for (i = 0; i < method->param_count + 1; ++i) {
+ marshal_info = NULL;
+ name = "";
+ has_param_row = param_index && param_index < next_param_index;
+
+ if (method->param_count == 0 && !has_param_row)
+ /* method has zero parameters, and no row for return val in the PARAM table */
+ continue;
+
+ if (has_param_row)
mono_metadata_decode_row (&m->tables [MONO_TABLE_PARAM], param_index - 1, pcols, MONO_PARAM_SIZE);
- name = mono_metadata_string_heap (m, pcols [MONO_PARAM_NAME]);
- method->params [i]->attrs = pcols [MONO_PARAM_FLAGS];
+
+ if (has_param_row && i == pcols [MONO_PARAM_SEQUENCE]) {
+ if (i)
+ name = mono_metadata_string_heap (m, pcols [MONO_PARAM_NAME]);
if (pcols [MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_FIELD_MARSHAL) {
const char *tp;
g_assert (tp);
spec = mono_metadata_parse_marshal_spec (m, tp);
- marshal_info = g_strdup_printf (" marshal (%s)", dis_stringify_marshal_spec (spec));
+ if (i)
+ marshal_info = dis_stringify_marshal_spec (spec);
+ else
+ ret_marshal_info = dis_stringify_marshal_spec (spec);
}
-
- param_index++;
+ param_index ++;
} else {
- name = "";
+ if (i)
+ name = g_strdup_printf ("A_%i", i - start);
}
- if (i)
+
+ if (!i)
+ continue;
+
+ if (i > 1)
g_string_append (result, ", ");
- retval = dis_stringify_param (m, method->params [i]);
+
+ retval = dis_stringify_param (m, method->params [i - 1]);
esname = get_escaped_name (name);
- g_string_append_printf (result, "%s %s%s", retval, esname, marshal_info ? marshal_info : "");
+ g_string_append_printf (result, "%s%s %s", retval, marshal_info ? marshal_info : "", esname);
g_free (retval);
g_free (esname);
+ g_free (marshal_info);
}
g_string_append (result, ") ");
+ retval = dis_stringify_param (m, method->ret);
+
+ if (method->hasthis)
+ g_string_append (result_ret, "instance ");
+ g_string_append (result_ret, map (method->call_convention, call_conv_type_map));
+ g_string_sprintfa (result_ret, " %s%s ", retval, ret_marshal_info ? ret_marshal_info :"");
+ g_free (ret_marshal_info);
+ if (type) {
+ char *estype = get_escaped_name (type);
+ g_string_sprintfa (result_ret, "%s::", estype);
+ g_free (estype);
+ }
+ esname = get_escaped_name (method_name);
+ g_string_append (result_ret, esname);
+ g_free (esname);
+ if (gen_param) {
+ g_string_append (result_ret, gen_param);
+ g_free (gen_param);
+ }
+ g_string_append (result_ret, " (");
+ g_free (retval);
+
+ g_string_prepend (result, result_ret->str);
+ g_string_free (result_ret, FALSE);
+
if (show_method_tokens && methoddef_row)
g_string_append_printf (result, " /* 0x%X */ ",
(methoddef_row >> MONO_TYPEORMETHOD_BITS) | MONO_TOKEN_METHOD_DEF);
}
if (*ptr == MONO_TYPE_TYPEDBYREF){
- g_string_append (str, "typedbyref");
+ g_string_append (str, "typedref");
ptr++;
} else if (*ptr == MONO_TYPE_VOID){
g_string_append (str, "void");
}
if (*ptr == MONO_TYPE_TYPEDBYREF){
- g_string_append (str, " typedbyref ");
+ g_string_append (str, " typedref ");
ptr++;
} else {
gboolean by_ref = 0;
{ FIELD_ATTRIBUTE_SPECIAL_NAME, "specialname " },
{ FIELD_ATTRIBUTE_PINVOKE_IMPL, "FIXME:pinvokeimpl " },
{ FIELD_ATTRIBUTE_RT_SPECIAL_NAME, "rtspecialname " },
- { FIELD_ATTRIBUTE_HAS_FIELD_MARSHAL, "hasfieldmarshal " },
+ /*{ FIELD_ATTRIBUTE_HAS_FIELD_MARSHAL, "hasfieldmarshal " },*/
{ 0, NULL }
};
case MONO_TYPE_U4:
case MONO_TYPE_I4:
- return g_strdup_printf ("int32(%d)", read32 (ptr));
+ return g_strdup_printf ("int32(0x%08x)", read32 (ptr));
+ case MONO_TYPE_U8:
case MONO_TYPE_I8: {
guint32 low, high;
low = read32 (ptr);
high = read32 (ptr + 4);
return g_strdup_printf ("int64(0x%08x%08x)", high, low);
}
- case MONO_TYPE_U8: {
- guint32 low, high;
- low = read32 (ptr);
- high = read32 (ptr + 4);
- return g_strdup_printf ("0x%08x%08x", high, low);
- }
case MONO_TYPE_R4: {
float r;
readr4 (ptr, &r);
- return g_strdup_printf ("float32(%g)", (double) r);
- }
+ if (! isnormal (r))
+ return g_strdup_printf ("float32(0x%08x)", read32 (ptr));
+ else
+ return g_strdup_printf ("float32(%g)", r);
+ }
case MONO_TYPE_R8: {
double r;
readr8 (ptr, &r);
- return g_strdup_printf ("float64(%g)", r);
+ if (! isnormal (r)) {
+ guint32 low, high;
+ low = read32 (ptr);
+ high = read32 (ptr + 4);
+ return g_strdup_printf ("float64(0x%08x%08x)", high, low);
+ } else {
+ return g_strdup_printf ("float64(%g)", r);
+ }
}
case MONO_TYPE_STRING: {
gchar *str;
result = g_strdup_printf ("field %s", temp);
g_free (temp);
return result;
- }
- else {
- g_error ("Do not know how to decode tokens of type 0x%08x", token);
+ } else {
+ temp = get_method (m, token, context);
+ result = g_strdup_printf ("method %s", temp);
+ g_free (temp);
+ return result;
}
break;
}
g_hash_table_insert (key_table, (char *) "wchar", GINT_TO_POINTER (TRUE));
g_hash_table_insert (key_table, (char *) "winapi", GINT_TO_POINTER (TRUE));
g_hash_table_insert (key_table, (char *) "with", GINT_TO_POINTER (TRUE));
+ g_hash_table_insert (key_table, (char *) "xor", GINT_TO_POINTER (TRUE));
}
guint32