Ejemplo n.º 1
0
void* getNotifier(LPCUSBSIO_I2C_Ctrl_t * dev)
{
    CONTAINER_STATUS lContainerStatus = CONTAINER_SUCCESS;
    uint32_t size = 0x00;
    void* Notifier = NULL;
    if(NULL != dev)
    {
        framework_LockMutex(dev->NotifierContainerLock);
        if(NULL == dev->NotifierContainer)
        {
            lContainerStatus = container_create(&dev->NotifierContainer, 2);
        }
        if (CONTAINER_SUCCESS == lContainerStatus)
        {
            lContainerStatus = container_size(dev->NotifierContainer, &size);
            if(0x00 == size)
            {
                framework_CreateMutex(&Notifier);
            }
            else
            {
                container_remove(dev->NotifierContainer, 0x00, &Notifier);
            }
        }
        framework_UnlockMutex(dev->NotifierContainerLock);
    }
    return Notifier;
}
Ejemplo n.º 2
0
/**
 * Creates function container
 */
container_t	*mjr_create_function_container(mjrcontext_t	*ctx,
					       eresi_Addr	vaddr,
					       u_int		size,
					       char		*name,
					       mjrblock_t	*first,
					       char		*md5)
{
  mjrfunc_t	*newfunction;
  container_t	*newcntnr;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
  
#if __DEBUG_CNTNR__
  newcntnr = mjr_get_container_by_vaddr(ctx, vaddr, ASPECT_TYPE_FUNC);
  if (newcntnr)
    {
      fprintf(D_DESC,"[D] %s: func container addr %x id:%d is there ALREADY\n",
	      __FUNCTION__, vaddr, newcntnr->id);
      PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, newcntnr);
    }
#endif

  /* Allocate the new container and its links lists */
  newfunction = alloca(sizeof(mjrfunc_t));
  bzero(newfunction, sizeof(mjrfunc_t));
  newfunction->vaddr = vaddr;
  newfunction->size  = size;

  /* Create name and md5 string for function */
  if (name)
    strncpy(newfunction->name, (char *) name, sizeof(newfunction->name) - 1);
  if (md5)
    memcpy(newfunction->md5, md5, sizeof(newfunction->md5));

#if __DEBUG_CNTNR__
  fprintf(D_DESC,"[D] %s: create func addr: %x name: <%s> (sz %d) (md5 %s)\n",
	  __FUNCTION__, vaddr, name, size, md5);
#endif

  newcntnr = container_create(ASPECT_TYPE_FUNC, newfunction, NULL, NULL, ctx->obj->id);
  if (!newcntnr)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
		 "Unable to create function container", NULL);  
  mjr_register_container(ctx, newcntnr);  
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, newcntnr);
}
Ejemplo n.º 3
0
/**
 * @brief Creates a block container
 */
container_t	*mjr_create_block_container(mjrcontext_t	*ctx,
					    u_int		symoff,
					    eresi_Addr		vaddr,
					    u_int		size,
					    u_char		seen)
{
  mjrblock_t 	*newblock;
  container_t	*newcntnr;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

#if __DEBUG_CNTNR__
  newcntnr = mjr_get_container_by_vaddr(ctx, vaddr, ASPECT_TYPE_BLOC);
  if (newcntnr)
    {
      fprintf(D_DESC,"[D] %s: block container %x id:%d is there ALREADY\n",
	      __FUNCTION__, vaddr, newcntnr->id);
      PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, newcntnr);
    }
#endif

  newblock         = alloca(sizeof(mjrblock_t));
  bzero(newblock, sizeof(mjrblock_t));
  newblock->symoff = symoff;
  newblock->vaddr  = vaddr;
  newblock->size   = size;
  newblock->seen   = seen;
  newcntnr         = container_create(ASPECT_TYPE_BLOC, newblock, NULL, NULL, ctx->obj->id);
  if (!newcntnr)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
		 "Unable to create block container", NULL);  

#if __DEBUG_CNTNR__
  fprintf(D_DESC, "[D] %s: create block addr " XFMT " (sz %d)\n", __FUNCTION__, vaddr, size);
