From: Jay Freeman (saurik) Date: Mon, 21 Sep 2015 19:50:36 +0000 (-0700) Subject: Indirect support for .app signing via new -E flag. X-Git-Tag: v2.1.0~91 X-Git-Url: https://git.saurik.com/ldid.git/commitdiff_plain/e57b1f91c2669a5fbc872db6ccd87a4cc6be6e6e Indirect support for .app signing via new -E flag. --- diff --git a/ldid.cpp b/ldid.cpp index 01b4e09..6207304 100644 --- 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 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 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(&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);