1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_PDB_PDB_STREAM_RECORD_H_
16 : #define SYZYGY_PDB_PDB_STREAM_RECORD_H_
17 :
18 : #include <cstdint>
19 :
20 : #include "base/logging.h"
21 : #include "base/strings/string16.h"
22 : #include "syzygy/common/assertions.h"
23 : #include "syzygy/common/binary_stream.h"
24 :
25 : namespace pdb {
26 :
27 : class NumericConstant {
28 : public:
29 : enum Kind { CONSTANT_UNINITIALIZED, CONSTANT_UNSIGNED, CONSTANT_SIGNED };
30 :
31 : NumericConstant();
32 :
33 : // Acc
34 E : Kind kind() const { return kind_; }
35 E : uint64_t unsigned_value() const { return unsigned_value_; }
36 E : int64_t signed_value() const { return signed_value_; }
37 :
38 : // We need the function to set this constant for us.
39 : friend bool ReadNumericConstant(common::BinaryStreamParser* parser,
40 : NumericConstant* constant);
41 :
42 : private:
43 : union {
44 : uint64_t unsigned_value_;
45 : uint64_t signed_value_;
46 : };
47 :
48 : Kind kind_;
49 : };
50 :
51 : // Reads string from pdb stream and converts it into a wide string.
52 : // @param parser a pointer to the stream to parse.
53 : // @param string_field pointer to the wide string object.
54 : // @returns true on success, false on failure.
55 : bool ReadWideString(common::BinaryStreamParser* parser,
56 : base::string16* string_field);
57 :
58 : // Reads unsigned numeric leaf from pdb stream and stores it as 64-bit unsigned.
59 : // @param stream a pointer to the pdb stream.
60 : // @param data_field pointer to the numeric leaf object.
61 : // @returns true on success, false on failure.
62 : bool ReadUnsignedNumeric(common::BinaryStreamParser* parser,
63 : uint64_t* data_field);
64 :
65 : // Reads unsigned numeric leaf from pdb stream and stores it as 64-bit unsigned.
66 : // @param stream a pointer to the pdb stream.
67 : // @param constant pointer to the numeric constant object.
68 : // @returns true on success, false on failure.
69 : bool ReadNumericConstant(common::BinaryStreamParser* parser,
70 : NumericConstant* constant);
71 :
72 : // Reads basic type from pdb stream.
73 : // @param parser the pdb data to parse.
74 : // @param basic_type a pointer to the destination object.
75 : // @returns true on success, false on failure.
76 : template <typename T>
77 E : bool ReadBasicType(common::BinaryStreamParser* parser, T* basic_type) {
78 : COMPILE_ASSERT_IS_POD(T);
79 E : DCHECK_NE(static_cast<common::BinaryStreamParser*>(nullptr), parser);
80 E : DCHECK_NE(static_cast<T*>(nullptr), basic_type);
81 :
82 E : return parser->Read(basic_type);
83 E : }
84 :
85 : } // namespace pdb
86 :
87 : #endif // SYZYGY_PDB_PDB_STREAM_RECORD_H_
|