Пример #1
0
void enum_files_in_dir(const char* path, callback_fn cb, void *param)
{
	assert(path);
#ifdef _WIN32
	strbuf tmp=STRBUF_INIT;
	strbuf_addf (&tmp, "%s\\*", path);
	struct _finddata_t d;
	int fh=_findfirst(tmp.buf, &d);
	assert(fh!=-1);
	strbuf tmp2=STRBUF_INIT;

	do
	{
		if (strcasecmp(d.name, ".")==0)
			continue;
		
		strbuf_reinit(&tmp2, 0);
		strbuf_addf (&tmp2, "%s\\%s", path, d.name);

		cb (d.name, tmp2.buf, d.size, d.time_write, IS_SET(d.attrib, _A_SUBDIR), param);

	} while (_findnext(fh, &d)==0);

	_findclose (fh);
	strbuf_deinit(&tmp2);
	strbuf_deinit (&tmp);
#elif defined(__linux__) || defined(__CYGWIN__) || defined (__APPLE__)
	DIR* DIR_V = opendir(path);
	struct dirent* t = NULL;
	if (DIR_V==NULL)
		die ("opendir(%s) failed: %s\n", path, strerror(errno));

	strbuf tmp2=STRBUF_INIT;

	while ((t=readdir(DIR_V))!=NULL)
	{
		if (strcasecmp(t->d_name, ".")==0)
			continue;
		
		strbuf_reinit(&tmp2, 0);
		strbuf_addf (&tmp2, "%s/%s", path, t->d_name);
		struct stat st;
		if (stat (tmp2.buf, &st)==-1)
			die ("stat(%s) failed: %s\n", tmp2.buf, strerror(errno));
// conflict with c99...
#ifndef DT_DIR
#define DT_DIR 4
#endif
		cb (t->d_name, tmp2.buf, st.st_size, st.st_mtime, IS_SET(t->d_type, DT_DIR), param);
	};
	
	strbuf_deinit(&tmp2);
	closedir(DIR_V);
#else
#warning "undetermined compiler"
#endif
};
Пример #2
0
static void dump_stack_EBP_frame (process *p, thread *t, CONTEXT * ctx, MemoryCache *mem)
{
    HANDLE THDL=t->THDL;
    address stack_top=TIB_get_stack_top (THDL, mem);
    address stack_bottom=TIB_get_stack_bottom (THDL, mem);
    strbuf sb=STRBUF_INIT;

    L ("Call stack:\n");

    address next_BP=CONTEXT_get_BP (ctx);

    if (TIB_is_ptr_in_stack_limits (THDL, next_BP, mem)==false)
    {
        L ("Current frame pointer %s (0x" PRI_ADR_HEX ") is not within current stack limits (top=0x" PRI_ADR_HEX ", bottom=0x" PRI_ADR_HEX ")\n", 
                BP_REGISTER_NAME,
                CONTEXT_get_BP (ctx), stack_top, stack_bottom);
        goto exit;
    };

    while (next_BP<=stack_top && next_BP>=stack_bottom)
    {
        REG tmp;
        bool b=MC_ReadREG(mem, next_BP, &tmp);
        oassert (b);
        address ret_adr;
        b=MC_ReadREG(mem, next_BP+sizeof(REG), &ret_adr);
        oassert (b);

        if (ret_adr==0)
            break;

        strbuf_reinit(&sb, 0);
        process_get_sym (p, ret_adr, true, true, &sb);

        L ("return address=0x" PRI_ADR_HEX " (%s)\n", ret_adr, sb.buf);

        if (next_BP==tmp)
            break;
        
        next_BP=tmp;
    };

exit:
    strbuf_deinit (&sb);
};
Пример #3
0
void dump_buf_as_array_of_strings(MemoryCache *mc, address a, size_t size)
{
    strbuf sb=STRBUF_INIT;
    BYTE *buf=DMALLOC (BYTE, size, "BYTE*");
    if (MC_ReadBuffer (mc, a, size, buf)==false)
        goto exit;
    for (unsigned i=0; i<size; i+=sizeof(REG))
    {
        address a2=*(REG*)&buf[i];
        if (MC_get_any_string(mc, a2, &sb))
        {
            L ("0x" PRI_ADR_HEX "+0x%x: ptr to %s\n", a, i, sb.buf);
            strbuf_reinit(&sb, 0);
        };
    };
exit:
    DFREE (buf);
    strbuf_deinit(&sb);
};