예제 #1
0
파일: record.C 프로젝트: Zirkon/dyninst
bool record_create(record_t *record, const char *prog, int argc, char **argv)
{
    char hash_buf[SHA1_STRING_LEN];
    const char *prog_bin = prog;
    unsigned i;

    record_clear(record);

    if (strrchr(prog, '/'))
	prog_bin = strrchr(prog, '/') + 1;

    if (!sha1_file(prog, hash_buf)) return false;
    strlist_push_back(&record->prog_line, prog_bin);
    strlist_push_back(&record->prog_line, sha1_file(prog, hash_buf));
    for (i = 0; i < (unsigned)argc; ++i)
	strlist_push_back(&record->prog_line, argv[i]);

    strlist lib_list = STRLIST_INITIALIZER;
    get_libs(&lib_list, prog);
    for (i = 0; i < lib_list.count; ++i) {
	const char *lib_path = strlist_get(&lib_list, i);

	if (!sha1_file(lib_path, hash_buf)) continue;
	strlist_push_back(&record->lib_line, lib_path);
	strlist_push_back(&record->lib_line, sha1_file(lib_path, hash_buf));
    }

    record->enabled = true;
    return true;
}
예제 #2
0
/* FIXME: Test with reduced features! */
static char *lib_list(const struct manifest *m)
{
	unsigned int i, num;
	char **libs;
	char *ret = talloc_strdup(m, "");

	libs = get_libs(m, m->dir, &num,
			&m->info_file->compiled[COMPILE_NORMAL]);
	for (i = 0; i < num; i++)
		ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
	return ret;
}
예제 #3
0
static char *example_lib_list(const void *ctx, struct manifest **deps)
{
	char *list = tal_strdup(ctx, "");
	char **libs;
	unsigned int i, j;

	/* FIXME: This doesn't uniquify. */
	for (i = 0; i < tal_count(deps); i++) {
		libs = get_libs(ctx, deps[i]->dir, NULL, get_or_compile_info);
		for (j = 0; libs[j]; j++)
			tal_append_fmt(&list, "-l%s ", libs[j]);
	}
	return list;
}
예제 #4
0
static void
do_install_admin_nogimpui (const gchar *what)
{
  do_build_2 (get_cflags (), get_libs (), get_sys_plugin_dir (TRUE), what);
}
예제 #5
0
static void
do_install (const gchar *what)
{
  do_build_2 (get_cflags (), get_libs (), get_user_plugin_dir (FALSE), what);
}
예제 #6
0
static void
do_build (const gchar *what)
{
  do_build_2 (get_cflags (), get_libs (), NULL, what);
}
예제 #7
0
static void
do_libs (void)
{
  g_print ("%s\n", get_libs ());
}
예제 #8
0
int main(int ac, char *av[])
{
  /* create .preloader directory */
  char path[500];
  sprintf( path, "%s/.preloader", getenv("HOME") );
  if( mkdir( path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) < 0 )  /* mkdir failed */
    if( errno !=  EEXIST ) {
      fprintf( stderr, "error: failed to create %s!\n", path );
      exit( 0 );
    }


  CTX ctx;
  memset( &ctx, 0, sizeof( ctx ) );

  snprintf( ctx.filename,
            sizeof( ctx.filename ),
            "%s%s", *av[1] == '/' || *av[1] == '.' ? "" : "./",
            av[1] );

  _init_display();
  ctx.state = STATE_PROCESSING_SYMS;

  ctx.db = database_init();
  ctx.hash = database_add_target( ctx.db, ctx.filename ); /* add target to db */

  /* get symbols from target target */
  int fd = open( av[1], O_RDONLY );
  DYNSYM *ds = get_dynsyms( fd, DYNSYM_UNDEFINED_ONLY );
  close( fd );

  /* add symbols to db */
  DYNSYM *p_ds = ds;
  while( p_ds ) {
    ctx.extra = p_ds->name;
    _draw_display( &ctx );
    database_add_symbol( ctx.db, p_ds->name );
    p_ds = p_ds->nxt;
  }

  ctx.state = STATE_PROCESSING_LIBS;

  /* add libs to db */
  LL *lib_sym_info = ll_calloc();

  LIBS *libs = get_libs(ctx.filename);
  LIBS *p_libs = libs;
  while( p_libs ) {
    ctx.extra = p_libs->path;
    _draw_display( &ctx );
    database_add_lib( ctx.db, p_libs->name, p_libs->path );

    p_libs = p_libs->nxt;
  }

  ctx.state = STATE_RESOLVING_SYMBOLS;
  /* match symbols to libs */
  /* immensely inefficient, should call get_dynsyms() ONCE for each lib!! (TODO) */
  p_ds = ds;
  while( p_ds ) {   /* for each symbol in target */
    int found = 0;

    ctx.extra = p_ds->name;
    _draw_display( &ctx );

    LIBS *p_lib = libs;
    while( p_lib && !found ) {  /* search each lib for match */

      int fd_lib = open( p_lib->path, O_RDONLY );
      DYNSYM *ds_lib = get_dynsyms( fd_lib, DYNSYM_DEFINED_ONLY );    /* get symbols from lib */

      DYNSYM *p_ds_lib = ds_lib;
      while( p_ds_lib ) { /* for each symbol in library */
        if( strcmp( p_ds_lib->name, p_ds->name ) == 0 ) {
          database_link_sym_lib( ctx.db, p_ds->name, p_lib->path );
          found = 1;
          break;
        }
        p_ds_lib = p_ds_lib->nxt;   /* move to next symbol in library */
      }
      free_dynsyms( ds_lib );

      close( fd_lib );

      p_lib = p_lib->nxt;   /* move to next library */
    }

    p_ds = p_ds->nxt; /* move to next symbol */
  }

  ll_free( lib_sym_info );

  free_libs( libs );

  free_dynsyms( ds );

  // TODO iter through and free free_dynsyms( ds_lib );

  _populate_symbol_list( ctx.db, &ctx.symbols );

  ctx.state = STATE_NORMAL;
  ctx.running = 1;

  while( ctx.running ) {
    usleep(1000);

    _draw_display( &ctx );
    _parse_input( &ctx );
  }

  _disable_display();

  database_kill( ctx.db );

  /* free symbol list */
  ll_free( ctx.symbols.func );
  ll_free( ctx.symbols.sig );

  return 0;
}