From 9b693b3477abaa13b2915411a8ba77f77fe67c25 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 6 Feb 2017 06:48:38 -0800 Subject: Support separate provisioning for bundled plugins. --- ldid.cpp | 23 ++++++++++++++++++----- ldid.hpp | 3 +-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ldid.cpp b/ldid.cpp index fa21a15..1eacfb7 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -2061,7 +2061,7 @@ static std::vector Sign(const uint8_t *prefix, size_t size, std::streambuf return Sign(data.data(), data.size(), proxy, identifier, entitlements, requirement, key, slots); } -Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std::map &remote, const std::string &entitlements, const std::string &requirement) { +Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std::map &remote, const std::string &requirement, const Functor &alter) { std::string executable; std::string identifier; @@ -2085,6 +2085,17 @@ Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std mac = true; } + std::string entitlements; + folder.Open(executable, fun([&](std::streambuf &buffer, const void *flag) { + // XXX: this is a miserable fail + std::stringbuf temp; + auto size(copy(buffer, temp)); + // XXX: this is a stupid hack + pad(temp, 0x10 - (size & 0xf)); + auto data(temp.str()); + entitlements = alter(root, Analyze(data.data(), data.size())); + })); + static const std::string directory("_CodeSignature/"); static const std::string signature(directory + "CodeResources"); @@ -2133,7 +2144,9 @@ Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std auto bundle(root + Split(name).dir); bundle.resize(bundle.size() - resources.size()); SubFolder subfolder(folder, bundle); - bundles[nested[1]] = Sign(bundle, subfolder, key, local, "", ""); + + bundles[nested[1]] = Sign(bundle, subfolder, key, local, "", Starts(name, "PlugIns/") ? alter : + static_cast &>(fun([&](const std::string &, const std::string &entitlements) -> std::string { return entitlements; }))); }), fun([&](const std::string &name, const Functor &read) { })); @@ -2320,9 +2333,9 @@ Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std return bundle; } -Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &entitlements, const std::string &requirement) { +Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &requirement, const Functor &alter) { std::map local; - return Sign(root, folder, key, local, entitlements, requirement); + return Sign(root, folder, key, local, requirement, alter); } #endif @@ -2499,7 +2512,7 @@ int main(int argc, char *argv[]) { #ifndef LDID_NOPLIST _assert(!flag_r); ldid::DiskFolder folder(path); - path += "/" + Sign("", folder, key, entitlements, requirement).path; + path += "/" + Sign("", folder, key, requirement, ldid::fun([&](const std::string &, const std::string &) -> std::string { return entitlements; })).path; #else _assert(false); #endif diff --git a/ldid.hpp b/ldid.hpp index b3631bb..db6e986 100644 --- a/ldid.hpp +++ b/ldid.hpp @@ -149,11 +149,10 @@ struct Bundle { std::vector hash; }; -Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &entitlements, const std::string &requirement); +Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &requirement, const Functor &alter); 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