Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/coml2/stg_prop.c
8745 views
1
/*
2
* Compound Storage (32 bit version)
3
* Storage implementation
4
*
5
* This file contains the compound file implementation
6
* of the storage interface.
7
*
8
* Copyright 1999 Francis Beaudet
9
* Copyright 1999 Sylvain St-Germain
10
* Copyright 1999 Thuy Nguyen
11
* Copyright 2005 Mike McCormack
12
* Copyright 2005 Juan Lang
13
* Copyright 2006 Mike McCormack
14
*
15
* This library is free software; you can redistribute it and/or
16
* modify it under the terms of the GNU Lesser General Public
17
* License as published by the Free Software Foundation; either
18
* version 2.1 of the License, or (at your option) any later version.
19
*
20
* This library is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
* Lesser General Public License for more details.
24
*
25
* You should have received a copy of the GNU Lesser General Public
26
* License along with this library; if not, write to the Free Software
27
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28
*
29
* TODO:
30
* - I don't honor the maximum property set size.
31
* - Certain bogus files could result in reading past the end of a buffer.
32
* - Mac-generated files won't be read correctly, even if they're little
33
* endian, because I disregard whether the generator was a Mac. This means
34
* strings will probably be munged (as I don't understand Mac scripts.)
35
* - Not all PROPVARIANT types are supported.
36
* - User defined properties are not supported, see comment in
37
* PropertyStorage_ReadFromStream
38
*/
39
40
#include <assert.h>
41
#include <stdarg.h>
42
#include <stdio.h>
43
#include <stdlib.h>
44
#include <string.h>
45
46
#define COBJMACROS
47
#include "windef.h"
48
#include "winbase.h"
49
#include "winnls.h"
50
#include "winuser.h"
51
#include "wine/asm.h"
52
#include "wine/debug.h"
53
#include "oleauto.h"
54
55
WINE_DEFAULT_DEBUG_CHANNEL(storage);
56
57
/***********************************************************************
58
* Format ID <-> name conversion
59
*/
60
static const WCHAR szSummaryInfo[] = L"\5SummaryInformation";
61
static const WCHAR szDocSummaryInfo[] = L"\5DocumentSummaryInformation";
62
63
#define BITS_PER_BYTE 8
64
#define CHARMASK 0x1f
65
#define BITS_IN_CHARMASK 5
66
#define NUM_ALPHA_CHARS 26
67
68
/***********************************************************************
69
* FmtIdToPropStgName [coml2.@]
70
*/
71
HRESULT WINAPI FmtIdToPropStgName(const FMTID *rfmtid, LPOLESTR str)
72
{
73
static const char fmtMap[] = "abcdefghijklmnopqrstuvwxyz012345";
74
75
TRACE("%s, %p\n", debugstr_guid(rfmtid), str);
76
77
if (!rfmtid) return E_INVALIDARG;
78
if (!str) return E_INVALIDARG;
79
80
if (IsEqualGUID(&FMTID_SummaryInformation, rfmtid))
81
lstrcpyW(str, szSummaryInfo);
82
else if (IsEqualGUID(&FMTID_DocSummaryInformation, rfmtid))
83
lstrcpyW(str, szDocSummaryInfo);
84
else if (IsEqualGUID(&FMTID_UserDefinedProperties, rfmtid))
85
lstrcpyW(str, szDocSummaryInfo);
86
else
87
{
88
const BYTE *fmtptr;
89
WCHAR *pstr = str;
90
ULONG bitsRemaining = BITS_PER_BYTE;
91
92
*pstr++ = 5;
93
for (fmtptr = (const BYTE *)rfmtid; fmtptr < (const BYTE *)rfmtid + sizeof(FMTID); )
94
{
95
ULONG i = *fmtptr >> (BITS_PER_BYTE - bitsRemaining);
96
97
if (bitsRemaining >= BITS_IN_CHARMASK)
98
{
99
*pstr = (WCHAR)(fmtMap[i & CHARMASK]);
100
if (bitsRemaining == BITS_PER_BYTE && *pstr >= 'a' &&
101
*pstr <= 'z')
102
*pstr += 'A' - 'a';
103
pstr++;
104
bitsRemaining -= BITS_IN_CHARMASK;
105
if (bitsRemaining == 0)
106
{
107
fmtptr++;
108
bitsRemaining = BITS_PER_BYTE;
109
}
110
}
111
else
112
{
113
if (++fmtptr < (const BYTE *)rfmtid + sizeof(FMTID))
114
i |= *fmtptr << bitsRemaining;
115
*pstr++ = (WCHAR)(fmtMap[i & CHARMASK]);
116
bitsRemaining += BITS_PER_BYTE - BITS_IN_CHARMASK;
117
}
118
}
119
*pstr = 0;
120
}
121
TRACE("returning %s\n", debugstr_w(str));
122
return S_OK;
123
}
124
125
/***********************************************************************
126
* PropStgNameToFmtId [coml2.@]
127
*/
128
HRESULT WINAPI PropStgNameToFmtId(const LPOLESTR str, FMTID *rfmtid)
129
{
130
HRESULT hr = STG_E_INVALIDNAME;
131
132
TRACE("%s, %p\n", debugstr_w(str), rfmtid);
133
134
if (!rfmtid) return E_INVALIDARG;
135
if (!str) return STG_E_INVALIDNAME;
136
137
if (!lstrcmpiW(str, szDocSummaryInfo))
138
{
139
*rfmtid = FMTID_DocSummaryInformation;
140
hr = S_OK;
141
}
142
else if (!lstrcmpiW(str, szSummaryInfo))
143
{
144
*rfmtid = FMTID_SummaryInformation;
145
hr = S_OK;
146
}
147
else
148
{
149
ULONG bits;
150
BYTE *fmtptr = (BYTE *)rfmtid - 1;
151
const WCHAR *pstr = str;
152
153
memset(rfmtid, 0, sizeof(*rfmtid));
154
for (bits = 0; bits < sizeof(FMTID) * BITS_PER_BYTE;
155
bits += BITS_IN_CHARMASK)
156
{
157
ULONG bitsUsed = bits % BITS_PER_BYTE, bitsStored;
158
WCHAR wc;
159
160
if (bitsUsed == 0)
161
fmtptr++;
162
wc = *++pstr - 'A';
163
if (wc > NUM_ALPHA_CHARS)
164
{
165
wc += 'A' - 'a';
166
if (wc > NUM_ALPHA_CHARS)
167
{
168
wc += 'a' - '0' + NUM_ALPHA_CHARS;
169
if (wc > CHARMASK)
170
{
171
WARN("invalid character (%d)\n", *pstr);
172
goto end;
173
}
174
}
175
}
176
*fmtptr |= wc << bitsUsed;
177
bitsStored = min(BITS_PER_BYTE - bitsUsed, BITS_IN_CHARMASK);
178
if (bitsStored < BITS_IN_CHARMASK)
179
{
180
wc >>= BITS_PER_BYTE - bitsUsed;
181
if (bits + bitsStored == sizeof(FMTID) * BITS_PER_BYTE)
182
{
183
if (wc != 0)
184
{
185
WARN("extra bits\n");
186
goto end;
187
}
188
break;
189
}
190
fmtptr++;
191
*fmtptr |= (BYTE)wc;
192
}
193
}
194
hr = S_OK;
195
}
196
end:
197
return hr;
198
}
199
200