Example #1
0
int		cmd_configure()
{
    configitem_t *ci;
    int		cnt;
    int		idx;
    char		**tab;

    PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

    /* We list the configuration */
    if (world.curjob->curcmd->argc < 2)
    {
        tab = hash_get_keys(&aspectworld.config_hash, &cnt);

        printf(" [*] Configure parameters\n\n");

        for (idx = 0; idx < cnt; idx++)
        {
            ci = hash_get(&aspectworld.config_hash, tab[idx]);

            if (ci->type == CONFIG_TYPE_INT)
                printf(" [+] (%2s) %-30s : %d\n",
                       (ci->mode == CONFIG_MODE_RW) ? "RW" : "RO",
                       ci->name, ci->val);

            if (ci->type == CONFIG_TYPE_STR)
                printf(" [+] (%2s) %-30s : %s\n",
                       (ci->mode == CONFIG_MODE_RW) ? "RW" : "RO",
                       ci->name, (char *) ci->data);
        }
        printf("\n");
    }

    /* We change a configuration option */
    else
    {
        ci = hash_get(&aspectworld.config_hash, world.curjob->curcmd->param[0]);

        if (ci != NULL)
        {
            if (ci->mode == CONFIG_MODE_RO)
                PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                             "Cannot update a READONLY key", (-1));

            if (ci->type == CONFIG_TYPE_INT)
                config_update_key(ci->name,
                                  (void *) atoi(world.curjob->curcmd->param[1]));

            if (ci->type == CONFIG_TYPE_STR)
                config_update_key(ci->name,
                                  (void *) world.curjob->curcmd->param[1]);

            printf(" [*] setting new configuration value for %s to %s\n\n",
                   world.curjob->curcmd->param[0],
                   world.curjob->curcmd->param[1]);
        }
        else
            PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                         "Configuration key not found.", (-1));
    }

    PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}
