@Override public byte[] getOrDecideContent(Map<Element, LayoutDecisionMap> alreadyDecided, byte[] contentHint) { OutputAssembler out = AssemblyBuffer.createOutputAssembler(ByteBuffer.allocate(65536).order(getOwner().getByteOrder())); // HACK // int loadCommandsSizeInBytes = computeLoadCommandsSize(loadCommands); out.skip((new HeaderStruct()).getWrittenSize()); out.align(8); int loadCommandsSizeInBytes = 0; for (LoadCommand cmd : loadCommands) { loadCommandsSizeInBytes += (int) alreadyDecided.get(cmd).getDecidedValue(LayoutDecision.Kind.SIZE); } out.pushSeek(0); new HeaderStruct(getOwner().getByteOrder() == nativeOrder ? MAGIC : CIGAM, cpuType, MachOObjectFile.this.cpuSubType, loadCommands.size(), loadCommandsSizeInBytes, (int) ObjectFile.flagSetAsLong(MachOObjectFile.this.flags)).write(out); out.pop(); return out.getBlob(); }
ent.flags = ObjectFile.flagSetAsLong(es.getFlags()); ent.fileOffset = (int) alreadyDecided.get(es).getDecidedValue(LayoutDecision.Kind.OFFSET);
db.write4Byte((int) ObjectFile.flagSetAsLong(maxprot)); db.write4Byte((int) ObjectFile.flagSetAsLong(initprot)); int sectionCountPos = db.pos(); db.write4Byte(0); // placeholder for section count ourRelocs == null ? 0 : (int) alreadyDecided.get(ourRelocs).getDecidedValue(LayoutDecision.Kind.OFFSET) + ourRelocs.startIndexFor(s) * ourRelocs.encodedEntrySize(), ourRelocs == null ? 0 : ourRelocs.countFor(s), (int) ObjectFile.flagSetAsLong(s.flags) | s.type.getValue(), /* reserved1 */ 0, /* reserved2 */ 0);
@Override public byte[] getOrDecideContent(Map<Element, LayoutDecisionMap> alreadyDecided, byte[] contentHint) { OutputAssembler oa = AssemblyBuffer.createOutputAssembler(getOwner().getByteOrder()); byte[] strtabContent = (byte[]) alreadyDecided.get(strtab).getDecidedValue(LayoutDecision.Kind.CONTENT); StringTable t = new StringTable(strtabContent); EntryStruct s = new EntryStruct(); for (Entry e : getSortedEntries()) { s.strx = t.indexFor(e.getNameInObject()); assert s.strx != -1; s.type = (byte) (e.type.value() | (e.privateExtern ? EntryStruct.N_PEXT : 0) | (e.extern ? EntryStruct.N_EXT : 0)); // NOTE: Mach-O section numbers are 1-based int sectionIndex = (e.section == null) ? 0 : getOwner().getSections().indexOf(e.section) + 1; assert !e.isDefined() || sectionIndex != -1; s.sect = (byte) (e.isDefined() ? sectionIndex : EntryStruct.NO_SECT); s.desc = (short) (ObjectFile.flagSetAsLong(e.descFlags) | e.refType.value()); /* * If we're a defined non-absolute symbol, we need to make this the virtual address * (even for relocatable files!), so add the vaddr of the section. Absolute symbols are * denoted by sectionIndex == 0. */ int valueToAdd = (sectionIndex == 0) ? 0 : (int) alreadyDecided.get(e.section).getDecidedValue(LayoutDecision.Kind.VADDR); s.value = e.value + valueToAdd; s.write(oa); } assert oa.pos() == getWrittenSize(); return oa.getBlob(); }
(int) ObjectFile.flagSetAsLong(es.getFlags()), /* TODO: alignment is 1024?? es.getAlignment() */ 16, sectionIndex + 1);