]> git.saurik.com Git - ldid.git/commitdiff
Provide a simple to use implementation of ldid -e.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 22 Dec 2016 00:44:35 +0000 (16:44 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 22 Dec 2016 00:44:35 +0000 (16:44 -0800)
ldid.cpp
ldid.hpp

index 80102113cb0200bdb77c2d2a00d1759d526a3140..d7fdf7a0e121242cc4a097af82b953e26ba38c62 100644 (file)
--- 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<void *>(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<struct linkedit_data_command *>(load_command));
+                auto offset(mach_header.Swap(signature->dataoff));
+                auto pointer(reinterpret_cast<uint8_t *>(mach_header.GetBase()) + offset);
+                auto super(reinterpret_cast<struct SuperBlob *>(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<struct Blob *>(pointer + begin));
+                        auto writ(Swap(blob->length) - sizeof(*blob));
+
+                        if (entitlements.empty())
+                            entitlements.assign(reinterpret_cast<char *>(blob + 1), writ);
+                        else
+                            _assert(entitlements.compare(0, entitlements.size(), reinterpret_cast<char *>(blob + 1), writ) == 0);
+                    }
+            }
+
+    return entitlements;
+}
+
 static void Allocate(const void *idata, size_t isize, std::streambuf &output, const Functor<size_t (const MachHeader &, size_t)> &allocate, const Functor<size_t (const MachHeader &, std::streambuf &output, size_t, const std::string &, const char *)> &save) {
     FatHeader source(const_cast<void *>(idata), isize);
 
index b603bbd1c18aac4fe569c377fde701d44f385f1c..fbacc86d68a3da6c1aa93b174affc11128f877b9 100644 (file)
--- 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<uint32_t, std::vector<char>> Slots;
 
+std::string Analyze(const void *data, size_t size);
 std::vector<char> 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);
 
 }