Changeset 360 for trunk/util
- Timestamp:
- 07/18/08 08:19:34 (6 months ago)
- Files:
-
- 1 modified
-
trunk/util/ldid.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/util/ldid.cpp
r354 r360 305 305 306 306 bool flag_T(false); 307 307 308 bool flag_S(false); 309 bool flag_s(false); 308 310 309 311 bool timeh(false); … … 325 327 case 'p': flag_p = true; break; 326 328 329 case 's': 330 _assert(!flag_S); 331 flag_s = true; 332 break; 333 327 334 case 'S': 335 _assert(!flag_s); 328 336 flag_S = true; 329 337 if (argv[argi][2] != '\0') { … … 406 414 if (pid == 0) { 407 415 char *ssize; 408 asprintf(&ssize, "%u", (sizeof(struct SuperBlob) + 2 * sizeof(struct BlobIndex) + sizeof(struct CodeDirectory) + strlen(base) + 1 + ( size + 0x1000 - 1) / 0x1000* 0x14 + 0xc + (xmld == NULL ? 0 : 0x10 + xmls) + 15) / 16 * 16);409 //printf(" codesign_allocate -i %s -a %s %s -o %s\n", path, arch, ssize, temp);416 asprintf(&ssize, "%u", (sizeof(struct SuperBlob) + 2 * sizeof(struct BlobIndex) + sizeof(struct CodeDirectory) + strlen(base) + 1 + ((xmld == NULL ? CSSLOT_REQUIREMENTS : CSSLOT_ENTITLEMENTS) + (size + 0x1000 - 1) / 0x1000) * 0x14 + 0xc + (xmld == NULL ? 0 : 0x10 + xmls) + 15) / 16 * 16); 417 //printf("%s -i %s -a %s %s -o %s\n", allocate, path, arch, ssize, temp); 410 418 execlp(allocate, allocate, "-i", path, "-a", arch, ssize, "-o", temp, NULL); 411 419 _assert(false); … … 461 469 } 462 470 } 471 } 472 473 if (flag_s) { 474 _assert(signature != NULL); 475 476 uint32_t data = framework.Swap(signature->dataoff); 477 uint32_t size = framework.Swap(signature->datasize); 478 479 uint8_t *top = reinterpret_cast<uint8_t *>(framework.GetBase()); 480 uint8_t *blob = top + data; 481 struct SuperBlob *super = reinterpret_cast<struct SuperBlob *>(blob); 482 483 for (size_t index(0); index != Swap(super->count); ++index) 484 if (Swap(super->index[index].type) == CSSLOT_CODEDIRECTORY) { 485 uint32_t begin = Swap(super->index[index].offset); 486 struct CodeDirectory *directory = reinterpret_cast<struct CodeDirectory *>(blob + begin); 487 488 uint8_t (*hashes)[20] = reinterpret_cast<uint8_t (*)[20]>(blob + begin + Swap(directory->hashOffset)); 489 uint32_t pages = Swap(directory->nCodeSlots); 490 491 if (pages != 1) 492 for (size_t i = 0; i != pages - 1; ++i) 493 sha1(hashes[i], top + 0x1000 * i, 0x1000); 494 if (pages != 0) 495 sha1(hashes[pages - 1], top + 0x1000 * (pages - 1), data % 0x1000); 496 } 463 497 } 464 498 … … 498 532 offset += strlen(base) + 1; 499 533 534 uint32_t special = xmld == NULL ? CSSLOT_REQUIREMENTS : CSSLOT_ENTITLEMENTS; 535 directory->nSpecialSlots = Swap(special); 536 500 537 uint8_t (*hashes)[20] = reinterpret_cast<uint8_t (*)[20]>(blob + offset); 501 uint32_t special = 0; 538 memset(hashes, 0, sizeof(*hashes) * special); 539 540 offset += sizeof(*hashes) * special; 541 hashes += special; 502 542 503 543 uint32_t pages = (data + 0x1000 - 1) / 0x1000; 504 directory->nSpecialSlots = Swap(special);505 544 directory->nCodeSlots = Swap(pages); 506 545 507 546 if (pages != 1) 508 547 for (size_t i = 0; i != pages - 1; ++i) 509 sha1(hashes[ special +i], top + 0x1000 * i, 0x1000);548 sha1(hashes[i], top + 0x1000 * i, 0x1000); 510 549 if (pages != 0) 511 sha1(hashes[ special +pages - 1], top + 0x1000 * (pages - 1), data % 0x1000);550 sha1(hashes[pages - 1], top + 0x1000 * (pages - 1), data % 0x1000); 512 551 513 552 directory->hashOffset = Swap(offset - begin); 514 offset += sizeof(*hashes) * (special + pages);553 offset += sizeof(*hashes) * pages; 515 554 directory->blob.length = Swap(offset - begin); 516 555 … … 534 573 entitlements->magic = Swap(CSMAGIC_ENTITLEMENTS); 535 574 entitlements->length = Swap(offset - begin); 575 } 576 577 for (size_t index(0); index != count; ++index) { 578 uint32_t type = Swap(super->index[index].type); 579 if (type != 0 && type <= special) { 580 uint32_t offset = Swap(super->index[index].offset); 581 struct Blob *local = (struct Blob *) (blob + offset); 582 sha1((uint8_t *) (hashes - type), (uint8_t *) local, Swap(local->length)); 583 } 536 584 } 537 585
