summaryrefslogtreecommitdiff
path: root/registry/source/reflcnst.hxx
blob: 2c93a9cd22f28d17a20b7300d782392496828060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#pragma once

#include <registry/types.hxx>

#include <string.h>

#define REGTYPE_IEEE_NATIVE 1

extern const sal_uInt32 magic;
extern const sal_uInt16 minorVersion;
extern const sal_uInt16 majorVersion;

#define OFFSET_MAGIC                0
#define OFFSET_SIZE                 static_cast<sal_uInt32>(OFFSET_MAGIC + sizeof(magic))
#define OFFSET_MINOR_VERSION        static_cast<sal_uInt32>(OFFSET_SIZE + sizeof(sal_uInt32))
#define OFFSET_MAJOR_VERSION        static_cast<sal_uInt32>(OFFSET_MINOR_VERSION + sizeof(minorVersion))
#define OFFSET_N_ENTRIES            static_cast<sal_uInt32>(OFFSET_MAJOR_VERSION + sizeof(majorVersion))
#define OFFSET_TYPE_SOURCE          static_cast<sal_uInt32>(OFFSET_N_ENTRIES + sizeof(sal_uInt16))
#define OFFSET_TYPE_CLASS           static_cast<sal_uInt32>(OFFSET_TYPE_SOURCE + sizeof(sal_uInt16))
#define OFFSET_THIS_TYPE            static_cast<sal_uInt32>(OFFSET_TYPE_CLASS + sizeof(sal_uInt16))
#define OFFSET_UIK                  static_cast<sal_uInt32>(OFFSET_THIS_TYPE + sizeof(sal_uInt16))
#define OFFSET_DOKU                 static_cast<sal_uInt32>(OFFSET_UIK + sizeof(sal_uInt16))
#define OFFSET_FILENAME             static_cast<sal_uInt32>(OFFSET_DOKU + sizeof(sal_uInt16))

#define OFFSET_N_SUPERTYPES         static_cast<sal_uInt32>(OFFSET_FILENAME + sizeof(sal_uInt16))
#define OFFSET_SUPERTYPES           static_cast<sal_uInt32>(OFFSET_N_SUPERTYPES + sizeof(sal_uInt16))

#define OFFSET_CP_SIZE              static_cast<sal_uInt32>(OFFSET_SUPERTYPES + sizeof(sal_uInt16))
#define OFFSET_CP                   static_cast<sal_uInt32>(OFFSET_CP_SIZE + sizeof(sal_uInt16))

#define CP_OFFSET_ENTRY_SIZE        0
#define CP_OFFSET_ENTRY_TAG         static_cast<sal_uInt32>(CP_OFFSET_ENTRY_SIZE + sizeof(sal_uInt32))
#define CP_OFFSET_ENTRY_DATA        static_cast<sal_uInt32>(CP_OFFSET_ENTRY_TAG + sizeof(sal_uInt16))

#define FIELD_OFFSET_ACCESS         0
#define FIELD_OFFSET_NAME           static_cast<sal_uInt32>(FIELD_OFFSET_ACCESS + sizeof(sal_uInt16))
#define FIELD_OFFSET_TYPE           static_cast<sal_uInt32>(FIELD_OFFSET_NAME + sizeof(sal_uInt16))
#define FIELD_OFFSET_VALUE          static_cast<sal_uInt32>(FIELD_OFFSET_TYPE + sizeof(sal_uInt16))
#define FIELD_OFFSET_DOKU           static_cast<sal_uInt32>(FIELD_OFFSET_VALUE + sizeof(sal_uInt16))
#define FIELD_OFFSET_FILENAME       static_cast<sal_uInt32>(FIELD_OFFSET_DOKU + sizeof(sal_uInt16))

#define PARAM_OFFSET_TYPE           0
#define PARAM_OFFSET_MODE           static_cast<sal_uInt32>(PARAM_OFFSET_TYPE + sizeof(sal_uInt16))
#define PARAM_OFFSET_NAME           static_cast<sal_uInt32>(PARAM_OFFSET_MODE + sizeof(sal_uInt16))

#define METHOD_OFFSET_SIZE          0
#define METHOD_OFFSET_MODE          static_cast<sal_uInt32>(METHOD_OFFSET_SIZE + sizeof(sal_uInt16))
#define METHOD_OFFSET_NAME          static_cast<sal_uInt32>(METHOD_OFFSET_MODE + sizeof(sal_uInt16))
#define METHOD_OFFSET_RETURN        static_cast<sal_uInt32>(METHOD_OFFSET_NAME + sizeof(sal_uInt16))
#define METHOD_OFFSET_DOKU          static_cast<sal_uInt32>(METHOD_OFFSET_RETURN + sizeof(sal_uInt16))
#define METHOD_OFFSET_PARAM_COUNT   static_cast<sal_uInt32>(METHOD_OFFSET_DOKU + sizeof(sal_uInt16))

