void () { long virtualAddress = mySectionHeaders.get(0).getVirtualAddress().getValue(); long sectionAlignment = myImageOptionalHeader.getSectionAlignment().getValue(); for (ImageSectionHeader header : mySectionHeaders) { // Section always starts from an address aligned to IMAGE_OPTIONAL_HEADER::SectionAlignment, which is 0x1000 by default if (virtualAddress % sectionAlignment != 0) { virtualAddress += sectionAlignment - virtualAddress % sectionAlignment; } header.getVirtualAddress().setValue(virtualAddress); virtualAddress += header.getVirtualSize().getValue(); } // Update the relative virtual address of the Base Relocation Table, if any. updateDataDirectoryFromSectionHeader(Section.RESOURCES_SECTION_NAME, ImageDataDirectory.IMAGE_DIRECTORY_ENTRY_RESOURCE); updateDataDirectoryFromSectionHeader(Section.RELOCATIONS_SECTION_NAME, ImageDataDirectory.IMAGE_DIRECTORY_ENTRY_BASERELOC); // Resources section may have changed virtual offset, re-shake of all nested structures required to have correct addresses, // also the binary size may have been changed as the result resetOffsets(0); }