Пример #1
0
eresi_Addr elfops_move_ptr(elf_bf_exec_t *e, eresi_Addr delta)
{

  elf_bf_link_map_t *l = &(e->ee_lm);
  eresi_Addr start = l->lm_next_reloc;

  //change tape pointer
  set_next_reloc(l, R_X86_64_64, symtab_get_index(e->ee_ptr_tape_ptr),
                 symtab_get_value_addr(e->ee_ptr_tape_ptr), delta);
  //copy new tape value into workspace
  set_next_reloc(l, R_X86_64_COPY, symtab_get_index(e->ee_ptr_tape_ptr),
                 symtab_get_value_addr(e->ee_tape_ptr), 0);

   return l->lm_next_reloc - start;
 }
Пример #2
0
 eresi_Addr elfops_add(elf_bf_exec_t *ee, eresi_Addr delta)
 {
   elf_bf_link_map_t *l = &(ee->ee_lm);

   eresi_Addr start = l->lm_next_reloc;

   //we assume that correct value is in scratch space, just do addition
   set_next_reloc(l, R_X86_64_64, symtab_get_index(ee->ee_tape_ptr),
                  symtab_get_value_addr(ee->ee_tape_ptr), delta);

   eresi_Addr setupi, copyi;
   elf_bf_Rela setup, copy;

   //update tape
   setupi = set_next_reloc(l, 0, 0, 0, 0);

   //copy new value back to tape
   copyi = set_next_reloc(l, R_X86_64_COPY, symtab_get_index(ee->ee_tape_copy),
                            0, 0);

   //go back at actually setup first entry
   reloc_get_reloc_entry(l, setupi, &setup);
   reloc_get_reloc_entry(l, copyi, &copy);
   //setup next entry so it knows where tape pointer is
   reloc_set_rela(&setup, R_X86_64_64, symtab_get_index(ee->ee_ptr_tape_ptr),
                  reloc_get_offset_addr(&copy), 0);
  return l->lm_next_reloc - start;
}
Пример #3
0
eresi_Addr init_scatch_space(elf_bf_exec_t *ee)
{
  elf_bf_link_map_t *l = &(ee->ee_lm);
  eresi_Addr start = l->lm_next_reloc;

  //copy new tape value into workspace
  set_next_reloc(l, R_X86_64_COPY, symtab_get_index(ee->ee_ptr_tape_ptr),
                 symtab_get_value_addr(ee->ee_tape_ptr), 0);
  return l->lm_next_reloc - start;
}
Пример #4
0
//just cont number of symbols if lm_allocated is false
void init_tape_syms(elf_bf_exec_t *env)
{

  elf_bf_Sym *sym, *psym, *ifunc, *execmap, *ptrtapecpy, *stackaddr, *getchar, *putchar, *ldbase, *libcbase, *execmapvalue, *putcharextra;
  elf_bf_Sym top;
  if (env->ee_lm.lm_allocated){
    psym = calloc(1, sizeof(elf_bf_Sym));
    sym = calloc(1, sizeof(elf_bf_Sym));
    ptrtapecpy = calloc(1, sizeof(elf_bf_Sym));
    ifunc = calloc(1, sizeof(elf_bf_Sym));
    execmap = calloc(1, sizeof(elf_bf_Sym));
    stackaddr = calloc(1, sizeof(elf_bf_Sym));
    ldbase = calloc(1, sizeof(elf_bf_Sym));
    libcbase = calloc(1, sizeof(elf_bf_Sym));
    getchar = calloc(1, sizeof(elf_bf_Sym));
    putchar = calloc(1, sizeof(elf_bf_Sym));
    putcharextra = calloc(1, sizeof(elf_bf_Sym));
    execmapvalue = calloc(1, sizeof(elf_bf_Sym));
  }
  eresi_Addr index = env->ee_num_used_syms;
  //index++;
  //printf("index: %d\n", index);
  //symtab_get_sym(&(env->ee_lm), index++, nsym);
  symtab_get_sym(&(env->ee_lm), index++, psym);
  symtab_get_sym(&(env->ee_lm), index++, sym);
  symtab_get_sym(&(env->ee_lm), index++, ifunc);
  symtab_get_sym(&(env->ee_lm), index++, ptrtapecpy);
  symtab_get_sym(&(env->ee_lm), index++, execmap);
  symtab_get_sym(&(env->ee_lm), index++, stackaddr);
  symtab_get_sym(&(env->ee_lm), index++, ldbase);
  symtab_get_sym(&(env->ee_lm), index++, libcbase);
  symtab_get_sym(&(env->ee_lm), index++, getchar);
  symtab_get_sym(&(env->ee_lm), index++, putchar);
  symtab_get_sym(&(env->ee_lm), index++, putcharextra);
  symtab_get_sym(&(env->ee_lm), index, execmapvalue);

  

  if (env->ee_lm.lm_allocated){
    env->ee_num_used_syms = index;

    symtab_get_sym(&(env->ee_lm), index+1, &top);

    //keeps the tape head symbol number

    //address of where tape head is pointing's value
    symtab_set_sym(psym, 1, top.addr, STT_FUNC);

    //assume tape head value is zero
    symtab_set_sym(sym, 1, 0, STT_FUNC);
    symtab_set_sym(ifunc, 8, 0, STT_GNU_IFUNC);
    //elfsh_set_symbol_link(ifunc->sym, 1);
    symtab_set_sym(ptrtapecpy, 1, symtab_get_value_addr(sym), STT_FUNC);

    //start it up with address of PLTGOT
    elfsh_Dyn *dyn;
    eresi_Addr pltgot;
    dyn = elfsh_get_dynamic_entry_by_type(env->ee_lm.lm_f, DT_PLTGOT);
    pltgot = elfsh_get_dynentry_val(dyn);
    env->ee_dt_pltgot = pltgot+8;
    symtab_set_sym(execmap, 8, pltgot+8, STT_FUNC);


    symtab_set_sym(stackaddr, 8, 0, STT_FUNC);
    symtab_set_sym(ldbase, 8, 0, STT_FUNC);
    symtab_set_sym(libcbase, 8, 0, STT_FUNC);
    symtab_set_sym(getchar, 8, 0, STT_FUNC);
    symtab_set_sym(putchar, 8, 0, STT_FUNC);
    symtab_set_sym(putcharextra, 0, 0, STT_FUNC);  //we jsut want a readable address here
    //printf("ptr_tape_ptr %x, tape_ptr %x, copy %x\n", symtab_get_index(psym), symtab_get_index(sym), symtab_get_index(ptrtapecpy));
    symtab_set_sym(execmapvalue, 8, 0, STT_FUNC);

    //env->ee_tape_symnum = psym->index;
    env->ee_ptr_tape_ptr = psym;
    env->ee_tape_ptr = sym;
    env->ee_lm.lm_ifunc = ifunc;
    env->ee_ptr_tape_copy = ptrtapecpy;
    env->ee_exec_map = execmap;
    env->ee_stack_addr = stackaddr;
    env->ee_ld_base = ldbase;
    env->ee_libc_base = libcbase;
    env->ee_lm.lm_getchar = getchar;
    env->ee_lm.lm_putchar = putchar;
    env->ee_lm.lm_putcharextra = putcharextra;
    env->ee_exec_map_value = execmapvalue;
  }
  env->ee_num_new_syms = index - env->ee_num_used_syms;
}