#define REFERENCE_OFFSET_TYPE       0
#define REFERENCE_OFFSET_NAME       static_cast<sal_uInt32>(REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16))
#define REFERENCE_OFFSET_DOKU       static_cast<sal_uInt32>(REFERENCE_OFFSET_NAME + sizeof(sal_uInt16))
#define REFERENCE_OFFSET_ACCESS     static_cast<sal_uInt32>(REFERENCE_OFFSET_DOKU + sizeof(sal_uInt16))

enum CPInfoTag
{
    CP_TAG_INVALID = RT_TYPE_NONE,
    CP_TAG_CONST_BOOL = RT_TYPE_BOOL,
    CP_TAG_CONST_BYTE  = RT_TYPE_BYTE,
    CP_TAG_CONST_INT16 = RT_TYPE_INT16,
    CP_TAG_CONST_UINT16 = RT_TYPE_UINT16,
    CP_TAG_CONST_INT32 = RT_TYPE_INT32,
    CP_TAG_CONST_UINT32 = RT_TYPE_UINT32,
    CP_TAG_CONST_INT64 = RT_TYPE_INT64,
    CP_TAG_CONST_UINT64 = RT_TYPE_UINT64,
    CP_TAG_CONST_FLOAT = RT_TYPE_FLOAT,
    CP_TAG_CONST_DOUBLE = RT_TYPE_DOUBLE,
    CP_TAG_CONST_STRING = RT_TYPE_STRING,
    CP_TAG_UTF8_NAME
};

inline sal_uInt32 writeUINT16(sal_uInt8* buffer, sal_uInt16 v)
{
    buffer[0] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
    buffer[1] = static_cast<sal_uInt8>((v >> 0) & 0xFF);

    return sizeof(sal_uInt16);
}

inline sal_uInt32 readUINT16(const sal_uInt8* buffer, sal_uInt16& v)
{
    //This is untainted data which comes from a controlled source
    //so, using a byte-swapping pattern which coverity doesn't
    //detect as such
    //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
    v = *buffer++; v <<= 8;
    v |= *buffer;
    return sizeof(sal_uInt16);
}

inline sal_uInt32 writeINT32(sal_uInt8* buffer, sal_Int32 v)
{
    buffer[0] = static_cast<sal_uInt8>((v >> 24) & 0xFF);
    buffer[1] = static_cast<sal_uInt8>((v >> 16) & 0xFF);
    buffer[2] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
    buffer[3] = static_cast<sal_uInt8>((v >> 0) & 0xFF);

    return sizeof(sal_Int32);
}

inline sal_uInt32 readINT32(const sal_uInt8* buffer, sal_Int32& v)
{
    v = (
            (buffer[0] << 24) |
            (buffer[1] << 16) |
            (buffer[2] << 8)  |
            (buffer[3] << 0)
        );

    return sizeof(sal_Int32);
}

inline sal_uInt32 writeUINT32(sal_uInt8* buffer, sal_uInt32 v)
{
    buffer[0] = static_cast<sal_uInt8>((v >> 24) & 0xFF);
    buffer[1] = static_cast<sal_uInt8>((v >> 16) & 0xFF);
    buffer[2] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
    buffer[3] = static_cast<sal_uInt8>((v >> 0) & 0xFF);

    return sizeof(sal_uInt32);
}

inline sal_uInt32 readUINT32(const sal_uInt8* buffer, sal_uInt32& v)
{
    //This is untainted data which comes from a controlled source
    //so, using a byte-swapping pattern which coverity doesn't
    //detect as such
    //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
    v = *buffer++; v <<= 8;
    v |= *buffer++; v <<= 8;
    v |= *buffer++; v <<= 8;
    v |= *buffer;
    return sizeof(sal_uInt32);
}

inline sal_uInt32 writeUtf8(sal_uInt8* buffer, const char* v)
{
    sal_uInt32 size = strlen(v) + 1;

    memcpy(buffer, v, size);

    return size;
}

inline sal_uInt32 readUtf8(const sal_uInt8* buffer, char* v, sal_uInt32 maxSize)
{
    sal_uInt32 size = strlen(reinterpret_cast<const char*>(buffer)) + 1;
    if(size > maxSize)
    {
        size = maxSize;
    }

    memcpy(v, buffer, size);

    if (size == maxSize) v[size - 1] = '\0';

    return size;
}


sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v);
sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize);

sal_uInt32 UINT16StringLen(const sal_uInt8* wstring);

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */