Example #1
0
int rel2(void)
{
    if(rand() % 3 < 2)
        return 0;

    if(rand() % 4 < 3) { // 75% chance to only change its related Symbol Table index
        Elf_Section sym_ndx;

        if(rand() % 2)
            sym_ndx = rand() % orcHDR->e_shnum; // A random but valid Symbol Table index within the SHT
        else
            sym_ndx = getElf_Section();

        if(orcSHT->sh_type == SHT_REL)
            orcREL->r_info  = ELF_R_INFO(sym_ndx, ELF_R_TYPE(orcREL->r_info));
        else
            orcRELA->r_info = ELF_R_INFO(sym_ndx, ELF_R_TYPE(orcRELA->r_info));
    } else {
        if(orcSHT->sh_type == SHT_REL)
#if defined(__i386__)
            orcREL->r_info = getElf_Word();
#elif defined(__x86_64__)
            orcREL->r_info = getElf_Xword();
#endif
        else
#if defined(__i386__)
            orcRELA->r_info = getElf_Word();
#elif defined(__x86_64__)
            orcRELA->r_info = getElf_Xword();
#endif
    }
Example #2
0
void
renum_reloc_syms(Elf_Ehdr * ehdr, Symmap * symmap, int symtabsecnum)
{
	Elf_Shdr       *pshdr;
	int             i, j;
	int             num_reloc;
	Elf_Rel        *prel;
	Elf_RelA       *prela;
	int             symnum;

	for (i = 0; i < ehdr->e_shnum; i++) {
		pshdr = (Elf_Shdr *) (pexe + ehdr->e_shoff +
		    (i * ehdr->e_shentsize));
		if ((pshdr->sh_type == SHT_RELA) &&
		    pshdr->sh_link == symtabsecnum) {

#ifdef DEBUG
			printf("section %d has rela relocations in symtab\n", i);
#endif
			prela = (Elf_RelA *) (pexe + pshdr->sh_offset);
			num_reloc = pshdr->sh_size / sizeof(Elf_RelA);
			for (j = 0; j < num_reloc; j++) {
				symnum = ELF_R_SYM(prela[j].r_info);
#ifdef DEBUG
				printf("sym num o %d n %d\n", symnum,
				    symmap[symnum]);
#endif
				prela[j].r_info = ELF_R_INFO(symmap[symnum],
				    ELF_R_TYPE(prela[j].r_info));
			}
		}
		if ((pshdr->sh_type == SHT_REL) &&
		    pshdr->sh_link == symtabsecnum) {
#ifdef DEBUG
			printf("section %d has rel relocations in symtab\n", i);
#endif
			prel = (Elf_Rel *) (pexe + pshdr->sh_offset);
			num_reloc = pshdr->sh_size / sizeof(Elf_Rel);
			for (j = 0; j < num_reloc; j++) {
				symnum = ELF_R_SYM(prel[j].r_info);
#ifdef DEBUG
				printf("sym num o %d n %d\n", symnum,
				    symmap[symnum]);
#endif
				prel[j].r_info = ELF_R_INFO(symmap[symnum],
				    ELF_R_TYPE(prel[j].r_info));
			}
		}
	}

}
Example #3
0
/*
 * Clear a relocation record.  The relocation has been applied to the image and
 * thus the relocation must not occur again.
 */
void
clear_reloc(void *vrel)
{
	Rela	*rel = vrel;

	rel->r_offset = 0;
	rel->r_info = ELF_R_INFO(0, R_AMD64_NONE);
	rel->r_addend = 0;
}