/** Encode Elf header disk structure */ void * SgAsmElfFileHeader::encode(ByteOrder::Endianness sex, Elf32FileHeader_disk *disk) const { ROSE_ASSERT(p_magic.size() == NELMTS(disk->e_ident_magic)); for (size_t i=0; i<NELMTS(disk->e_ident_magic); i++) disk->e_ident_magic[i] = p_magic[i]; ByteOrder::host_to_disk(sex, p_e_ident_file_class, &(disk->e_ident_file_class)); ByteOrder::host_to_disk(sex, p_e_ident_data_encoding, &(disk->e_ident_data_encoding)); ByteOrder::host_to_disk(sex, p_e_ident_file_version, &(disk->e_ident_file_version)); ROSE_ASSERT(p_e_ident_padding.size() == NELMTS(disk->e_ident_padding)); for (size_t i=0; i<NELMTS(disk->e_ident_padding); i++) disk->e_ident_padding[i] = p_e_ident_padding[i]; ByteOrder::host_to_disk(sex, p_e_type, &(disk->e_type)); ByteOrder::host_to_disk(sex, p_e_machine, &(disk->e_machine)); ByteOrder::host_to_disk(sex, p_exec_format->get_version(), &(disk->e_version)); ByteOrder::host_to_disk(sex, get_entry_rva(), &(disk->e_entry)); if (get_segment_table()) { ByteOrder::host_to_disk(sex, get_segment_table()->get_offset(), &(disk->e_phoff)); } else { ByteOrder::host_to_disk(sex, 0, &(disk->e_phoff)); } if (get_section_table()) { ByteOrder::host_to_disk(sex, get_section_table()->get_offset(), &(disk->e_shoff)); } else { ByteOrder::host_to_disk(sex, 0, &(disk->e_shoff)); } ByteOrder::host_to_disk(sex, p_e_flags, &(disk->e_flags)); ByteOrder::host_to_disk(sex, p_e_ehsize, &(disk->e_ehsize)); if (p_e_phnum>0) { ByteOrder::host_to_disk(sex, p_phextrasz+sizeof(SgAsmElfSegmentTableEntry::Elf32SegmentTableEntry_disk), &(disk->e_phentsize)); } else { ByteOrder::host_to_disk(sex, 0, &(disk->e_phentsize)); } if (p_e_shnum>0) { ByteOrder::host_to_disk(sex, p_shextrasz+sizeof(SgAsmElfSectionTableEntry::Elf32SectionTableEntry_disk), &(disk->e_shentsize)); } else { ByteOrder::host_to_disk(sex, 0, &(disk->e_shentsize)); } ByteOrder::host_to_disk(sex, p_e_phnum, &(disk->e_phnum)); ByteOrder::host_to_disk(sex, p_e_shnum, &(disk->e_shnum)); ByteOrder::host_to_disk(sex, p_e_shstrndx, &(disk->e_shstrndx)); return disk; }
void * SgAsmPEFileHeader::encode(PE64OptHeader_disk *disk) const { host_to_le(p_e_opt_magic, &(disk->e_opt_magic)); host_to_le(p_e_lmajor, &(disk->e_lmajor)); host_to_le(p_e_lminor, &(disk->e_lminor)); host_to_le(p_e_code_size, &(disk->e_code_size)); host_to_le(p_e_data_size, &(disk->e_data_size)); host_to_le(p_e_bss_size, &(disk->e_bss_size)); host_to_le(get_entry_rva(), &(disk->e_entrypoint_rva)); host_to_le(p_e_code_rva, &(disk->e_code_rva)); // host_to_le(p_e_data_rva, &(disk->e_data_rva)); /* not present in PE32+ */ host_to_le(get_base_va(), &(disk->e_image_base)); host_to_le(p_e_section_align, &(disk->e_section_align)); host_to_le(p_e_file_align, &(disk->e_file_align)); host_to_le(p_e_os_major, &(disk->e_os_major)); host_to_le(p_e_os_minor, &(disk->e_os_minor)); host_to_le(p_e_user_major, &(disk->e_user_major)); host_to_le(p_e_user_minor, &(disk->e_user_minor)); host_to_le(p_e_subsys_major, &(disk->e_subsys_major)); host_to_le(p_e_subsys_minor, &(disk->e_subsys_minor)); host_to_le(p_e_reserved9, &(disk->e_reserved9)); host_to_le(p_e_image_size, &(disk->e_image_size)); host_to_le(p_e_header_size, &(disk->e_header_size)); host_to_le(p_e_file_checksum, &(disk->e_file_checksum)); host_to_le(p_e_subsystem, &(disk->e_subsystem)); host_to_le(p_e_dll_flags, &(disk->e_dll_flags)); host_to_le(p_e_stack_reserve_size, &(disk->e_stack_reserve_size)); host_to_le(p_e_stack_commit_size, &(disk->e_stack_commit_size)); host_to_le(p_e_heap_reserve_size, &(disk->e_heap_reserve_size)); host_to_le(p_e_heap_commit_size, &(disk->e_heap_commit_size)); host_to_le(p_e_loader_flags, &(disk->e_loader_flags)); host_to_le(p_e_num_rvasize_pairs, &(disk->e_num_rvasize_pairs)); return disk; }