OLD | NEW |
| (Empty) |
1 // Copyright 2010 Google, Inc. All Rights reserved | |
2 // | |
3 // Redistribution and use in source and binary forms, with or without | |
4 // modification, are permitted provided that the following conditions are | |
5 // met: | |
6 // | |
7 // * Redistributions of source code must retain the above copyright | |
8 // notice, this list of conditions and the following disclaimer. | |
9 // * Redistributions in binary form must reproduce the above | |
10 // copyright notice, this list of conditions and the following disclaimer | |
11 // in the documentation and/or other materials provided with the | |
12 // distribution. | |
13 // * Neither the name of Google Inc. nor the names of its | |
14 // contributors may be used to endorse or promote products derived from | |
15 // this software without specific prior written permission. | |
16 // | |
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | |
29 | |
30 // This file contains the interface for processing ELF Data | |
31 | |
32 #ifndef ELF_READER_ELF_READER_H_ | |
33 #define ELF_READER_ELF_READER_H_ | |
34 | |
35 #include "common/types.h" | |
36 | |
37 namespace elf_reader { | |
38 | |
39 | |
40 // | |
41 // Pure interface class for an ElfReader. | |
42 // | |
43 class IElfReader { | |
44 public: | |
45 // Called at the beginning of processing, with basic information | |
46 // about the ELF file being processed. | |
47 virtual void Header(const char *path, void *data, uint64_t length, | |
48 uint32_t classSize, bool lsb) = 0; | |
49 | |
50 // These functions are called when processing sections headers. The | |
51 // SectionHeaderStart function must return true for this data to | |
52 // be processed. | |
53 virtual bool SectionHeadersStart(uint32_t count) = 0; | |
54 virtual void SectionHeadersEnd() = 0; | |
55 virtual void SectionHeader(const char *name, void *data, uint64_t virt, | |
56 uint32_t type, uint32_t flags, uint64_t size)=0; | |
57 | |
58 // These functions are called when processing program headers. The | |
59 // ProgramHeaderStart function must return true for this data to | |
60 // be processed. | |
61 virtual bool ProgramHeadersStart(uint32_t count) = 0; | |
62 virtual void ProgramHeadersEnd() = 0; | |
63 virtual void ProgramHeader(uint32_t type, uint32_t flags, uint64_t offset, | |
64 uint64_t virt, uint64_t fsize, uint64_t msize)=0; | |
65 }; | |
66 | |
67 | |
68 // | |
69 // Base class does nothing so that the user can choose to reimplement | |
70 // only those pieces which are needed | |
71 // | |
72 class ElfReaderBase : public IElfReader { | |
73 public: | |
74 int foo(); | |
75 | |
76 virtual ~ElfReaderBase() {}; | |
77 | |
78 int bar(); | |
79 | |
80 // Called at the beginning of processing, with basic information | |
81 // about the ELF file being processed. | |
82 void Header(const char *path, void *data, uint64_t length, | |
83 uint32_t classSize, bool lsb) { }; | |
84 | |
85 // These functions are called when processing sections headers. The | |
86 // SectionHeaderStart function must return true for this data to | |
87 // be processed. | |
88 bool SectionHeadersStart(uint32_t count) { return false; } | |
89 void SectionHeadersEnd() {}; | |
90 void SectionHeader(const char *name, void *data, uint64_t virt, | |
91 uint32_t type, uint32_t flags, uint64_t size) {}; | |
92 | |
93 // These functions are called when processing sections headers. The | |
94 // ProgramHeaderStart function must return true for this data to | |
95 // be processed. | |
96 bool ProgramHeadersStart(uint32_t count) { return false; } | |
97 void ProgramHeadersEnd() { }; | |
98 void ProgramHeader(uint32_t type, uint32_t flags, uint64_t offset, | |
99 uint64_t virt, uint64_t fsize, uint64_t msize) {}; | |
100 | |
101 }; | |
102 | |
103 } // namespace elf_reader | |
104 | |
105 #endif // ELF_READER_ELF_READER_H_ | |
106 | |
OLD | NEW |