Changeset 353 for trunk/util/ldid.cpp
- Timestamp:
- 07/06/08 20:56:57 (6 months ago)
- Files:
-
- 1 modified
-
trunk/util/ldid.cpp (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/util/ldid.cpp
r316 r353 52 52 uint32_t magic; 53 53 uint32_t nfat_arch; 54 } ;54 } _packed; 55 55 56 56 #define FAT_MAGIC 0xcafebabe … … 63 63 uint32_t size; 64 64 uint32_t align; 65 } ;65 } _packed; 66 66 67 67 struct mach_header { … … 73 73 uint32_t sizeofcmds; 74 74 uint32_t flags; 75 } ;75 } _packed; 76 76 77 77 #define MH_MAGIC 0xfeedface … … 86 86 uint32_t cmd; 87 87 uint32_t cmdsize; 88 } ;88 } _packed; 89 89 90 90 #define LC_REQ_DYLD 0x80000000 … … 101 101 uint32_t current_version; 102 102 uint32_t compatibility_version; 103 } ;103 } _packed; 104 104 105 105 struct dylib_command { … … 107 107 uint32_t cmdsize; 108 108 struct dylib dylib; 109 } ;109 } _packed; 110 110 111 111 struct uuid_command { … … 113 113 uint32_t cmdsize; 114 114 uint8_t uuid[16]; 115 } ;115 } _packed; 116 116 117 117 struct linkedit_data_command { … … 120 120 uint32_t dataoff; 121 121 uint32_t datasize; 122 } ;122 } _packed; 123 123 124 124 uint16_t Swap_(uint16_t value) { … … 246 246 }; 247 247 248 #define CSMAGIC_CODEDIRECTORY 0xfade0c02248 #define CSMAGIC_CODEDIRECTORY 0xfade0c02 249 249 #define CSMAGIC_EMBEDDED_SIGNATURE 0xfade0cc0 250 #define CSMAGIC_ENTITLEMENTS 0xfade7171 251 250 252 #define CSSLOT_CODEDIRECTORY 0 251 #define CSSLOT_REQUIREMENTS 2 253 #define CSSLOT_REQUIREMENTS 2 254 #define CSSLOT_ENTITLEMENTS 5 252 255 253 256 struct BlobIndex { 254 257 uint32_t type; 255 258 uint32_t offset; 256 } ;257 258 struct SuperBlob {259 } _packed; 260 261 struct Blob { 259 262 uint32_t magic; 260 263 uint32_t length; 264 } _packed; 265 266 struct SuperBlob { 267 struct Blob blob; 261 268 uint32_t count; 262 269 struct BlobIndex index[]; 263 } ;270 } _packed; 264 271 265 272 struct CodeDirectory { 266 uint32_t magic; 267 uint32_t length; 273 struct Blob blob; 268 274 uint32_t version; 269 275 uint32_t flags; … … 278 284 uint8_t pageSize; 279 285 uint32_t spare2; 280 } ;286 } _packed; 281 287 282 288 extern "C" uint32_t hash(uint8_t *k, uint32_t length, uint32_t initval); … … 302 308 bool timeh(false); 303 309 uint32_t timev(0); 310 311 const void *xmld(NULL); 312 size_t xmls(0); 304 313 305 314 std::vector<std::string> files; … … 314 323 case 'u': flag_u = true; break; 315 324 case 'p': flag_p = true; break; 316 case 'S': flag_S = true; break; 325 326 case 'S': 327 flag_S = true; 328 if (argv[argi][2] != '\0') { 329 const char *xml = argv[argi] + 2; 330 xmld = map(xml, 0, _not(size_t), &xmls, true); 331 } 332 break; 317 333 318 334 case 'T': { … … 389 405 if (pid == 0) { 390 406 char *ssize; 391 asprintf(&ssize, "%u", (sizeof(struct SuperBlob) + 2 * sizeof(struct BlobIndex) + sizeof(struct CodeDirectory) + strlen(base) + 1 + (size + 0x1000 - 1) / 0x1000 * 0x14 + 0xc + 15) / 16 * 16); 407 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); 408 //printf("codesign_allocate -i %s -a %s %s -o %s\n", path, arch, ssize, temp); 392 409 execlp(allocate, allocate, "-i", path, "-a", arch, ssize, "-o", temp, NULL); 393 410 _assert(false); … … 454 471 uint8_t *blob = top + data; 455 472 struct SuperBlob *super = reinterpret_cast<struct SuperBlob *>(blob); 456 super-> magic = Swap(CSMAGIC_EMBEDDED_SIGNATURE);457 458 uint32_t count = 2;473 super->blob.magic = Swap(CSMAGIC_EMBEDDED_SIGNATURE); 474 475 uint32_t count = xmld == NULL ? 2 : 3; 459 476 uint32_t offset = sizeof(struct SuperBlob) + count * sizeof(struct BlobIndex); 460 477 … … 466 483 offset += sizeof(struct CodeDirectory); 467 484 468 directory-> magic = Swap(CSMAGIC_CODEDIRECTORY);485 directory->blob.magic = Swap(CSMAGIC_CODEDIRECTORY); 469 486 directory->version = Swap(0x00020001); 470 487 directory->flags = Swap(0); … … 495 512 directory->hashOffset = Swap(offset - begin); 496 513 offset += sizeof(*hashes) * (special + pages); 497 directory-> length = Swap(offset - begin);514 directory->blob.length = Swap(offset - begin); 498 515 499 516 super->index[1].type = Swap(CSSLOT_REQUIREMENTS); … … 503 520 offset += 0xc; 504 521 522 if (xmld != NULL) { 523 super->index[2].type = Swap(CSSLOT_ENTITLEMENTS); 524 super->index[2].offset = Swap(offset); 525 526 uint32_t begin = offset; 527 struct Blob *entitlements = reinterpret_cast<struct Blob *>(blob + begin); 528 offset += sizeof(struct Blob); 529 530 memcpy(blob + offset, xmld, xmls); 531 offset += xmls; 532 533 entitlements->magic = Swap(CSMAGIC_ENTITLEMENTS); 534 entitlements->length = Swap(offset - begin); 535 } 536 505 537 super->count = Swap(count); 506 super->length = Swap(offset); 507 508 _assert(offset <= size); 538 super->blob.length = Swap(offset); 539 540 if (offset > size) { 541 fprintf(stderr, "offset (%zu) > size (%zu)\n", offset, size); 542 _assert(false); 543 } //else fprintf(stderr, "offset (%zu) <= size (%zu)\n", offset, size); 544 509 545 memset(blob + offset, 0, size - offset); 510 546 }
