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

int revm_file_load ( char *  name,
eresi_Addr  base,
elfshlinkmap_t lm 
)

Load a file in elfsh

Parameters:
name 
base 
lm 
Returns:

Definition at line 98 of file load.c.

References elfsh_init_symbol_hashtables(), elfsh_is_debug_mode(), elfsh_map_obj(), s_revm_object::immed_val, mjr_blocks_get(), mjr_create_context_as_current(), mjr_functions_get(), mjr_setup_processor(), s_hash::name, revm_load_enumdep(), revm_load_init_dephash(), revm_output(), and s_revm_expr::value.

Referenced by cmd_load().

{
  elfshobj_t      *new;
  revmexpr_t      *expr;
  revmobj_t *tmp;
  char            logbuf[BUFSIZ];
  char            *timec;
  hash_t    *filehash;
  
  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);  
  if (!name)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
             "Invalid argument", -1);

  /* Reset the id counter in case we have unloaded all our files */
  filehash = hash_find("files");
  if (!hash_size(filehash))
    world.state.lastid = 0;
  
  /* Map the standard ELF object */
  new = elfsh_map_obj(name);
  if (NULL == new)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
             "Cannot load object", -1);
  
  /* Print a msg if not in quiet mode */
  new->loadtime = time(&new->loadtime);
  if (!world.state.revm_quiet)
    {
      timec = ctime(&new->loadtime);
      timec[strlen(timec) - 1] = '\0';
      snprintf(logbuf, BUFSIZ - 1, " [*] %s - New object loaded : %s\n",
             timec , name);
      revm_output(logbuf);
    }
  
  /* Set base address */
  new->rhdr.base = base;
  
  /* Set linkmap address */
  if (new->hdr->e_type != ET_CORE)
    new->linkmap = lm;
  else 
    new->linkmap = NULL;
  
  /* Add the object to the list of opened objects */
  new->id = ++world.state.lastid;
  world.curjob->curfile = new;
  expr = revm_expr_get(REVM_VAR_LOAD);
  if (!expr || !expr->value)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
             "TROUBLE : Last loaded file inexistant", -1);
  tmp = expr->value;
  tmp->immed_val.word = new->id;
  
  /* Support shared objects */
  if (world.state.revm_shared)
    hash_add(&world.shared_hash, new->name, new);
  else
    hash_add(&world.curjob->loaded, new->name, new);
  
  /* Add an entry into the loaded files hashtable */
  hash_add(&file_hash, new->name, (void *) new);

  /* Init hash dep */
  revm_load_init_dephash(new, name);
  
  if (new->hdr->e_type == ET_CORE) 
    {
      hash_add(&new->root_hash, new->name, new);
      PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
    }
  
  /* Create libmjollnir context for this binary */
  mjr_create_context_as_current(&world.mjr_session, new);
  mjr_setup_processor(&world.mjr_session);

  /* Init search hash tables */
  elfsh_init_symbol_hashtables(new);

  /* Parse debugging informations */
  revm_edfmt_parse(new);

  /* Load dependances */
  if (new->hdr->e_type == ET_EXEC)
    hash_add(&new->root_hash, new->name, new);
  
  /* We use a different dependences technique for mapped files 
     in the debugger. Just load dependences here for unmapped files */
  if (!elfsh_is_debug_mode())
    revm_load_enumdep(new);
  
  /* Load EDFMT debug sections */
  if ((int) config_get_data(ERESI_VMCONFIG_ONLOAD_RCONTROL)) 
    {
      if (mjr_functions_get(world.mjr_session.cur) < 0)
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                 "Analyzed functions edfmt section cannot be restored", -1);
      if (mjr_blocks_get(world.mjr_session.cur) < 0)
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                 "Analyzed blocks edfmt section cannot be restored", -1);
    }
  
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}


Generated by  Doxygen 1.6.0   Back to index