LLVM  4.0.0
Decompressor.h
Go to the documentation of this file.
1 //===-- Decompressor.h ------------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===/
9 
10 #ifndef LLVM_OBJECT_DECOMPRESSOR_H
11 #define LLVM_OBJECT_DECOMPRESSOR_H
12 
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/Object/ObjectFile.h"
16 
17 namespace llvm {
18 namespace object {
19 
20 /// @brief Decompressor helps to handle decompression of compressed sections.
21 class Decompressor {
22 public:
23  /// @brief Create decompressor object.
24  /// @param Name Section name.
25  /// @param Data Section content.
26  /// @param IsLE Flag determines if Data is in little endian form.
27  /// @param Is64Bit Flag determines if object is 64 bit.
29  bool IsLE, bool Is64Bit);
30 
31  /// @brief Resize the buffer and uncompress section data into it.
32  /// @param Out Destination buffer.
34 
35  /// @brief Uncompress section data to raw buffer provided.
36  /// @param Buffer Destination buffer.
38 
39  /// @brief Return memory buffer size required for decompression.
40  uint64_t getDecompressedSize() { return DecompressedSize; }
41 
42  /// @brief Return true if section is compressed, including gnu-styled case.
43  static bool isCompressed(const object::SectionRef &Section);
44 
45  /// @brief Return true if section is a ELF compressed one.
46  static bool isCompressedELFSection(uint64_t Flags, StringRef Name);
47 
48  /// @brief Return true if section name matches gnu style compressed one.
49  static bool isGnuStyle(StringRef Name);
50 
51 private:
52  Decompressor(StringRef Data);
53 
54  Error consumeCompressedGnuHeader();
55  Error consumeCompressedZLibHeader(bool Is64Bit, bool IsLittleEndian);
56 
57  StringRef SectionData;
58  uint64_t DecompressedSize;
59 };
60 
61 } // end namespace object
62 } // end namespace llvm
63 
64 #endif // LLVM_OBJECT_DECOMPRESSOR_H
static bool isCompressed(const object::SectionRef &Section)
Return true if section is compressed, including gnu-styled case.
static bool isGnuStyle(StringRef Name)
Return true if section name matches gnu style compressed one.
Error decompress(SmallString< 32 > &Out)
Resize the buffer and uncompress section data into it.
Decompressor helps to handle decompression of compressed sections.
Definition: Decompressor.h:21
struct fuzzer::@269 Flags
uint64_t getDecompressedSize()
Return memory buffer size required for decompression.
Definition: Decompressor.h:40
Tagged union holding either a T or a Error.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:283
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
static bool isCompressedELFSection(uint64_t Flags, StringRef Name)
Return true if section is a ELF compressed one.
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:70
static Expected< Decompressor > create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit)
Create decompressor object.