Update recalculates all section offsets.
()
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // update recalculates the section offsets. |
| 39 | func (exe *Executable) update(section *Section, index int) { |
| 40 | if index == 0 { |
| 41 | exe.updateFirst(section) |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | previous := exe.Sections[index-1] |
| 46 | section.FileOffset, section.Padding = AlignPad(previous.FileOffset+len(previous.Bytes), exe.fileAlign) |
| 47 | section.MemoryOffset = Align(previous.MemoryOffset+len(previous.Bytes), exe.memoryAlign) |
| 48 | |
| 49 | if exe.congruent && exe.fileAlign != exe.memoryAlign { |
| 50 | section.MemoryOffset += section.FileOffset % exe.memoryAlign |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // updateFirst recalculates the section offsets for the first section. |
| 55 | func (exe *Executable) updateFirst(section *Section) { |
| 56 | if exe.embedHeaders { |
| 57 | section.FileOffset, section.Padding = AlignPad(exe.headerEnd, 0x40) |
| 58 | section.MemoryOffset = section.FileOffset |
| 59 | } else { |
| 60 | section.FileOffset, section.Padding = AlignPad(exe.headerEnd, exe.fileAlign) |
| 61 | section.MemoryOffset = Align(exe.headerEnd, exe.memoryAlign) |
| 62 | } |
| 63 | |
| 64 | if exe.congruent && exe.fileAlign != exe.memoryAlign { |