示例#1
0
文件: xrefs.c 项目: XVilka/radare2
R_API bool r_anal_xrefs_init(RAnal *anal) {
	sdb_reset (DB);
	if (DB) {
		sdb_array_set (DB, "types", -1, "code.jmp,code.call,data.mem,data.string", 0);
		return true;
	}
	return false;
}
示例#2
0
static void r_anal_emul_restore(RCore *core, bool *state) {
	sdb_reset (core->anal->esil->db_trace);
	r_config_set_i (core->config, "esil.romem", state[ROMEM]);
	r_config_set_i (core->config, "asm.trace", state[ASM_TRACE]);
	r_config_set_i (core->config, "anal.trace", state[ANAL_TRACE]);
	r_config_set_i (core->config, "dbg.trace", state[DBG_TRACE]);
	r_config_set_i (core->config, "esil.nonull", state[NONULL]);
}
示例#3
0
R_API int r_meta_del(RAnal *a, int type, ut64 addr, ut64 size, const char *str) {
	char key[100], *dtr, *s, *p, *next;
#if 0
	char key2[100];
#endif
	const char *ptr;
	int i;
	if (size == UT64_MAX) {
		// FULL CLEANUP
		// XXX: this thing ignores the type
		if (type == R_META_TYPE_ANY) {
			sdb_reset (DB);
		} else {
			snprintf (key, sizeof (key)-1, "meta.%c.count", type);
			int last = (ut64)sdb_num_get (DB, key, NULL)/K;
			for (i=0; i<last; i++) {
				snprintf (key, sizeof (key)-1, "meta.%c.%d", type, i);
				dtr = sdb_get (DB, key, 0);
				for (p = dtr; p; p = next) {
					s = sdb_anext (p, &next);
					snprintf (key, sizeof (key)-1,
						"meta.%c.0x%"PFMT64x,
						type, sdb_atoi (s));
					eprintf ("--> %s\n", key);
					sdb_unset (DB, key, 0);
					if (!next) break;
				}
				free (dtr);
			}
		}
		return false;
	}
	meta_inrange_del (a, addr, size);
	snprintf (key, sizeof (key)-1, type == R_META_TYPE_COMMENT ?
		"meta.C.0x%"PFMT64x : "meta.0x%"PFMT64x, addr);
	ptr = sdb_const_get (DB, key, 0);
	if (ptr) {
		sdb_unset (DB, key, 0);
		#if 0
		// This code is wrong, but i guess it's necessary in case type is ANY
		for (i=0; ptr[i]; i++) {
			if (ptr[i] != SDB_RS) {
				snprintf (key2, sizeof (key2)-1,
					"meta.%c.0x%"PFMT64x, ptr[i], addr);
					printf ("UNSET (%s)\n", key2);
				sdb_unset (DB, key2, 0);
			}
		}
		#endif
	}
	sdb_unset (DB, key, 0);
	return false;
}
示例#4
0
int sdb_init( sdb_table_t *tbl, const char *persistId, const char *path, size_t n_columns, const char *colnames[]) {
    enum sdb_storage_kind_t storage_kind = persistId==NULL ? SDB_SK_RAM : SDB_SK_RAM ;  //TODO when Flash support
    int i;
    int r = sdb_initwithoutcolumns( tbl, persistId, path, n_columns, storage_kind);
    if( SDB_EOK != r) return r;
   	for(i=0; i< n_columns; i++) {
        r = addcolumn( tbl, colnames[i]);
        if( r) { sdb_reset( tbl); return r; }
    }

    if( tbl->state != SDB_ST_READING) return SDB_EINTERNAL;
    return SDB_EOK;
}
示例#5
0
static Sdb *openDatabase(Sdb *db, const char *name) {
	char *file = r_str_newf ("%s/%s/%s.sdb",
		r_sys_prefix (NULL), "share/radare2/last", name);
	if (r_file_exists (file)) {
		if (db) {
			sdb_reset (db);
			sdb_open (db, file);
		} else {
			db = sdb_new (0, file, 0);
		}
	}
	free (file);
	return db;
}
示例#6
0
static Sdb *openDatabase(Sdb *db, const char *name) {
#define SYSCALLPATH "/share/radare2/" R2_VERSION
	const char *file = sdb_fmt (0, "%s/%s/%s.sdb",
		r_sys_prefix (NULL), SYSCALLPATH, name);
	if (!r_file_exists (file)) {
	//	eprintf ("r_syscall_setup: Cannot find '%s'\n", file);
		return false;
	}
	if (!db) {
		return sdb_new (0, file, 0);
	}
	sdb_reset (db);
	sdb_open (db, file);
	return db;
}
示例#7
0
R_API void r_anal_esil_stats(RAnalEsil *esil, int enable) {
	if (enable) {
		if (esil->stats) 
			sdb_reset (esil->stats);
		else esil->stats = sdb_new0();
		// reset sdb->stats
		esil->cb.hook_reg_read = hook_reg_read;
		esil->cb.hook_mem_read = hook_mem_read;
		esil->cb.hook_mem_write = hook_mem_write;
		esil->cb.hook_reg_write = hook_reg_write;
		esil->cb.hook_flag_read = hook_flag_read;
		esil->cb.hook_command = hook_command;
	} else {
		esil->cb.hook_mem_write = NULL;
		esil->cb.hook_flag_read = NULL;
		esil->cb.hook_command = NULL;
		sdb_free (esil->stats);
		esil->stats = NULL;
	}
}
示例#8
0
文件: sign.c 项目: kolen/radare2
R_API bool r_sign_delete(RAnal *a, const char *name) {
	struct ctxDeleteCB ctx;
	char k[R_SIGN_KEY_MAXSZ];

	// Remove all zigns
	if (name[0] == '*') {
		if (a->zign_spaces.space_idx == -1) {
			sdb_reset (a->sdb_zigns);
			return true;
		} else {
			ctx.anal = a;
			serializeKey (a, a->zign_spaces.space_idx, "", ctx.buf);
			sdb_foreach (a->sdb_zigns, deleteBySpaceCB, &ctx);
			return true;
		}
	}

	// Remove specific zign
	serializeKey (a, a->zign_spaces.space_idx, name, k);
	return sdb_remove (a->sdb_zigns, k, 0);
}
示例#9
0
文件: meta.c 项目: KarjamP/radare2
R_API int r_meta_del(RAnal *a, int type, ut64 addr, ut64 size, const char *str) {
	char key[100], key2[100], *dtr, *s, *p, *next;
	const char *ptr;
	int i;
	if (size == UT64_MAX) {
		// FULL CLEANUP
		// XXX: this thing ignores the type
		if (type == R_META_TYPE_ANY) {
			sdb_reset (DB);
		} else {
			snprintf (key, sizeof (key)-1, "meta.%c", type);
			dtr = sdb_get (DB, key, 0);
			for (p = dtr; p; p = next) {
				s = sdb_anext (p, &next);
				snprintf (key, sizeof (key)-1,
					"meta.%c.0x%"PFMT64x,
					type, sdb_atoi (s));
				eprintf ("--> %s\n", key);
				sdb_unset (DB, key, 0);
				if (!next) break;
			}
			free (dtr);
		}
		return R_FALSE;
	}
	meta_inrange_del (a, addr, size);
	snprintf (key, sizeof (key)-1, type==R_META_TYPE_COMMENT ? "meta.C.0x%"PFMT64x : "meta.0x%"PFMT64x, addr);
	ptr = sdb_const_get (DB, key, 0);
	if (ptr) {
		for (i=0; ptr[i]; i++) {
			if (ptr[i] != SDB_RS) {
				snprintf (key2, sizeof (key2)-1,
					"meta.%c.0x%"PFMT64x, ptr[i], addr);
				sdb_unset (DB, key2, 0);
			}
		}
	}
	sdb_unset (DB, key, 0);
	return R_FALSE;
}
示例#10
0
static int cmd_meta_lineinfo(RCore *core, const char *input) {
	int ret;
	ut64 offset = UT64_MAX; // use this as error value
	int remove = R_FALSE;
	int all = R_FALSE;
	const char *p = input;
	char *colon, *space, *file_line = 0;

	if (*p == '?') {
		eprintf ("Usage: CL[-][*] [file:line] [addr]");
		return 0;
	}

	if (*p == '-') {
		p++;
		remove = R_TRUE;
	}

	if (*p == '*') {
		p++;
		all = R_TRUE;
	}

	if (all) {
		if (remove) {
			sdb_reset (core->bin->cur->sdb_addrinfo);
		} else {
			sdb_foreach (core->bin->cur->sdb_addrinfo, print_addrinfo, NULL);
		}
		return 0;
	}

	while (*p == ' ') {
		p++;
	}

	if (*p) {
		offset = r_num_math (core->num, p);
		if (!offset)
			offset = core->offset;
	} else offset = core->offset;
	colon = strchr (p, ':');
	if (colon) {
		space = strchr (p, ' ');
		if (!space) {
			file_line = strdup (p);
		} else if (space > colon) {
			file_line = r_str_ndup (p, space - p);
		} else {
			goto error;
		}

		colon = strchr (file_line, ':');
		if (!colon)
			goto error;
		*colon = '|';

		while (*p != ' ')
			p++;

		while (*p == ' ')
			p++;

		if (*p != '\0') {
			ret = sscanf (p, "0x%"PFMT64x, &offset);

			if (ret != 1) {
				eprintf ("Failed to parse addr at %s\n", p);
				goto error;
			}

			ret = cmd_meta_add_fileline (core->bin->cur->sdb_addrinfo,
					file_line, offset);

			goto error;
		}

		if (!file_line)
			return -1;

		if (remove) {
			remove_meta_fileline (core, file_line);
		} else {
			print_meta_fileline (core, file_line);
		}

		free (file_line);
		return 0;
	}
	offset = core->offset;

	if (offset != UT64_MAX) {
		if (remove) {
			remove_meta_offset (core, offset);
		} else {
			print_meta_offset (core, offset);
		}
	} else {
		goto error;
	}
	return 0;

error:
	free (file_line);
	return -1;
}
示例#11
0
文件: debug.c 项目: Kakkoroid/radare2
R_API void r_debug_tracenodes_reset (RDebug *dbg) {
	sdb_foreach (dbg->tracenodes, (SdbForeachCallback)free_tracenodes_entry, dbg);
	sdb_reset (dbg->tracenodes);
}
示例#12
0
R_API bool r_syscall_setup(RSyscall *s, const char *arch, const char *os, int bits) {
	const char *file;
	if (!os || !*os) {
		os = R_SYS_OS;
	}
	if (!arch) {
		arch = R_SYS_ARCH;
	}
	free (s->os);
	s->os = strdup (os);

	if (!strcmp (os, "any")) { // ignored
		return true;
	}
	if (!strcmp (arch, "mips")) {
		s->regs = fastcall_mips;
	} else if (!strcmp (arch,"avr")) {
		s->sysport = sysport_avr;
	} else if (!strcmp (arch,"sh")) {
		s->regs = fastcall_sh;
	} else if (!strcmp (arch, "arm")) {
		switch (bits) {
		case 16:
		case 32:
			s->regs = fastcall_arm;
			break;
		case 64:
			s->regs = fastcall_arm64;
			break;
		}
	} else if (!strcmp (arch, "x86")) {
		s->sysport = sysport_x86;
		switch (bits) {
		case 8:
			s->regs = fastcall_x86_8;
			break;
		case 32:
			s->regs = fastcall_x86_32;
			break;
		case 64:
			s->regs = fastcall_x86_64;
			break;
		}
	}

#define SYSCALLPATH R2_PREFIX "/share/radare2/" R2_VERSION "/syscall"
	file = sdb_fmt (0, "%s/%s-%s-%d.sdb",
		SYSCALLPATH, os, arch, bits);
	if (!r_file_exists (file)) {
		// eprintf ("r_syscall_setup: Cannot find '%s'\n", file);
		return false;
	}

	//eprintf ("DBG098: syscall->db must be reindexed for k\n");
	sdb_close (s->db);
	sdb_reset (s->db);
	sdb_open (s->db, file);
//	s->db = sdb_new (0, file, 0);
#if 1
	if (s->fd) {
		fclose (s->fd);
	}
	s->fd = NULL;
#endif
	return true;
}
示例#13
0
文件: hint.c 项目: xarkes/radare2
R_API void r_anal_hint_clear(RAnal *a) {
	sdb_reset (a->sdb_hints);
}
示例#14
0
// mysdb :reset()
static int api_reset( lua_State *L) {
    int r = sdb_reset( lua_sdb_checktable( L, 1));
    if( r) return push_sdb_error( L, r);
    return 1; // push table back
}
示例#15
0
文件: meta.c 项目: skuater/radare2
R_API int r_meta_del(RAnal *a, int type, ut64 addr, ut64 size) {
	char key[100], *dtr, *s, *p, *next;
	const char *val;
	int i;
	if (size == UT64_MAX) {
		// FULL CLEANUP
		// XXX: this thing ignores the type
		if (type == R_META_TYPE_ANY) {
			sdb_reset (DB);
		} else {
			snprintf (key, sizeof (key)-1, "meta.%c.count", type);
			int last = (ut64)sdb_num_get (DB, key, NULL)/K;
			for (i=0; i<last; i++) {
				snprintf (key, sizeof (key)-1, "meta.%c.%d", type, i);
				dtr = sdb_get (DB, key, 0);
				for (p = dtr; p; p = next) {
					s = sdb_anext (p, &next);
					snprintf (key, sizeof (key)-1,
						"meta.%c.0x%"PFMT64x,
						type, sdb_atoi (s));
					sdb_unset (DB, key, 0);
					if (!next) break;
				}
				free (dtr);
			}
		}
		return false;
	}
	if (type == R_META_TYPE_ANY) {
		/* special case */
		r_meta_del (a, R_META_TYPE_COMMENT, addr, size);
		r_meta_del (a, R_META_TYPE_VARTYPE, addr, size);
	}
	if (type == R_META_TYPE_COMMENT || type == R_META_TYPE_VARTYPE) {
		snprintf (key, sizeof (key)-1, "meta.%c.0x%"PFMT64x, type, addr);
	} else {
		snprintf (key, sizeof (key)-1, "meta.0x%"PFMT64x, addr);
	}
	meta_inrange_del (a, addr, size);
	val = sdb_const_get (DB, key, 0);
	if (val) {
		if (type == R_META_TYPE_ANY) {
			char item_key[100];
			const char *ptr = val;
			while (*ptr) {
				snprintf (item_key, sizeof (item_key), "meta.%c.0x%" PFMT64x, *ptr, addr);
				sdb_unset (DB, item_key, 0);
				ptr++;
				if (*ptr) {
					ptr++;
				}
			}
			sdb_unset (DB, key, 0);
			return false;
		}
		if (strchr (val, ',')) {
			char type_fld[] = "##";
			if (val[0] == type) {
				type_fld[0] = type;
				type_fld[1] = ',';
			} else {
				type_fld[0] = ',';
				type_fld[1] = type;
			}
			sdb_uncat (DB, key, type_fld, 0);
		} else {
			sdb_unset (DB, key, 0);
		}
		snprintf (key, sizeof (key), "meta.%c.0x%" PFMT64x, type, addr);
		sdb_unset (DB, key, 0);
	}
	sdb_unset (DB, key, 0);
	return false;
}