/** Define an RVA/Size pair in the PE file header. */ void SgAsmPEFileHeader::set_rvasize_pair(PairPurpose idx, SgAsmPESection *section) { ROSE_ASSERT(get_rvasize_pairs()!=NULL); ROSE_ASSERT(section->get_parent()!=NULL); ROSE_ASSERT(isSgAsmPEFileHeader(section->get_header())!=NULL); if (idx>=16) fprintf(stderr, "SgAsmPEFileHeader::set_rvasize_pair: warning: index %u exceeds specification limit\n", (unsigned)idx); /* Extend array of rva/size pairs if necessary */ if ((size_t)idx>=get_rvasize_pairs()->get_pairs().size()) { get_rvasize_pairs()->get_pairs().resize(idx+1, NULL); for (size_t i=0; i<=(size_t)idx; i++) { if (NULL==get_rvasize_pairs()->get_pairs()[i]) { SgAsmPERVASizePair *pair = new SgAsmPERVASizePair(get_rvasize_pairs(), 0, 0); get_rvasize_pairs()->get_pairs()[i] = pair; } } } SgAsmPERVASizePair *pair = get_rvasize_pairs()->get_pairs()[idx]; ROSE_ASSERT(pair!=NULL); pair->set_e_rva(rose_rva_t(section->get_mapped_preferred_rva(), section)); pair->set_e_size(section->get_mapped_size()); pair->set_section(section); /* If the section has no name then give it one based on the RVA/Size index. This is mostly for convenience and debugging * since the name is never stored in the file. */ if (section->get_name()->get_string().empty()) { const char *short_name; section->get_name()->set_string(rvasize_pair_name(idx, &short_name)); section->set_short_name(short_name); } }
/** Define an RVA/Size pair in the PE file header. */ void SgAsmPEFileHeader::set_rvasize_pair(PairPurpose idx, SgAsmPESection *section) { ROSE_ASSERT(get_rvasize_pairs()!=NULL); ROSE_ASSERT(section->get_parent()!=NULL); ROSE_ASSERT(isSgAsmPEFileHeader(section->get_header())!=NULL); switch (idx) { case PAIR_EXPORTS: case PAIR_IMPORTS: case PAIR_RESOURCES: case PAIR_EXCEPTIONS: case PAIR_CERTIFICATES: case PAIR_BASERELOCS: case PAIR_DEBUG: case PAIR_ARCHITECTURE: case PAIR_GLOBALPTR: case PAIR_TLS: case PAIR_LOADCONFIG: case PAIR_BOUNDIMPORT: case PAIR_IAT: case PAIR_DELAYIMPORT: case PAIR_CLRRUNTIME: case PAIR_RESERVED15: break; default: mlog[WARN] <<"SgAsmPEFileHeader::set_rvasize_pair: index " <<idx <<" exceeds specification limit\n"; } /* Extend array of rva/size pairs if necessary */ if ((size_t)idx>=get_rvasize_pairs()->get_pairs().size()) { get_rvasize_pairs()->get_pairs().resize(idx+1, NULL); for (size_t i=0; i<=(size_t)idx; i++) { if (NULL==get_rvasize_pairs()->get_pairs()[i]) { SgAsmPERVASizePair *pair = new SgAsmPERVASizePair(get_rvasize_pairs(), 0, 0); get_rvasize_pairs()->get_pairs()[i] = pair; } } } SgAsmPERVASizePair *pair = get_rvasize_pairs()->get_pairs()[idx]; ROSE_ASSERT(pair!=NULL); pair->set_e_rva(rose_rva_t(section->get_mapped_preferred_rva(), section)); pair->set_e_size(section->get_mapped_size()); pair->set_section(section); /* If the section has no name then give it one based on the RVA/Size index. This is mostly for convenience and debugging * since the name is never stored in the file. */ if (section->get_name()->get_string().empty()) { const char *short_name; section->get_name()->set_string(rvasize_pair_name(idx, &short_name)); section->set_short_name(short_name); } }
/** Update all the RVA/Size pair info from the section to which it points. */ void SgAsmPEFileHeader::update_rvasize_pairs() { for (size_t i=0; i<get_rvasize_pairs()->get_pairs().size(); i++) { SgAsmPERVASizePair *pair = get_rvasize_pairs()->get_pairs()[i]; SgAsmGenericSection *section = pair->get_section(); if (section) { pair->set_e_rva(rose_rva_t(section->get_mapped_preferred_rva(), section)); pair->set_e_size(section->get_mapped_size()); } } }