| Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2017 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef AAPT_FORMAT_CONTAINER_H | 
|  | 18 | #define AAPT_FORMAT_CONTAINER_H | 
|  | 19 |  | 
|  | 20 | #include <inttypes.h> | 
|  | 21 |  | 
| Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 22 | #include "Resources.pb.h" | 
|  | 23 | #include "ResourcesInternal.pb.h" | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 24 | #include "androidfw/BigBuffer.h" | 
| Jeremy Meyer | b4f83ff | 2023-11-30 19:29:50 +0000 | [diff] [blame] | 25 | #include "androidfw/Streams.h" | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 26 | #include "google/protobuf/io/coded_stream.h" | 
|  | 27 | #include "google/protobuf/io/zero_copy_stream.h" | 
| Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 28 | #include "io/Util.h" | 
| Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 29 |  | 
|  | 30 | namespace aapt { | 
|  | 31 |  | 
|  | 32 | enum ContainerEntryType : uint8_t { | 
|  | 33 | kResTable = 0x00u, | 
|  | 34 | kResFile = 0x01u, | 
|  | 35 | }; | 
|  | 36 |  | 
|  | 37 | class ContainerWriter { | 
|  | 38 | public: | 
|  | 39 | explicit ContainerWriter(::google::protobuf::io::ZeroCopyOutputStream* out, size_t entry_count); | 
|  | 40 |  | 
|  | 41 | bool AddResTableEntry(const pb::ResourceTable& table); | 
| Jeremy Meyer | b4f83ff | 2023-11-30 19:29:50 +0000 | [diff] [blame] | 42 | bool AddResFileEntry(const pb::internal::CompiledFile& file, android::KnownSizeInputStream* in); | 
| Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 43 | bool HadError() const; | 
|  | 44 | std::string GetError() const; | 
|  | 45 |  | 
|  | 46 | private: | 
|  | 47 | DISALLOW_COPY_AND_ASSIGN(ContainerWriter); | 
|  | 48 |  | 
|  | 49 | ::google::protobuf::io::ZeroCopyOutputStream* out_; | 
|  | 50 | size_t total_entry_count_; | 
|  | 51 | size_t current_entry_count_; | 
|  | 52 | std::string error_; | 
|  | 53 | }; | 
|  | 54 |  | 
|  | 55 | class ContainerReader; | 
|  | 56 |  | 
|  | 57 | class ContainerReaderEntry { | 
|  | 58 | public: | 
|  | 59 | ContainerEntryType Type() const; | 
|  | 60 |  | 
|  | 61 | bool GetResTable(pb::ResourceTable* out_table); | 
|  | 62 | bool GetResFileOffsets(pb::internal::CompiledFile* out_file, off64_t* out_offset, | 
|  | 63 | size_t* out_len); | 
|  | 64 |  | 
|  | 65 | bool HadError() const; | 
|  | 66 | std::string GetError() const; | 
|  | 67 |  | 
|  | 68 | private: | 
|  | 69 | DISALLOW_COPY_AND_ASSIGN(ContainerReaderEntry); | 
|  | 70 |  | 
|  | 71 | friend class ContainerReader; | 
|  | 72 |  | 
|  | 73 | explicit ContainerReaderEntry(ContainerReader* reader); | 
|  | 74 |  | 
|  | 75 | ContainerReader* reader_; | 
|  | 76 | ContainerEntryType type_ = ContainerEntryType::kResTable; | 
|  | 77 | size_t length_ = 0u; | 
|  | 78 | }; | 
|  | 79 |  | 
|  | 80 | class ContainerReader { | 
|  | 81 | public: | 
| Jeremy Meyer | b4f83ff | 2023-11-30 19:29:50 +0000 | [diff] [blame] | 82 | explicit ContainerReader(android::InputStream* in); | 
| Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 83 |  | 
|  | 84 | ContainerReaderEntry* Next(); | 
|  | 85 |  | 
|  | 86 | bool HadError() const; | 
|  | 87 | std::string GetError() const; | 
|  | 88 |  | 
|  | 89 | private: | 
|  | 90 | DISALLOW_COPY_AND_ASSIGN(ContainerReader); | 
|  | 91 |  | 
|  | 92 | friend class ContainerReaderEntry; | 
|  | 93 |  | 
| Jeremy Meyer | b4f83ff | 2023-11-30 19:29:50 +0000 | [diff] [blame] | 94 | android::InputStream* in_; | 
| Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 95 | io::ZeroCopyInputAdaptor adaptor_; | 
|  | 96 | ::google::protobuf::io::CodedInputStream coded_in_; | 
|  | 97 | size_t total_entry_count_; | 
|  | 98 | size_t current_entry_count_; | 
|  | 99 | ContainerReaderEntry entry_; | 
|  | 100 | std::string error_; | 
|  | 101 | }; | 
|  | 102 |  | 
|  | 103 | }  // namespace aapt | 
|  | 104 |  | 
|  | 105 | #endif /* AAPT_FORMAT_CONTAINER_H */ |