LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DyldSharedCache/DyldSharedCache.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 Quarkslab
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#ifndef LIEF_DSC_DYLD_SHARED_CACHE_H
17#define LIEF_DSC_DYLD_SHARED_CACHE_H
22#include "LIEF/iterators.hpp"
23#include "LIEF/visibility.h"
24#include <string_view>
25
27
28#include <memory>
29#include <string>
30#include <vector>
31
32namespace LIEF {
33class FileStream;
34
36namespace dsc {
37namespace details {
38class DyldSharedCache;
39}
40
43 public:
46 enum class VERSION : uint32_t {
47 UNKNOWN = 0,
48
49 DYLD_95_3,
50 DYLD_195_5,
51 DYLD_239_3,
52 DYLD_360_14,
53 DYLD_421_1,
54 DYLD_832_7_1,
55 DYLD_940,
56 DYLD_1042_1,
57 DYLD_1231_3,
58 DYLD_1284_13,
59
62 UNRELEASED,
63 };
64
66 enum class DYLD_TARGET_PLATFORM : uint32_t {
67 UNKNOWN = 0,
68 MACOS = 1,
69 IOS = 2,
70 TVOS = 3,
71 WATCHOS = 4,
72 BRIDGEOS = 5,
73 IOSMAC = 6,
74 IOS_SIMULATOR = 7,
75 TVOS_SIMULATOR = 8,
76 WATCHOS_SIMULATOR = 9,
77 DRIVERKIT = 10,
78 VISIONOS = 11,
79 VISIONOS_SIMULATOR = 12,
80 FIRMWARE = 13,
81 SEPOS = 14,
82
83 ANY = 0xFFFFFFFF,
84 };
85
87 enum class DYLD_TARGET_ARCH {
88 UNKNOWN = 0,
89
90 I386,
91
92 X86_64,
93 X86_64H,
94
95 ARMV5,
96 ARMV6,
97 ARMV7,
98
99 ARM64,
100 ARM64E,
101 };
102
105
108
111
113
114 DyldSharedCache(std::unique_ptr<details::DyldSharedCache> impl);
116
118 static std::unique_ptr<DyldSharedCache> from_path(const std::string& path,
119 const std::string& arch = "");
120
122 static std::unique_ptr<DyldSharedCache>
123 from_files(const std::vector<std::string>& path);
124
129 std::string filename() const;
130
133
136 std::string filepath() const;
137
139 uint64_t load_address() const;
140
142 std::string arch_name() const;
143
146
149
152 std::unique_ptr<Dylib> find_lib_from_va(uint64_t va) const LIEF_LIFETIMEBOUND;
153
155 std::unique_ptr<Dylib>
156 find_lib_from_path(std::string_view path) const LIEF_LIFETIMEBOUND;
157
162 std::unique_ptr<Dylib>
163 find_lib_from_name(std::string_view name) const LIEF_LIFETIMEBOUND;
164
166 bool has_subcaches() const;
167
181
195
210
214
216 std::vector<uint8_t> get_content_from_va(uint64_t va, uint64_t size) const;
217
219 std::unique_ptr<DyldSharedCache>
221
224
227 std::unique_ptr<DyldSharedCache>
229
235 result<uint64_t> va_to_offset(uint64_t va) const;
236
239
242
263 void enable_caching(const std::string& target_cache_dir) const;
264
266 void flush_cache() const;
267
268 private:
269 std::unique_ptr<details::DyldSharedCache> impl_;
270};
271
291inline std::unique_ptr<DyldSharedCache> load(const std::string& path,
292 const std::string& arch = "") {
293 return DyldSharedCache::from_path(path, arch);
294}
295
305inline std::unique_ptr<DyldSharedCache>
306 load(const std::vector<std::string>& files) {
307 return DyldSharedCache::from_files(files);
308}
309
310}
311}
312#endif
Stream interface over a std::ifstream.
Definition FileStream.hpp:30
This class represents a dyld shared cache file.
Definition DyldSharedCache/DyldSharedCache.hpp:42
std::string filepath() const
Full path to the original dyld shared cache file associated with object (e.g. /home/lief/downloads/vi...
iterator_range< MappingInfo::Iterator > mapping_info_iterator
Iterator over the mapping info in the shared cache.
Definition DyldSharedCache/DyldSharedCache.hpp:107
std::unique_ptr< Dylib > find_lib_from_name(std::string_view name) const
Find the Dylib whose filename of Dylib::path matches the provided name.
void flush_cache() const
Flush internal information into the on-disk cache (see: enable_caching).
uint64_t load_address() const
Based address of this cache.
iterator_range< assembly::Instruction::Iterator > instructions_iterator
Definition DyldSharedCache/DyldSharedCache.hpp:112
instructions_iterator disassemble(uint64_t va) const
Disassemble instructions at the provided virtual address. This function returns an iterator over asse...
FileStream & stream() const
Return the stream associated with this dyld shared cache.
dylib_iterator libraries() const
Return an iterator over the libraries embedded in this dyld shared cache.
void enable_caching(const std::string &target_cache_dir) const
When enabled, this function records and keeps in cache the dyld shared cache information that is cost...
DyldSharedCache(std::unique_ptr< details::DyldSharedCache > impl)
bool has_subcaches() const
True if the subcaches are associated with this cache.
DYLD_TARGET_ARCH arch() const
Architecture targeted by this cache.
VERSION
This enum wraps the dyld's git tags for which the structure of dyld shared cache evolved.
Definition DyldSharedCache/DyldSharedCache.hpp:46
std::unique_ptr< Dylib > find_lib_from_path(std::string_view path) const
Find the Dylib whose Dylib::path matches the provided path.
iterator_range< Dylib::Iterator > dylib_iterator
Iterator over the libraries in the shared cache.
Definition DyldSharedCache/DyldSharedCache.hpp:104
DYLD_TARGET_PLATFORM platform() const
Platform targeted by this cache (e.g. visionOS).
static std::unique_ptr< DyldSharedCache > from_path(const std::string &path, const std::string &arch="")
See the load functions for the details.
std::unique_ptr< DyldSharedCache > find_subcache(std::string_view filename) const
Try to find the DyldSharedCache associated with the filename given in the first parameter.
std::unique_ptr< DyldSharedCache > cache_for_address(uint64_t va) const
Find the sub-DyldSharedCache that wraps the given virtual address.
std::vector< uint8_t > get_content_from_va(uint64_t va, uint64_t size) const
Return the content at the specified virtual address.
std::string arch_name() const
Name of the architecture targeted by this cache (x86_64h).
DYLD_TARGET_ARCH
Architecture supported by the dyld shared cache.
Definition DyldSharedCache/DyldSharedCache.hpp:87
std::string filename() const
Filename of the dyld shared file associated with this object.
std::unique_ptr< Dylib > find_lib_from_va(uint64_t va) const
Find the Dylib that encompasses the given virtual address. It returns a nullptr if a Dylib can't be f...
mapping_info_iterator mapping_info() const
Return an iterator over the mapping information of this dyld shared cache.
iterator_range< SubCache::Iterator > subcache_iterator
Iterator over the split/sub-cache in this main shared cache.
Definition DyldSharedCache/DyldSharedCache.hpp:110
static std::unique_ptr< DyldSharedCache > from_files(const std::vector< std::string > &path)
See the load functions for the details.
result< uint64_t > va_to_offset(uint64_t va) const
Convert the given virtual address into an offset.
DYLD_TARGET_PLATFORM
Platforms supported by the dyld shared cache.
Definition DyldSharedCache/DyldSharedCache.hpp:66
std::unique_ptr< DyldSharedCache > main_cache() const
Return the principal dyld shared cache in the case of multiple subcaches.
subcache_iterator subcaches() const
Return an iterator over the subcaches associated with this (main) dyld shared cache.
VERSION version() const
Version of dyld used by this cache.
Definition iterators.hpp:681
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DyldSharedCache/DyldSharedCache.hpp:37
Namespace related to the dyld shared cache support.
Definition caching.hpp:22
std::unique_ptr< DyldSharedCache > load(const std::string &path, const std::string &arch="")
Load a shared cache from a single file or from a directory specified by the path parameter.
Definition DyldSharedCache/DyldSharedCache.hpp:291
LIEF namespace.
Definition Abstract/Binary.hpp:42
#define LIEF_API
Definition visibility.h:45