LIEF: Library to Instrument Executable Formats Version 0.16.2
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
25
26#include <memory>
27#include <string>
28#include <vector>
29
30namespace LIEF {
31class FileStream;
32namespace dsc {
35namespace details {
36class DyldSharedCache;
37}
41 public:
42 enum class VERSION : uint32_t {
46 UNKNOWN = 0,
47
48 DYLD_95_3,
49 DYLD_195_5,
50 DYLD_239_3,
51 DYLD_360_14,
52 DYLD_421_1,
53 DYLD_832_7_1,
54 DYLD_940,
55 DYLD_1042_1,
56 UNRELEASED,
60 };
61 enum class DYLD_TARGET_PLATFORM : uint32_t {
64 UNKNOWN = 0,
65 MACOS = 1,
66 IOS = 2,
67 TVOS = 3,
68 WATCHOS = 4,
69 BRIDGEOS = 5,
70 IOSMAC = 6,
71 IOS_SIMULATOR = 7,
72 TVOS_SIMULATOR = 8,
73 WATCHOS_SIMULATOR = 9,
74 DRIVERKIT = 10,
75 VISIONOS = 11,
76 VISIONOS_SIMULATOR = 12,
77 FIRMWARE = 13,
78 SEPOS = 14,
79
80 ANY = 0xFFFFFFFF
81 };
82 enum class DYLD_TARGET_ARCH {
85 UNKNOWN = 0,
86
87 I386,
88
89 X86_64,
90 X86_64H,
91
92 ARMV5,
93 ARMV6,
94 ARMV7,
95
96 ARM64,
97 ARM64E,
98 };
99 using dylib_iterator = iterator_range<Dylib::Iterator>;
102 using mapping_info_iterator = iterator_range<MappingInfo::Iterator>;
105 using subcache_iterator = iterator_range<SubCache::Iterator>;
108
109 using instructions_iterator = iterator_range<assembly::Instruction::Iterator>;
110
111 DyldSharedCache(std::unique_ptr<details::DyldSharedCache> impl);
112 ~DyldSharedCache();
113 static std::unique_ptr<DyldSharedCache> from_path(const std::string& path,
116 const std::string& arch = "");
117 static std::unique_ptr<DyldSharedCache> from_files(const std::vector<std::string>& path);
120 std::string filename() const;
125 VERSION version() const;
128 std::string filepath() const;
132 uint64_t load_address() const;
135 std::string arch_name() const;
138 DYLD_TARGET_PLATFORM platform() const;
141 DYLD_TARGET_ARCH arch() const;
144 std::unique_ptr<Dylib> find_lib_from_va(uint64_t va) const;
148 std::unique_ptr<Dylib> find_lib_from_path(const std::string& path) const;
151 std::unique_ptr<Dylib> find_lib_from_name(const std::string& name) const;
157 bool has_subcaches() const;
160 dylib_iterator libraries() const;
174 mapping_info_iterator mapping_info() const;
188 subcache_iterator subcaches() const;
203 instructions_iterator disassemble(uint64_t va) const;
207 std::vector<uint8_t> get_content_from_va(uint64_t va, uint64_t size) const;
210 std::unique_ptr<DyldSharedCache> cache_for_address(uint64_t va) const;
213 std::unique_ptr<DyldSharedCache> main_cache() const;
216 std::unique_ptr<DyldSharedCache> find_subcache(const std::string& filename) const;
220 result<uint64_t> va_to_offset(uint64_t va) const;
227 FileStream& stream() const;
230 FileStream& stream();
233 void enable_caching(const std::string& target_cache_dir) const;
254 void flush_cache() const;
257
258 private:
259 std::unique_ptr<details::DyldSharedCache> impl_;
260};
261inline std::unique_ptr<DyldSharedCache> load(const std::string& path,
282 const std::string& arch = "")
283{
284 return DyldSharedCache::from_path(path, arch);
285}
286inline std::unique_ptr<DyldSharedCache> load(const std::vector<std::string>& files)
297{
298 return DyldSharedCache::from_files(files);
299}
300
301}
302}
303#endif
304
305
Dylib.hpp
Instruction.hpp
MappingInfo.hpp
SubCache.hpp
LIEF::FileStream
Stream interface over a std::ifstream
Definition FileStream.hpp:30
LIEF::dsc::DyldSharedCache
This class represents a dyld shared cache file.
Definition DyldSharedCache/DyldSharedCache.hpp:40
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::disassemble
instructions_iterator disassemble(uint64_t va) const
Disassemble instructions at the provided virtual address. This function returns an iterator over asse...
LIEF::dsc::DyldSharedCache::stream
FileStream & stream() const
Return the stream associated with this dyld shared cache.
LIEF::dsc::DyldSharedCache::stream
FileStream & stream()
Return the stream associated with this dyld shared 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::cache_for_address
std::unique_ptr< DyldSharedCache > cache_for_address(uint64_t va) const
Find the sub-DyldSharedCache that wraps the given virtual address.
LIEF::dsc::DyldSharedCache::get_content_from_va
std::vector< uint8_t > get_content_from_va(uint64_t va, uint64_t size) const
Return the content at the specified virtual address.
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::find_subcache
std::unique_ptr< DyldSharedCache > find_subcache(const std::string &filename) const
Try to find the DyldSharedCache associated with the filename given in the first parameter.
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::va_to_offset
result< uint64_t > va_to_offset(uint64_t va) const
Convert the given virtual address into an offset.
LIEF::dsc::DyldSharedCache::main_cache
std::unique_ptr< DyldSharedCache > main_cache() const
Return the principal dyld shared cache in the case of multiple subcaches.
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:35
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:281
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41