Logo Search packages:      
Sourcecode: eresi version File versions  Download package

char* revm_resolve ( elfshobj_t file,
eresi_Addr  addr,
elfsh_SAddr *  roffset 
)

Resolve symbol in one file or all (mapped) if we are in e2dbg Runtime compatible.

Parameters:
file 
addr 
roffset 
Returns:

Definition at line 24 of file disasm.c.

References buf, s_listent::data, elfsh_is_debug_mode(), elfsh_reverse_dynsymbol(), elfsh_reverse_symbol(), s_listent::key, s_obj::linkmap, s_obj::name, s_listent::next, and strcmp().

Referenced by asm_do_resolve(), cmd_delete(), cmd_got(), and e2dbg_do_breakpoint().

{
  listent_t *ent;
  int       index;
  elfshobj_t      *actual;
  char            *name = NULL;
  char            *dname = NULL;
  elfsh_SAddr     offset = 0;
  elfsh_SAddr     doffset = 0;
  char            *bestname = NULL;
  elfsh_SAddr     bestoffset;
  elfshobj_t      *bestfile;
  char            buf[BUFSIZ];
  char            *str;


  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

  if (!file)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                  "Invalid NULL argument", NULL);

  actual = file;
  name = elfsh_reverse_symbol(actual, addr, &offset);
  dname = elfsh_reverse_dynsymbol(actual, addr, &doffset);

  if (!name || (dname && !strcmp(name, ELFSH_SECTION_NAME_PLT)) || 
      (offset < 0) || (dname && doffset < offset && doffset >= 0))
    {
      name = dname;
      offset = doffset;
    }  
  
  bestname = name;
  bestoffset = offset;
  bestfile = actual;
  

#if __DEBUG_RESOLVE__
  printf("[elfsh:resolve] file : %s name %s %d\n", actual->name, name, offset);
#endif
  
  /* Find the best symbol by searching in all the objects of the process */
  if (world.state.revm_mode == REVM_STATE_DEBUGGER)
      for (index = 0; index < world.curjob->loaded.size; index++)
      for (ent = &world.curjob->loaded.ent[index];
           ent != NULL && ent->key != NULL;
           ent = ent->next)
        {
          actual = ent->data;
          if (!actual->linkmap)
            continue;
          
          name = elfsh_reverse_symbol(actual, addr, &offset);
          dname = elfsh_reverse_dynsymbol(actual, addr, &doffset);
          
          if (!name || (offset < 0) || 
            (dname && doffset < offset && doffset >= 0))
            {
            name = dname;
            offset = doffset;
            }  
          
          if (!bestname || 
            (bestoffset < 0) || (name && offset < bestoffset && offset >= 0))
            {
            bestname = name;
            bestoffset = offset;
            bestfile = actual;
            }
          
#if __DEBUG_RESOLVE__
          printf("[elfsh:resolve] file : %s name %s %d\n", 
               actual->name, name, offset);
#endif
        }
  
#if __DEBUG_RESOLVE__
  printf("[elfsh:resolve] BEST name %s %d\n", bestname, bestoffset);
#endif

  if (roffset)
    *roffset = bestoffset;
  
  if (bestname == NULL)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                  "Unable to resolve best name", (NULL));

  if (elfsh_is_debug_mode())
    {
      str = revm_basename(bestfile->name);
      snprintf(buf, BUFSIZ, "%s@%s", 
             bestname, (str ? str : "CORRUPTED"));
    }
  else
    snprintf(buf, BUFSIZ, "%s", bestname);
  
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, strdup(buf));
 
}


Generated by  Doxygen 1.6.0   Back to index