#endif

  mjr_register_container(ctx, newcntnr);

  /* fill the btree */
  btree_insert_sort(&ctx->block_btree, match_block, newcntnr);
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, newcntnr);
}
Ejemplo n.º 4
0
Archivo: view.c Proyecto: neomutt/arch
VIEW *
view_create (VIEW *v)
{
	if (!v) {
		v = calloc (1, sizeof (VIEW));
		if (!v) {
			return NULL;
		}
	}

	container_create (&v->container);	// Construct parent

	OBJECT *o = &v->container.object;

	o->type     = MAGIC_VIEW;
	o->destroy  = (object_destroy_fn) view_destroy;
	o->display  = (object_display_fn) view_display;

	return v;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
    const char *program = basename(argv[0]);
    int c, opt_index;
    size_t desc_len;
    struct ext4_crypt_options opts = {
        .verbose = false,
        .contents_cipher = "aes-256-xts",
        .filename_cipher = "aes-256-cts",
        .filename_padding = 4,
        .key_descriptor = { 0 },
        .requires_descriptor = true,
    };

    while ( true ) {
        static struct option long_options[] = {
            { "help",         no_argument,        0, 'h' },
            { "verbose",      no_argument,        0, 'v' },
            { "name-padding", required_argument,  0, 'p' },
            { "key-desc",     required_argument,  0, 'd' },
            { 0, 0, 0, 0 },
        };

        c = getopt_long(argc, argv, "hvp:d:", long_options, &opt_index);
        if ( c == -1 )
            break;

        switch ( c ) {
            case 'h':
                usage(program);
                return EXIT_SUCCESS;

            case 'v':
                opts.verbose = true;
                break;

            case 'p':
                opts.filename_padding = atoi(optarg); 
                if ( !is_valid_padding(opts.filename_padding) ) {
                    fprintf(stderr, "Invalid filename padding length: must be 4, 8, 16 or 32\n");
                    return EXIT_FAILURE;
                }
                break;

            case 'd':
                desc_len = strlen(optarg);
                if ( desc_len == 0 || desc_len > sizeof(opts.key_descriptor) ) {
                    fprintf(stderr, "Invalid descriptor %s: must be between 1 and 8 characters.", optarg);
                    return EXIT_FAILURE;
                }

                memcpy(opts.key_descriptor, optarg, desc_len);
                opts.requires_descriptor = false;
                break;

            default:
                usage(program);
                return EXIT_FAILURE;
        }
    }

    if ( optind + 1 >= argc ) {
        usage(program);
        return EXIT_FAILURE;
    }

    int status = 0;
    const char *command = argv[optind];
    const char *dir_path = argv[optind + 1];

    if ( strcmp(command, "help") == 0 ) {
        usage(program);
    }
    else if ( strcmp(command, "status") == 0 ) {
        status = container_status(dir_path);
    }
    else if ( strcmp(command, "create") == 0 ) {
        status = container_create(dir_path, opts);
    }
    else if ( strcmp(command, "attach") == 0 ) {
        status = container_attach(dir_path, opts);
    }
    else if ( strcmp(command, "detach") == 0 ) {
        status = container_detach(dir_path, opts);
    }
    else {
        fprintf(stderr, "Error: unrecognized command %s\n", command);
        usage(program);
        status = -1;
    }

    return (status == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Ejemplo n.º 6
0
/**
 * Reflect command disassemble the block cache of the parameter and create a list of instr exprs
 */
int		cmd_reflect()
{
  container_t	*container;
  container_t	*instrcontainer;
  mjrblock_t	*curblock;
  asm_instr	cur;
  elfsh_Half	machine;
  char		logbuf[BUFSIZ];
  char		logbuf2[BUFSIZ];
  eresi_Addr	addr;
  eresi_Addr	daddr;
  u_int		off;
  int		ret;
  aspectype_t	*curtype;
  void		*blocdata;
  int		fileoff;
  list_t	*instrlist;
  revmexpr_t	*expr;
  u_int		insnbr;
  u_int		reqnbr;
  u_int		readsize;
  revmexpr_t	*immed;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
  curtype  = aspect_type_get_by_name("instr");
  if (!curtype)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                 "Failed reflection : unknown type : instr", -1);

  /* Validate parameters */
  if (world.curjob->curcmd->argc != 1 && world.curjob->curcmd->argc != 2)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                 "Command expect one or two parameters \n", -1);
  
  /* Init proc */
  if (!world.curjob->proc)
    {
      switch (machine = elfsh_get_arch(world.curjob->curfile->hdr))
        {
        case EM_386:
          world.curjob->proc = &world.proc_ia32;
          break;
        case EM_SPARC:
        case EM_SPARC32PLUS:
        case EM_SPARCV9:
          world.curjob->proc = &world.proc_sparc;
          break;
	case EM_ARM:
          world.curjob->proc = &world.proc_arm;
	  break;
	case EM_MIPS:
	case EM_MIPS_RS3_LE:
          world.curjob->proc = &world.proc_mips;
	  break;
        default:
          snprintf(logbuf, sizeof (logbuf),
                   "Architecture %s not supported. No disassembly available\n",
                   elfsh_get_machine_string(machine));
          revm_output(logbuf);
          PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
        }
    }

  /* Now lookup the block by its addr or symbol */
  immed = revm_lookup_param(world.curjob->curcmd->param[0], 1);
  if (!immed)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                 "Failed to lookup parameter address expr", -1);
  if (revm_convert_object(immed, ASPECT_TYPE_CADDR) < 0)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Invalid address parameter", 0);
  addr = (immed->value->immed ? immed->value->immed_val.ent : 
	  immed->value->get_obj(immed->value->parent));

  /* Analyse the binary if not already done */
  /*
  if (!world.mjr_session.cur->analysed)
    {
      maxdepth = (int) config_get_data(CONFIG_CFGDEPTH);
      ret = mjr_analyse(&world.mjr_session,
                        world.curjob->curfile->hdr->e_entry,
                        maxdepth, 0);
      if (ret < 0)
        PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                     "Failed analyzing current object", -1);
    }
  */

  /* One more param enables lightweight mode: lookup data from a binary file section - no CFG needed */
  if (world.curjob->curcmd->argc == 2)
    {
      immed = revm_lookup_param(world.curjob->curcmd->param[1], 1);
      if (revm_convert_object(immed, ASPECT_TYPE_INT) < 0)
	PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Invalid size parameter", 0);
      reqnbr = (immed->value->immed ? (u_int) immed->value->immed_val.ent : 
		(u_int) immed->value->get_obj(immed->value->parent));
      if (reqnbr <= 0)
	PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
		     "Invalid instruction number to reflect", -1);
      readsize = 16 * reqnbr;
      blocdata = alloca(readsize);
    }

  /* Only one param (an addr/symbol) --> Lookup data from a basic block on the CFG */
  else
    {
      container = mjr_block_get_by_vaddr(world.mjr_session.cur, addr, MJR_BLOCK_GET_STRICT);
      if (!container)
	PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
		     "Failed to find bloc at this virtual address", -1);
      curblock = (mjrblock_t *) container->data;
      readsize = curblock->size;
      blocdata = alloca(readsize);
      reqnbr = 0;
    }

  /* Read data -- could be imported from a remote process, so needs to copy buffer */
  fileoff = elfsh_get_foffset_from_vaddr(world.curjob->curfile, addr);
  if (elfsh_readmemf(world.curjob->curfile, fileoff, blocdata, readsize) != readsize)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
		 "Failed to read data to reflect", -1);

  /* Create the new list of instructions in expression form */
  XALLOC(__FILE__, __FUNCTION__, __LINE__, instrlist, sizeof(list_t), -1);
  snprintf(logbuf2, sizeof(logbuf2), AFMT, addr);
  elist_init(instrlist, strdup(logbuf2), ASPECT_TYPE_EXPR);

  /* Reflection all instructions of the basic bloc in the list */
  for (insnbr = off = 0; off < readsize; off += ret, insnbr++)      
    {

      /* If reached the number of requested instruction, stop now even without reaching buffer end */
      if (reqnbr && insnbr == reqnbr)			
	break;

      /* Fetch the current instruction */
      ret = asm_read_instr(&cur, (u_char *) blocdata + off,
                           readsize - off + 10, world.curjob->proc);
      if (ret < 0)
        {
          elist_destroy(instrlist);
          PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                       "Unable to fetch code for basic bloc", -1);
        }

      /* Also add the instruction to the current reflected list for this block */
      instrcontainer = container_create(curtype->type, (void *) &cur, NULL, NULL, 0);
      snprintf(logbuf, sizeof (logbuf), "$instr-"XFMT, addr + off);
      daddr = (eresi_Addr) instrcontainer;
      expr = revm_inform_type_addr(curtype->name, strdup(logbuf), daddr, NULL, 0, 1);
      elist_add(instrlist, strdup(logbuf), expr);
    }

  /* Reverse instrlist and add it to the hash of lists */
  instrlist = elist_reverse(instrlist);
  hash_add(&instrlists_hash, strdup(logbuf2), instrlist);

  /* Printing message if we are not in quiet mode */
  if (!world.state.revm_quiet)
    {
      snprintf(logbuf, sizeof(logbuf),
               " [*] Code at address " AFMT " reflected succesfully (%u instrs) \n\n",
               addr, insnbr);
      revm_output(logbuf);
    }

  /* Put the current bloc in the last result variable */
  /*
  revm_expr_destroy_by_name(REVM_VAR_RESULT);
  revm_expr_copy(expr, REVM_VAR_RESULT);
  */

  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}