summaryrefslogtreecommitdiffstats
path: root/libmsi/string.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-11-29 14:29:06 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2012-12-06 20:30:30 +0100
commitc65374371388780b01a2db999ecd3bc0e375b7c4 (patch)
tree046d45a0950f9f9663d17e1ec6f90d8683ee8856 /libmsi/string.c
parentdf9129a08f8744718d1445c357faeae006468fbc (diff)
downloadmsitools-c65374371388780b01a2db999ecd3bc0e375b7c4.tar.gz
msitools-c65374371388780b01a2db999ecd3bc0e375b7c4.tar.xz
msitools-c65374371388780b01a2db999ecd3bc0e375b7c4.zip
writing the string pool should be endian-friendly
Diffstat (limited to 'libmsi/string.c')
-rw-r--r--libmsi/string.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/libmsi/string.c b/libmsi/string.c
index 0a83dec..67bf7ae 100644
--- a/libmsi/string.c
+++ b/libmsi/string.c
@@ -562,7 +562,7 @@ unsigned msi_save_string_table( const string_table *st, IStorage *storage, unsig
unsigned i, datasize = 0, poolsize = 0, sz, used, r, codepage, n;
unsigned ret = ERROR_FUNCTION_FAILED;
char *data = NULL;
- uint16_t *pool = NULL;
+ uint8_t *pool = NULL;
TRACE("\n");
@@ -586,11 +586,13 @@ unsigned msi_save_string_table( const string_table *st, IStorage *storage, unsig
used = 0;
codepage = st->codepage;
- pool[0] = codepage & 0xffff;
- pool[1] = codepage >> 16;
+ pool[0] = codepage & 0xff;
+ pool[1] = codepage >> 8;
+ pool[2] = codepage >> 16;
+ pool[3] = codepage >> 24;
if (st->maxcount > 0xffff)
{
- pool[1] |= 0x8000;
+ pool[3] |= 0x80;
*bytes_per_strref = LONG_STR_BYTES;
}
else
@@ -601,8 +603,10 @@ unsigned msi_save_string_table( const string_table *st, IStorage *storage, unsig
{
if( !st->strings[n].persistent_refcount )
{
- pool[ i*2 ] = 0;
- pool[ i*2 + 1] = 0;
+ pool[ i*4 ] = 0;
+ pool[ i*4 + 1] = 0;
+ pool[ i*4 + 2] = 0;
+ pool[ i*4 + 3] = 0;
i++;
continue;
}
@@ -615,22 +619,30 @@ unsigned msi_save_string_table( const string_table *st, IStorage *storage, unsig
sz = 0;
}
- if (sz)
- pool[ i*2 + 1 ] = st->strings[n].persistent_refcount;
- else
- pool[ i*2 + 1 ] = 0;
- if (sz < 0x10000)
- {
- pool[ i*2 ] = sz;
+ if (sz == 0) {
+ pool[ i*4 ] = 0;
+ pool[ i*4 + 1 ] = 0;
+ pool[ i*4 + 2 ] = 0;
+ pool[ i*4 + 3 ] = 0;
i++;
+ continue;
}
- else
+
+ if (sz >= 0x10000)
{
- pool[ i*2 ] = 0;
- pool[ i*2 + 2 ] = sz&0xffff;
- pool[ i*2 + 3 ] = (sz>>16);
- i += 2;
+ /* Write a dummy entry, with the high part of the length
+ * in the reference count. */
+ pool[ i*4 ] = 0;
+ pool[ i*4 + 1 ] = 0;
+ pool[ i*4 + 2 ] = (sz >> 16);
+ pool[ i*4 + 3 ] = (sz >> 24);
+ i++;
}
+ pool[ i*4 ] = sz;
+ pool[ i*4 + 1 ] = sz >> 8;
+ pool[ i*4 + 2 ] = st->strings[n].persistent_refcount;
+ pool[ i*4 + 3 ] = st->strings[n].persistent_refcount >> 8;
+ i++;
used += sz;
if( used > datasize )
{