LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
DyldSharedCache/DyldSharedCache.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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
18#include "LIEF/visibility.h"
19#include "LIEF/iterators.hpp"
23
24#include <memory>
25#include <string>
26#include <vector>
27
28namespace LIEF {namespace dsc {
31namespace details {
32class DyldSharedCache;
33}
37 public:
38 enum class VERSION : uint32_t {
42 UNKNOWN = 0,
43
44 DYLD_95_3,
45 DYLD_195_5,
46 DYLD_239_3,
47 DYLD_360_14,
48 DYLD_421_1,
49 DYLD_832_7_1,
50 DYLD_940,
51 DYLD_1042_1,
52 UNRELEASED,
56 };
57 enum class DYLD_TARGET_PLATFORM : uint32_t {
60 UNKNOWN = 0,
61 MACOS = 1,
62 IOS = 2,
63 TVOS = 3,
64 WATCHOS = 4,
65 BRIDGEOS = 5,
66 IOSMAC = 6,
67 IOS_SIMULATOR = 7,
68 TVOS_SIMULATOR = 8,
69 WATCHOS_SIMULATOR = 9,
70 DRIVERKIT = 10,
71 VISIONOS = 11,
72 VISIONOS_SIMULATOR = 12,
73 FIRMWARE = 13,
74 SEPOS = 14,
75
76 ANY = 0xFFFFFFFF
77 };
78 enum class DYLD_TARGET_ARCH {
81 UNKNOWN = 0,
82
83 I386,
84
85 X86_64,
86 X86_64H,
87
88 ARMV5,
89 ARMV6,
90 ARMV7,
91
92 ARM64,
93 ARM64E,
94 };
95 using dylib_iterator = iterator_range<Dylib::Iterator>;
98 using mapping_info_iterator = iterator_range<MappingInfo::Iterator>;
101 using subcache_iterator = iterator_range<SubCache::Iterator>;
104
105 DyldSharedCache(std::unique_ptr<details::DyldSharedCache> impl);
106 ~DyldSharedCache();
107 static std::unique_ptr<DyldSharedCache> from_path(const std::string& path,
110 const std::string& arch = "");
111 static std::unique_ptr<DyldSharedCache> from_files(const std::vector<std::string>& path);
114 std::string filename() const;
119 VERSION version() const;
122 std::string filepath() const;
126 uint64_t load_address() const;
129 std::string arch_name() const;
132 DYLD_TARGET_PLATFORM platform() const;
135 DYLD_TARGET_ARCH arch() const;
138 std::unique_ptr<Dylib> find_lib_from_va(uint64_t va) const;
142 std::unique_ptr<Dylib> find_lib_from_path(const std::string& path) const;
145 std::unique_ptr<Dylib> find_lib_from_name(const std::string& name) const;
151 bool has_subcaches() const;
154 dylib_iterator libraries() const;
168 mapping_info_iterator mapping_info() const;
182 subcache_iterator subcaches() const;
197 void enable_caching(const std::string& target_cache_dir) const;
218 void flush_cache() const;
221
222 private:
223 std::unique_ptr<details::DyldSharedCache> impl_;
224};
225inline std::unique_ptr<DyldSharedCache> load(const std::string& path,
246 const std::string& arch = "")
247{
248 return DyldSharedCache::from_path(path, arch);
249}
250inline std::unique_ptr<DyldSharedCache> load(const std::vector<std::string>& files)
261{
262 return DyldSharedCache::from_files(files);
263}
264
265}
266}
267#endif
268
269
Dylib.hpp
MappingInfo.hpp
SubCache.hpp
LIEF::dsc::DyldSharedCache
This class represents a dyld shared cache file.
Definition DyldSharedCache/DyldSharedCache.hpp:36
LIEF::dsc::DyldSharedCache::filepath
std::string filepath() const
Full path to the original dyld shared cache file associated with object (e.g. /home/lief/downloads/vi...
LIEF::dsc::DyldSharedCache::flush_cache
void flush_cache() const
Flush internal information into the on-disk cache (see: enable_caching)
LIEF::dsc::DyldSharedCache::load_address
uint64_t load_address() const
Based address of this cache.
LIEF::dsc::DyldSharedCache::libraries
dylib_iterator libraries() const
Return an interator over the libraries embedded in this dyld shared cache.
LIEF::dsc::DyldSharedCache::enable_caching
void enable_caching(const std::string &target_cache_dir) const
When enabled, this function allows to record and to keep in cache, dyld shared cache information that...
LIEF::dsc::DyldSharedCache::~DyldSharedCache
~DyldSharedCache()
LIEF::dsc::DyldSharedCache::DyldSharedCache
DyldSharedCache(std::unique_ptr< details::DyldSharedCache > impl)
LIEF::dsc::DyldSharedCache::has_subcaches
bool has_subcaches() const
True if the subcaches are associated with this cache.
LIEF::dsc::DyldSharedCache::arch
DYLD_TARGET_ARCH arch() const
Architecture targeted by this cache.
LIEF::dsc::DyldSharedCache::platform
DYLD_TARGET_PLATFORM platform() const
Platform targeted by this cache (e.g. vision-os)
LIEF::dsc::DyldSharedCache::find_lib_from_path
std::unique_ptr< Dylib > find_lib_from_path(const std::string &path) const
Find the Dylib whose Dylib::path matches the provided path.
LIEF::dsc::DyldSharedCache::from_path
static std::unique_ptr< DyldSharedCache > from_path(const std::string &path, const std::string &arch="")
See the load functions for the details.
LIEF::dsc::DyldSharedCache::find_lib_from_name
std::unique_ptr< Dylib > find_lib_from_name(const std::string &name) const
Find the Dylib whose filename of Dylib::path matches the provided name.
LIEF::dsc::DyldSharedCache::arch_name
std::string arch_name() const
Name of the architecture targeted by this cache (x86_64h)
LIEF::dsc::DyldSharedCache::filename
std::string filename() const
Filename of the dyld shared file associated with this object.
LIEF::dsc::DyldSharedCache::find_lib_from_va
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...
LIEF::dsc::DyldSharedCache::mapping_info
mapping_info_iterator mapping_info() const
Return an interator over the mapping information of this dyld shared cache.
LIEF::dsc::DyldSharedCache::from_files
static std::unique_ptr< DyldSharedCache > from_files(const std::vector< std::string > &path)
See the load functions for the details.
LIEF::dsc::DyldSharedCache::subcaches
subcache_iterator subcaches() const
Return an interator over the subcaches associated with this (main) dyld shared cache.
LIEF::dsc::DyldSharedCache::version
VERSION version() const
Version of dyld used by this cache.
iterators.hpp
LIEF::dsc::details
Definition DyldSharedCache/DyldSharedCache.hpp:31
LIEF::dsc
Namespace related to the dyld shared cache support.
Definition caching.hpp:22
LIEF::dsc::load
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:245
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:32
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41