From b5614f763fe8e1f5c725cf26b693985a5ba6de5c Mon Sep 17 00:00:00 2001 From: Simon Richter Date: Tue, 17 Jun 2008 07:46:14 +0200 Subject: [PATCH] widl: Write string lengths in host endianness. 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 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c index 35c1f052381..97ec4ec7df9 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++)