Changeset 310 for trunk/util/ldid.cpp

Show
Ignore:
Timestamp:
06/14/08 09:29:39 (5 months ago)
Author:
saurik
Message:

Added requirement slots and armv6 support to ldid/codesign.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/ldid.cpp

    r302 r310  
    218218    } 
    219219 
     220    struct mach_header *operator ->() const { 
     221        return mach_header_; 
     222    } 
     223 
    220224    void *GetBase() { 
    221225        return base_; 
     
    242246#define CSMAGIC_EMBEDDED_SIGNATURE 0xfade0cc0 
    243247#define CSSLOT_CODEDIRECTORY 0 
     248#define CSSLOT_REQUIREMENTS 2 
    244249 
    245250struct BlobIndex { 
     
    347352                allocate = "codesign_allocate"; 
    348353 
    349             size_t size; { 
     354            size_t size = _not(size_t); 
     355            const char *arch; { 
    350356                Framework framework(path); 
    351                 size = framework.GetSize(); 
     357                _foreach (load_command, framework.GetLoadCommands()) { 
     358                    uint32_t cmd(framework.Swap((*load_command)->cmd)); 
     359                    if (cmd == LC_CODE_SIGNATURE) { 
     360                        struct linkedit_data_command *signature = reinterpret_cast<struct linkedit_data_command *>(*load_command); 
     361                        size = framework.Swap(signature->dataoff); 
     362                        _assert(size < framework.GetSize()); 
     363                        break; 
     364                    } 
     365                } 
     366 
     367                if (size == _not(size_t)) 
     368                    size = framework.GetSize(); 
     369 
     370                switch (framework->cputype) { 
     371                    case 12: switch (framework->cpusubtype) { 
     372                        case 0: arch = "arm"; break; 
     373                        case 6: arch = "armv6"; break; 
     374                        default: arch = NULL; break; 
     375                    } break; 
     376 
     377                    default: arch = NULL; break; 
     378                } 
    352379            } 
     380 
     381            _assert(arch != NULL); 
    353382 
    354383            pid_t pid = fork(); 
     
    356385            if (pid == 0) { 
    357386                char *ssize; 
    358                 asprintf(&ssize, "%u", (sizeof(struct SuperBlob) + sizeof(struct BlobIndex) + sizeof(struct CodeDirectory) + strlen(base) + 1 + (size + 0x1000 - 1) / 0x1000 * 0x14 + 15) / 16 * 16); 
    359                 printf("%s\n", ssize); 
    360                 execlp(allocate, allocate, "-i", path, "-a", "arm", ssize, "-o", temp, NULL); 
     387                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); 
     388                execlp(allocate, allocate, "-i", path, "-a", arch, ssize, "-o", temp, NULL); 
    361389                _assert(false); 
    362390            } 
     
    424452            super->magic = Swap(CSMAGIC_EMBEDDED_SIGNATURE); 
    425453 
    426             uint32_t count = 1; 
     454            uint32_t count = 2; 
    427455            uint32_t offset = sizeof(struct SuperBlob) + count * sizeof(struct BlobIndex); 
    428456 
     
    465493            directory->length = Swap(offset - begin); 
    466494 
     495            super->index[1].type = Swap(CSSLOT_REQUIREMENTS); 
     496            super->index[1].offset = Swap(offset); 
     497 
     498            memcpy(blob + offset, "\xfa\xde\x0c\x01\x00\x00\x00\x0c\x00\x00\x00\x00", 0xc); 
     499            offset += 0xc; 
     500 
    467501            super->count = Swap(count); 
    468502            super->length = Swap(offset); 
    469503 
    470             _assert(offset < size); 
     504            _assert(offset <= size); 
    471505            memset(blob + offset, 0, size - offset); 
    472506        }