• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
16 #ifndef LIBPANDAFILE_MODULE_DATA_ACCESSOR_INL_H
17 #define LIBPANDAFILE_MODULE_DATA_ACCESSOR_INL_H
18 
19 #include "module_data_accessor.h"
20 #include "file_items.h"
21 #include "helpers.h"
22 
23 namespace panda::panda_file {
24 template <class Callback>
EnumerateModuleRecord(const Callback & cb)25 inline void ModuleDataAccessor::EnumerateModuleRecord(const Callback &cb)
26 {
27     auto sp = entry_data_sp_;
28 
29     auto regular_import_num = panda_file::helpers::Read<panda_file::ID_SIZE>(&sp);
30     for (size_t idx = 0; idx < regular_import_num; idx++) {
31         auto local_name_offset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
32         auto import_name_offset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
33         auto module_request_idx = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint16_t)>(&sp));
34         cb(ModuleTag::REGULAR_IMPORT, 0, module_request_idx, import_name_offset, local_name_offset);
35     }
36 
37     auto namespace_import_num = panda_file::helpers::Read<panda_file::ID_SIZE>(&sp);
38     for (size_t idx = 0; idx < namespace_import_num; idx++) {
39         auto local_name_offset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
40         auto module_request_idx = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint16_t)>(&sp));
41         cb(ModuleTag::NAMESPACE_IMPORT, 0, module_request_idx, 0, local_name_offset);
42     }
43 
44     auto local_export_num = panda_file::helpers::Read<panda_file::ID_SIZE>(&sp);
45     for (size_t idx = 0; idx < local_export_num; idx++) {
46         auto local_name_offset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
47         auto export_name_offset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
48         cb(ModuleTag::LOCAL_EXPORT, export_name_offset, 0, 0, local_name_offset);
49     }
50 
51     auto indirect_export_num = panda_file::helpers::Read<panda_file::ID_SIZE>(&sp);
52     for (size_t idx = 0; idx < indirect_export_num; idx++) {
53         auto export_name_offset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
54         auto import_name_offset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
55         auto module_request_idx = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint16_t)>(&sp));
56         cb(ModuleTag::INDIRECT_EXPORT, export_name_offset, module_request_idx, import_name_offset, 0);
57     }
58 
59     auto starExportNum = panda_file::helpers::Read<panda_file::ID_SIZE>(&sp);
60     for (size_t idx = 0; idx < starExportNum; idx++) {
61         auto module_request_idx = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint16_t)>(&sp));
62         cb(ModuleTag::STAR_EXPORT, 0, module_request_idx, 0, 0);
63     }
64 }
65 }  // namespace panda::panda_file
66 
67 #endif  // LIBPANDAFILE_MODULE_DATA_ACCESSOR_INL_H