]> git.saurik.com Git - ldid.git/commitdiff
Indirect support for .app signing via new -E flag.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 21 Sep 2015 19:50:36 +0000 (12:50 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 21 Sep 2015 19:50:36 +0000 (12:50 -0700)
ldid.cpp

index 01b4e0904be9f0700d85b7b8fa6807cec7264dbd..6207304a8e5a5d7f82ced816a4971014d4ac756a 100644 (file)
--- a/ldid.cpp
+++ b/ldid.cpp
@@ -1289,7 +1289,9 @@ class Signature {
     }
 };
 
-void resign(void *idata, size_t isize, std::streambuf &output, const std::string &name, const std::string &entitlements, const std::string &key) {
+typedef std::map<uint32_t, std::string> Slots;
+
+void resign(void *idata, size_t isize, std::streambuf &output, const std::string &name, const std::string &entitlements, const std::string &key, const Slots &slots) {
     resign(idata, isize, output, fun([&](size_t size) -> size_t {
         size_t alloc(sizeof(struct SuperBlob));
 
@@ -1319,6 +1321,9 @@ void resign(void *idata, size_t isize, std::streambuf &output, const std::string
             alloc += 0x3000;
         }
 
+        _foreach (slot, slots)
+            special = std::max(special, slot.first);
+
         uint32_t normal((size + PageSize_ - 1) / PageSize_);
         alloc = Align(alloc + (special + normal) * SHA_DIGEST_LENGTH, 16);
         return alloc;
@@ -1346,6 +1351,8 @@ void resign(void *idata, size_t isize, std::streambuf &output, const std::string
             uint32_t special(0);
             _foreach (blob, blobs)
                 special = std::max(special, blob.first);
+            _foreach (slot, slots)
+                special = std::max(special, slot.first);
             uint32_t normal((limit + PageSize_ - 1) / PageSize_);
 
             CodeDirectory directory;
@@ -1375,6 +1382,11 @@ void resign(void *idata, size_t isize, std::streambuf &output, const std::string
                 sha1((uint8_t *) (hashes - blob.first), local, Swap(local->length));
             }
 
+            _foreach (slot, slots) {
+                _assert(sizeof(*hashes) == slot.second.size());
+                memcpy(hashes - slot.first, slot.second.data(), slot.second.size());
+            }
+
             if (normal != 1)
                 for (size_t i = 0; i != normal - 1; ++i)
                     sha1(hashes[i], (PageSize_ * i < overlap.size() ? overlap.data() : top) + PageSize_ * i, PageSize_);
@@ -1446,6 +1458,7 @@ int main(int argc, char *argv[]) {
 
     Map entitlements;
     Map key;
+    Slots slots;
 
     std::vector<std::string> files;
 
@@ -1469,6 +1482,19 @@ int main(int argc, char *argv[]) {
 
             case 'e': flag_e = true; break;
 
+            case 'E': {
+                const char *slot = argv[argi] + 2;
+                const char *colon = strchr(slot, ':');
+                _assert(colon != NULL);
+                Map file(colon + 1, O_RDONLY, PROT_READ, MAP_PRIVATE);
+                char *arge;
+                unsigned number(strtoul(slot, &arge, 0));
+                _assert(arge == colon);
+                std::string &hash(slots[number]);
+                hash.resize(SHA_DIGEST_LENGTH);
+                sha1(reinterpret_cast<uint8_t *>(&hash[0]), file.data(), file.size());
+            } break;
+
             case 'D': flag_D = true; break;
 
             case 'a': flag_a = true; break;
@@ -1558,9 +1584,8 @@ int main(int argc, char *argv[]) {
 
             if (flag_r)
                 resign(input.data(), input.size(), output);
-            else {
-                resign(input.data(), input.size(), output, name, entitlements, key);
-            }
+            else
+                resign(input.data(), input.size(), output, name, entitlements, key, slots);
         }
 
         Map mapping(!temp.empty() ? temp.c_str() : path, flag_T || flag_s);