From cdd9c0fdae31bc0f7b12884cce015b79e817367d Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 21 Dec 2016 16:44:35 -0800 Subject: Provide a simple to use implementation of ldid -e. --- ldid.cpp | 28 ++++++++++++++++++++++++++++ ldid.hpp | 1 + 2 files changed, 29 insertions(+) diff --git a/ldid.cpp b/ldid.cpp index 8010211..d7fdf7a 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -982,6 +982,34 @@ class Map { namespace ldid { +std::string Analyze(const void *data, size_t size) { + std::string entitlements; + + FatHeader fat_header(const_cast(data), size); + _foreach (mach_header, fat_header.GetMachHeaders()) + _foreach (load_command, mach_header.GetLoadCommands()) + if (mach_header.Swap(load_command->cmd) == LC_CODE_SIGNATURE) { + auto signature(reinterpret_cast(load_command)); + auto offset(mach_header.Swap(signature->dataoff)); + auto pointer(reinterpret_cast(mach_header.GetBase()) + offset); + auto super(reinterpret_cast(pointer)); + + for (size_t index(0); index != Swap(super->count); ++index) + if (Swap(super->index[index].type) == CSSLOT_ENTITLEMENTS) { + auto begin(Swap(super->index[index].offset)); + auto blob(reinterpret_cast(pointer + begin)); + auto writ(Swap(blob->length) - sizeof(*blob)); + + if (entitlements.empty()) + entitlements.assign(reinterpret_cast(blob + 1), writ); + else + _assert(entitlements.compare(0, entitlements.size(), reinterpret_cast(blob + 1), writ) == 0); + } + } + + return entitlements; +} + static void Allocate(const void *idata, size_t isize, std::streambuf &output, const Functor &allocate, const Functor &save) { FatHeader source(const_cast(idata), isize); diff --git a/ldid.hpp b/ldid.hpp index b603bbd..fbacc86 100644 --- a/ldid.hpp +++ b/ldid.hpp @@ -152,6 +152,7 @@ Bundle Sign(const std::string &root, Folder &folder, const std::string &key, con typedef std::map> Slots; +std::string Analyze(const void *data, size_t size); std::vector Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &requirement, const std::string &key, const Slots &slots); } -- cgit v1.2.3-56-ge451