widl: Write string lengths in host endianness
Simon Richter
Simon.Richter at hogyros.de
Tue Jun 17 00:46:14 CDT 2008
Type libraries are currently parsed in host endianness, so byte arrays
that are going to be interpreted as integers need to be written in the
appropriate byte order.
---
tools/widl/write_msft.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c
index 35c1f05..97ec4ec 100644
--- a/tools/widl/write_msft.c
+++ b/tools/widl/write_msft.c
@@ -296,16 +296,23 @@ static int ctl2_encode_name(
length = strlen(name);
memcpy(converted_name + 4, name, length);
- converted_name[0] = length & 0xff;
converted_name[length + 4] = 0;
- converted_name[1] = 0x00;
value = lhash_val_of_name_sys(typelib->typelib_header.varflags & 0x0f, typelib->typelib_header.lcid, converted_name + 4);
+#ifdef WORDS_BIGENDIAN
+ converted_name[3] = length & 0xff;
+ converted_name[2] = 0x00;
+ converted_name[1] = value;
+ converted_name[0] = value >> 8;
+#else
+ converted_name[0] = length & 0xff;
+ converted_name[1] = 0x00;
converted_name[2] = value;
converted_name[3] = value >> 8;
+#endif
for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
@@ -339,8 +346,14 @@ static int ctl2_encode_string(
length = strlen(string);
memcpy(converted_string + 2, string, length);
+
+#ifdef WORDS_BIGENDIAN
+ converted_string[1] = length & 0xff;
+ converted_string[0] = (length >> 8) & 0xff;
+#else
converted_string[0] = length & 0xff;
converted_string[1] = (length >> 8) & 0xff;
+#endif
if(length < 3) { /* strings of this length are padded with up to 8 bytes incl the 2 byte length */
for(offset = 0; offset < 4; offset++)
--
1.5.5.4
More information about the wine-patches
mailing list