1 /*
2  * Copyright (C) 2018 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 IDMAP2_INCLUDE_IDMAP2_RAWPRINTVISITOR_H_
18 #define IDMAP2_INCLUDE_IDMAP2_RAWPRINTVISITOR_H_
19 
20 #include <iostream>
21 #include <memory>
22 #include <string>
23 
24 #include "androidfw/AssetManager2.h"
25 #include "idmap2/Idmap.h"
26 
27 namespace android {
28 
29 class ApkAssets;
30 
31 namespace idmap2 {
32 
33 class RawPrintVisitor : public Visitor {
34  public:
RawPrintVisitor(std::ostream & stream)35   explicit RawPrintVisitor(std::ostream& stream) : stream_(stream), offset_(0) {
36   }
37   ~RawPrintVisitor() override = default;
38   void visit(const Idmap& idmap) override;
39   void visit(const IdmapHeader& header) override;
40   void visit(const IdmapData& data) override;
41   void visit(const IdmapData::Header& header) override;
42 
43  private:
44   void print(uint8_t value, const char* fmt, ...);
45   void print(uint16_t value, const char* fmt, ...);
46   void print(uint32_t value, const char* fmt, ...);
47   void print(const std::string& value, size_t encoded_size, const char* fmt, ...);
48   void print_raw(uint32_t length, const char* fmt, ...);
49 
50   std::ostream& stream_;
51   std::unique_ptr<const ApkAssets> target_apk_;
52   std::unique_ptr<const ApkAssets> overlay_apk_;
53   AssetManager2 target_am_;
54   AssetManager2 overlay_am_;
55   size_t offset_;
56 };
57 
58 }  // namespace idmap2
59 }  // namespace android
60 
61 #endif  // IDMAP2_INCLUDE_IDMAP2_RAWPRINTVISITOR_H_
62