Author: zoltan
Date: 2007-03-14 13:21:16 -0500 (Wed, 14 Mar 2007)
New Revision: 74290

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/process.c
Log:
2007-03-14  Zoltan Varga  <[EMAIL PROTECTED]>

        * process.c: Fix endianness issues. Fixes #81126.


Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2007-03-14 17:49:13 UTC (rev 74289)
+++ trunk/mono/mono/metadata/ChangeLog  2007-03-14 18:21:16 UTC (rev 74290)
@@ -1,5 +1,7 @@
 2007-03-14  Zoltan Varga  <[EMAIL PROTECTED]>
 
+       * process.c: Fix endianness issues. Fixes #81126.
+
        * reflection.c (mono_reflection_create_dynamic_method): Fix the last 
change so
        multiple circular calls made from the same DynamicMethod work. Fixes 
#81141.
 

Modified: trunk/mono/mono/metadata/process.c
===================================================================
--- trunk/mono/mono/metadata/process.c  2007-03-14 17:49:13 UTC (rev 74289)
+++ trunk/mono/mono/metadata/process.c  2007-03-14 18:21:16 UTC (rev 74290)
@@ -98,15 +98,32 @@
        } while(1);
 }
 
+static gunichar2*
+unicode_get (const gunichar2 *str)
+{
+       gunichar2 *swapped;
+       int i, len;
+
+       len = unicode_bytes (str);
+       swapped = g_malloc0 (len);
+       i = 0;
+       while (str [i]) {
+               swapped [i] = GUINT16_FROM_LE (str [i]);
+               i ++;
+       }
+
+       return swapped;
+}
+
 /* 
- * compare a null-terminated utf16 string and a normal string.
+ * compare a little-endian null-terminated utf16 string and a normal string.
  * Can be used only for ascii or latin1 chars.
  */
 static gboolean
 unicode_string_equals (const gunichar2 *str1, const gchar *str2)
 {
        while (*str1 && *str2) {
-               if (*str1 != *str2)
+               if (GUINT16_TO_LE (*str1) != *str2)
                        return FALSE;
                ++str1;
                ++str2;
@@ -212,13 +229,13 @@
 static gpointer process_get_versioninfo_block (gpointer data,
                                               version_data *block)
 {
-       block->data_len=*((guint16 *)data);
+       block->data_len=GUINT16_TO_LE (*((guint16 *)data));
        data = (char *)data + sizeof(guint16);
-       block->value_len=*((guint16 *)data);
+       block->value_len=GUINT16_TO_LE (*((guint16 *)data));
        data = (char *)data + sizeof(guint16);
 
        /* No idea what the type is supposed to indicate */
-       block->type=*((guint16 *)data);
+       block->type=GUINT16_TO_LE (*((guint16 *)data));
        data = (char *)data + sizeof(guint16);
        block->key=((gunichar2 *)data);
 
@@ -288,7 +305,7 @@
                }
                
                string_len=string_len+block.data_len;
-               value=(gunichar2 *)data_ptr;
+               value=unicode_get ((gunichar2 *)data_ptr);
                /* Skip over the value */
                data_ptr=((gunichar2 *)data_ptr)+block.value_len;
 
@@ -323,6 +340,7 @@
                                 */
                        }
                }
+               g_free (value);
        }
        
        return(data_ptr);
@@ -338,6 +356,7 @@
                                                guint16 data_len)
 {
        version_data block;
+       gunichar2 *value;
        gchar *language;
        guint16 string_len=36;  /* length of the StringFileInfo block */
 
@@ -365,7 +384,8 @@
                }
                string_len=string_len+block.data_len;
 
-               language = g_utf16_to_utf8 (block.key, unicode_bytes 
(block.key), NULL, NULL, NULL);
+               value = unicode_get (block.key);
+               language = g_utf16_to_utf8 (value, unicode_bytes (block.key), 
NULL, NULL, NULL);
                g_strdown (language);
 
                /* Kludge: treat en_US as neutral too */
@@ -388,7 +408,8 @@
                                                            FALSE);
                }
                g_free (language);
-
+               g_free (value);
+               
                if(data_ptr==NULL) {
                        /* Child block hit padding */
 #ifdef DEBUG

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to