• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
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 SIGNATRUETOOLS_NATIVE_LIB_INFO_SEGMENT_H
16 #define SIGNATRUETOOLS_NATIVE_LIB_INFO_SEGMENT_H
17 
18 #include <vector>
19 #include <string>
20 
21 #include "sign_info.h"
22 #include "signed_file_pos.h"
23 #include "signature_tools_log.h"
24 
25 namespace OHOS {
26 namespace SignatureTools {
27 
28 class NativeLibInfoSegment {
29 public:
30     static const int32_t MAGIC_LENGTH_SECNUM_BYTES = 12;
31     static const int32_t SIGNED_FILE_POS_SIZE = 16;
32     static const int32_t MAGIC_NUM = (0x0ED2 << 16) + 0xE720;
33     static const int32_t ALIGNMENT_FOR_SIGNINFO = 4;
34     NativeLibInfoSegment();
35     NativeLibInfoSegment(int32_t magic,
36                          int32_t segmentSize,
37                          int32_t sectionNum,
38                          const std::vector<SignedFilePos>& signedFilePosList,
39                          const std::vector<std::string>& fileNameList,
40                          const std::vector<SignInfo>& signInfoList,
41                          const std::vector<int8_t>& zeroPadding);
42     static NativeLibInfoSegment FromByteArray(std::vector<int8_t>& bytes);
43     void SetSoInfoList(const std::vector<std::pair<std::string, SignInfo>>& soInfoList);
44     int32_t GetSectionNum();
45     std::vector<std::string>& GetFileNameList();
46     std::vector<SignInfo>& GetSignInfoList();
47     int32_t Size();
48     void ToByteArray(std::vector<int8_t> &ret);
49 
50 private:
51     static bool CheckBuffer(ByteBuffer* bf, int32_t& inMagic,
52         int32_t& inSegmentSize, int32_t& inSectionNum);
53     void GenerateList();
54     int32_t magic;
55     int32_t segmentSize;
56     int32_t sectionNum;
57     std::vector<std::pair<std::string, SignInfo>> soInfoList;
58     std::vector<SignedFilePos> signedFilePosList;
59     std::vector<std::string> fileNameList;
60     std::vector<SignInfo> signInfoList;
61     std::vector<int8_t> zeroPadding;
62     int32_t fileNameListBlockSize;
63     int32_t signInfoListBlockSize;
64 };
65 } // namespace SignatureTools
66 } // namespace OHOS
67 #endif // SIGNATRUETOOLS_NATIVE_LIB_INFO_SEGMENT_H
68