Example #2
0
/* Check a hash */
int		cmd_kmem_chash()
{
  int	i, ret, mode, stype, type, nsize, size, off, origmode, val;
  char  buff[BUFSIZ], buff2[256];
  char	*param, *str;
  unsigned long addr;
  revmexpr_t *expr;
  revmobj_t *obj;

  unsigned char origbuffer[BUFSIZ];
  char	buffhash[BUFSIZ];
  unsigned char *hashbuffer;
  char *tmp;

  FILE *fd;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
  
  val = 0;
  memset(buff, '\0', sizeof(buff));
  memset(buff2, '\0', sizeof(buff2));

  param = world.curjob->curcmd->param[0];

  stype = (int)config_get_data(LIBKERNSH_CONFIG_HASH);

  if (param != NULL)
    {
      expr = revm_lookup_param(param, 1);
      obj = expr->value;

      if (obj->otype->type == ASPECT_TYPE_STR)
	{
	  str = (obj->immed ? obj->immed_val.str : 
		 obj->get_name(obj->root, obj->parent));
	  
	  memcpy(buff2, str, sizeof(buff2));
	  param = buff2;
	}

      /* We must get hash in a file ? */
      if (!strstr(param, ":"))
	{
	  fd = fopen(param, "r");
	  if (fd == NULL)
	    {
	      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
			   "Unable to open file",
			   -1);
	    }

	  while(fgets(buff, sizeof(buff), fd) != NULL)
	    {
	      buff[strlen(buff) - 1] = '\0';
	      
	      if (buff[0] == '#')
		continue;

	      if (extract_info(buff, 
			       &addr, 
			       &mode,
			       &type,
			       &size, 
			       &off, 
			       origbuffer, 
			       sizeof(origbuffer)))
		{
		  
		  PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
			       "Bad format", -1);
		}
	      /* Switch to the mode where the hash has been done */
	      origmode = elfsh_get_mode();
	      elfsh_set_mode(mode);

	      config_update_key(LIBKERNSH_CONFIG_HASH, (void *)type);
	      hashbuffer = kernsh_hash(addr+off, size, &nsize);	      
	      	      
	      elfsh_set_mode(origmode);

	      i = 0;
	      tmp = buffhash;
	      while((i < sizeof(buffhash)) && (hashbuffer[i] != '\0'))
		{
		  sprintf(tmp, "%02x", hashbuffer[i]);
		  i++;
		  tmp += 2;
		}

	      memset(buff, '\0', sizeof(buff));
	      
	      if (!strncmp((const char *)origbuffer, 
			   (const char *)buffhash, 
			   sizeof(origbuffer)))
		{
		  snprintf(buff, sizeof(buff),
			   "%s @ %s with size = %s and offset = %s\n",
			   revm_colorstr("HASH MATCH @ !"),
			   revm_coloraddress(XFMT, (eresi_Addr) addr),
			   revm_colornumber("%u", size),
			   revm_colornumber("%u", off));
		  revm_output(buff);
		  revm_endline();
		}
	      else
		{
		  snprintf(buff, sizeof(buff),
			   "%s @ %s with size = %s and offset = %s\n %s != %s\n",
			   revm_colorstr("HASH MISMATCH @ !"),
			   revm_coloraddress(XFMT, (eresi_Addr) addr),
			   revm_colornumber("%u", size),
			   revm_colornumber("%u", off),
			   revm_colorstr((char *)origbuffer),
			   revm_colorstr((char *)buffhash));
		  revm_output(buff);
		  revm_endline();
		  val++;
		}
	    }

	  fclose(fd);
	}
      else
	{
	  if (extract_info(param, 
			   &addr, 
			   &mode,
			   &type,
			   &size, 
			   &off, 
			   origbuffer, 
			   sizeof(origbuffer)))
	  {
	    
	    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
			 "Bad format", -1);
	  }

	  origmode = elfsh_get_mode();
	  elfsh_set_mode(mode);
	  config_update_key(LIBKERNSH_CONFIG_HASH, (void *)type);
	  hashbuffer = kernsh_hash(addr+off, size, &nsize);

	  elfsh_set_mode(origmode);
	  i = 0;
	  tmp = buffhash;
	  while((i < sizeof(buffhash)) && (hashbuffer[i] != '\0'))
	    {
	      sprintf(tmp, "%02x", hashbuffer[i]);
	      i++;
	      tmp += 2;
	    }

	  if (hashbuffer == NULL)
	    {
	      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
			   "Unable to make hash", -1);
	    }

	  memset(buff, '\0', sizeof(buff));

	  if (!strncmp((const char *)origbuffer, 
		       (const char *)buffhash, 
		       sizeof(origbuffer)))
	    {
	      snprintf(buff, sizeof(buff),
		       "%s @ %s with size = %s and offset = %s\n\n",
		       revm_colorstr("HASH MATCH @ !"),
		       revm_coloraddress(XFMT, (eresi_Addr) addr),
		       revm_colornumber("%u", size),
		       revm_colornumber("%u", off));
	      revm_output(buff);
	    }
	  else
	    {
	      snprintf(buff, sizeof(buff),
		       "%s @ %s with size = %s and offset = %s\n %s != %s\n\n",
		       revm_colorstr("HASH MISMATCH @ !"),
		       revm_coloraddress(XFMT, (eresi_Addr) addr),
		       revm_colornumber("%u", size),
		       revm_colornumber("%u", off),
		       revm_colorstr((char *)origbuffer),
		       revm_colorstr((char *)buffhash));
	      revm_output(buff);
	      val++;
	    }
	}
    }

  config_update_key(LIBKERNSH_CONFIG_HASH, (void *)stype);

  revm_setvar_int(REVM_VAR_RESULT, val);  

  revm_endline();
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, ret);
}
Example #3
0
/** 
 * @brief Functions to turn off safemode 
 */
void	config_safemode_reset()
{
  config_update_key(CONFIG_NAME_SAFEMODE,
		    (void *) CONFIG_SAFEMODE_OFF);
}
Example #4
0
/**
 * set config flag to specified endian
 * @param mode endian (big/little)
 */
void asm_config_set_endian(int mode)
{
  config_update_key(CONFIG_ASM_ENDIAN_FLAG,(void *) mode);
}