#ifndef DyldSharedCache_h
#define DyldSharedCache_h
#include <set>
#include <string>
#include <vector>
#include <unordered_map>
#include "dyld_cache_format.h"
#include "Diagnostics.h"
#include "MachOParser.h"
namespace dyld3 {
namespace launch_cache {
namespace binary_format {
struct Closure;
struct ImageGroup;
struct Image;
}
}
}
class VIS_HIDDEN DyldSharedCache
{
public:
enum CodeSigningDigestMode
{
SHA256only = 0,
SHA1only = 1,
Agile = 2
};
struct CreateOptions
{
std::string archName;
dyld3::Platform platform;
bool excludeLocalSymbols;
bool optimizeStubs;
bool optimizeObjC;
CodeSigningDigestMode codeSigningDigestMode;
bool agileSignatureChooseSHA256CdHash;
bool dylibsRemovedDuringMastering;
bool inodesAreSameAsRuntime;
bool cacheSupportsASLR;
bool forSimulator;
bool verbose;
bool evictLeafDylibsOnOverflow;
std::unordered_map<std::string, unsigned> dylibOrdering;
std::unordered_map<std::string, unsigned> dirtyDataSegmentOrdering;
std::vector<std::string> pathPrefixes;
std::string loggingPrefix;
};
struct MappedMachO
{
MappedMachO()
: mh(nullptr), length(0), isSetUID(false), protectedBySIP(false), sliceFileOffset(0), modTime(0), inode(0) { }
MappedMachO(const std::string& path, const mach_header* p, size_t l, bool isu, bool sip, uint64_t o, uint64_t m, uint64_t i)
: runtimePath(path), mh(p), length(l), isSetUID(isu), protectedBySIP(sip), sliceFileOffset(o), modTime(m), inode(i) { }
std::string runtimePath;
const mach_header* mh;
size_t length;
uint64_t isSetUID : 1,
protectedBySIP : 1,
sliceFileOffset : 62;
uint64_t modTime; uint64_t inode; };
struct CreateResults
{
const DyldSharedCache* cacheContent = nullptr; size_t cacheLength = 0;
std::string errorMessage;
std::set<std::string> warnings;
std::set<const mach_header*> evictions;
bool agileSignature = false;
std::string cdHashFirst;
std::string cdHashSecond;
};
static bool verifySelfContained(std::vector<MappedMachO>& dylibsToCache, MappedMachO (^loader)(const std::string& runtimePath), std::vector<std::pair<DyldSharedCache::MappedMachO, std::set<std::string>>>& excluded);
static CreateResults create(const CreateOptions& options,
const std::vector<MappedMachO>& dylibsToCache,
const std::vector<MappedMachO>& otherOsDylibs,
const std::vector<MappedMachO>& osExecutables);
std::string mapFile() const;
std::string archName() const;
uint32_t platform() const;
void forEachImage(void (^handler)(const mach_header* mh, const char* installName)) const;
void forEachImageEntry(void (^handler)(const char* path, uint64_t mTime, uint64_t inode)) const;
void forEachImageTextSegment(void (^handler)(uint64_t loadAddressUnslid, uint64_t textSegmentSize, const uuid_t dylibUUID, const char* installName)) const;
void forEachRegion(void (^handler)(const void* content, uint64_t vmAddr, uint64_t size, uint32_t permissions)) const;
uint64_t unslidLoadAddress() const;
void getUUID(uuid_t uuid) const;
uint64_t mappedSize() const;
dyld_cache_header header;
};
#endif