- for (size_t index(0); index != count; ++index) {
- uint32_t type = Swap(super->index[index].type);
- if (type != 0 && type <= special) {
- uint32_t offset = Swap(super->index[index].offset);
- struct Blob *local = (struct Blob *) (blob + offset);
- sha1((uint8_t *) (hashes - type), (uint8_t *) local, Swap(local->length));
+ if (true) {
+ std::stringbuf data;
+
+ uint32_t normal((allocation.limit_ + pagesize - 1) / pagesize);
+
+ Blob blob;
+ blob.magic = Swap(CSMAGIC_CODEDIRECTORY);
+ blob.length = Swap(uint32_t(sizeof(blob) + sizeof(CodeDirectory) + strlen(name) + 1 + SHA_DIGEST_LENGTH * (allocation.special_ + normal)));
+ put(data, &blob, sizeof(blob));
+
+ CodeDirectory directory;
+ directory.version = Swap(uint32_t(0x00020001));
+ directory.flags = Swap(uint32_t(0));
+ directory.hashOffset = Swap(uint32_t(sizeof(blob) + sizeof(CodeDirectory) + strlen(name) + 1 + SHA_DIGEST_LENGTH * allocation.special_));
+ directory.identOffset = Swap(uint32_t(sizeof(blob) + sizeof(CodeDirectory)));
+ directory.nSpecialSlots = Swap(allocation.special_);
+ directory.codeLimit = Swap(allocation.limit_);
+ directory.nCodeSlots = Swap(normal);
+ directory.hashSize = SHA_DIGEST_LENGTH;
+ directory.hashType = CS_HASHTYPE_SHA1;
+ directory.spare1 = 0x00;
+ directory.pageSize = pageshift;
+ directory.spare2 = Swap(uint32_t(0));
+ put(data, &directory, sizeof(directory));
+
+ put(data, name, strlen(name) + 1);
+
+ uint8_t storage[allocation.special_ + normal][SHA_DIGEST_LENGTH];
+ uint8_t (*hashes)[SHA_DIGEST_LENGTH] = storage + allocation.special_;
+
+ memset(storage, 0, sizeof(*storage) * allocation.special_);
+
+ _foreach (blob, blobs) {
+ auto local(reinterpret_cast<const Blob *>(&blob.second[0]));
+ sha1((uint8_t *) (hashes - blob.first), local, Swap(local->length));