Ejemplo n.º 1
0
static int prune_hits_in_hit_range(RList *hits, RCoreAsmHit *hit){
	RListIter *iter, *iter_tmp;
	RCoreAsmHit *to_check_hit;
	int result = 0;
	ut64 start_range, end_range;
	if (!hit || !hits) {
		return 0;
	}
	start_range = hit->addr;
	end_range =  hit->addr +  hit->len;
	r_list_foreach_safe (hits, iter, iter_tmp, to_check_hit){
		if (to_check_hit && is_hit_inrange(to_check_hit, start_range, end_range)) {
			IFDBG eprintf ("Found hit that clashed (start: 0x%"PFMT64x
				" - end: 0x%"PFMT64x" ), 0x%"PFMT64x" len: %d (valid: %d 0x%"PFMT64x
				" - 0x%"PFMT64x")\n", start_range, end_range, to_check_hit->addr,
				to_check_hit->len, to_check_hit->valid, to_check_hit->addr,
				to_check_hit->addr+to_check_hit->len);
			// XXX - could this be a valid decode instruction we are deleting?
			r_list_delete (hits, iter);
			//iter->data = NULL;
			to_check_hit = NULL;
			result ++;
		}
	}
	return result;
}
Ejemplo n.º 2
0
static RList *r_debug_native_modules_get (RDebug *dbg) {
	char *lastname = NULL;
	RDebugMap *map;
	RListIter *iter, *iter2;
	RList *list, *last;
	int must_delete;
#if __APPLE__
	list = xnu_dbg_maps (dbg, 1);
	if (list && !r_list_empty (list)) {
		return list;
	}
#endif
#if __WINDOWS__
	list = w32_dbg_modules (dbg);
	if (list && !r_list_empty (list)) {
		return list;
	}
#endif
	list = r_debug_native_map_get (dbg);
	if (!list) {
		return NULL;
	}
	last = r_list_newf ((RListFree)r_debug_map_free);
	if (!last) {
		r_list_free (list);
		return NULL;
	}
	r_list_foreach_safe (list, iter, iter2, map) {
		const char *file = map->file;
		if (!map->file) {
			file = map->file = strdup (map->name);
		}
		must_delete = 1;
		if (file && *file) {
			if (file[0] == '/') {
				if (lastname) {
					if (strcmp (lastname, file)) {
						must_delete = 0;
					}
				} else {
					must_delete = 0;
				}
			}
		}
		if (must_delete) {
			r_list_delete (list, iter);
		} else {
			r_list_append (last, map);
			free (lastname);
			lastname = strdup (file);
		}
	}
	list->free = NULL;
	free (lastname);
	r_list_free (list);
	return last;
}
Ejemplo n.º 3
0
// Below this line are the r_io_zip plugin APIs
static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
	RIODesc *result = NULL;
	RIOZipFileObj *zipFileObj = NULL;

	char *zip_uri = NULL, *zip_filename = NULL, *filename_in_zipfile = NULL;
	if (!r_io_zip_plugin_open (io, file)) {
		return result;
	}

	zip_uri = strdup(file);
	// 1) Tokenize to the '//' and find the base file directory ('/')
	zip_filename = strstr(zip_uri, "//");
	if (zip_filename && zip_filename[2]) {
		if (zip_filename[0] && zip_filename[0] == '/' &&
			zip_filename[1] && zip_filename[1] == '/' ) {
			*zip_filename++ = 0;	
		}
		*zip_filename++ = 0;

		filename_in_zipfile = strstr(zip_filename, "//");
		if (filename_in_zipfile && filename_in_zipfile[2]) {
			// null terminating uri to filename here.
			*filename_in_zipfile++ = 0;
			*filename_in_zipfile++ = 0;
		}
	}

	if (!zip_filename) {// && !filename_in_zipfile) {
		if (zip_uri)
			free(zip_uri);
		eprintf("usage: zip:///path/to/archive//filepath\n");
		eprintf("Archive was not found.\n");

		return result;
	}

	// Failed to find the file name the archive.
	if (!filename_in_zipfile) {
		RList *files = NULL;
		RListIter *iter, *iter_tmp;
		char *name;
		//eprintf("usage: zip:///path/to/archive//filepath\n");
		eprintf("\nFiles in archive\n\n");
		files = r_io_zip_get_files(zip_filename, 0, mode, rw );

		if (files) {
			int i = 0;
			r_list_foreach_safe(files, iter, iter_tmp, name) {
				// XXX - io->printf does not flush
				// io->printf("%s\n", name);
				r_cons_printf("%s\n", name);
				r_cons_flush ();
				free (name);
				r_list_delete (files, iter);
			}
			r_list_free (files);
		}
Ejemplo n.º 4
0
Archivo: list.c Proyecto: jduck/radare2
R_API bool r_list_delete_data(RList *list, void *ptr) {
	void *p;
	RListIter *iter;
	r_list_foreach (list, iter, p) {
		if (ptr == p) {
			r_list_delete (list, iter); //r_list_delete decrements 1 the length
			return true;
		}
	}
	return false;
}
Ejemplo n.º 5
0
Archivo: list.c Proyecto: jduck/radare2
/* remove all elements of a list */
R_API void r_list_purge(RList *list) {
	if (list) {
		RListIter *it = list->head;
		while (it) {
			RListIter *next = it->n;
			r_list_delete (list, it);
			it = next;
		}
		list->head = list->tail = NULL;
	}
}
Ejemplo n.º 6
0
Archivo: list.c Proyecto: 0x2F/radare2
R_API boolt r_list_delete_data (RList *list, void *ptr) {
	void *p;
	RListIter *iter;
	r_list_foreach (list, iter, p) {
		if (ptr == p) {
			r_list_delete (list, iter);
			return R_TRUE;
		}
	}
	return R_FALSE;
}
Ejemplo n.º 7
0
R_API bool r_mixed_change_end(RMixed *m, void *p) {
	int i;
	void *q;
	for (i=0; i<RMIXED_MAXKEYS; i++) {
		if (m->keys[i]) {
			RHashTable *ht = m->keys[i]->hash.ht;
			RHashTable64 *ht64 = m->keys[i]->hash.ht64;
			ut64 newstate = r_mixed_get_value (i, m->keys[i]->size, p);
			if (newstate != m->state[i]) {
				// rehash this pointer
				RListIter *iter;
				RList *list = r_mixed_get (m, i, m->state[i]);
				if (list == NULL) {
					eprintf ("RMixed internal corruption?\n");
					return false;
				}
				/* No _safe loop necessary because we return immediately after the delete. */
				r_list_foreach (list, iter, q) {
					if (q == p) {
						r_list_delete (list, iter);
						break;
					}
				}
				if (r_list_empty (list)) {
					// delete hash entry
					r_list_free (list);
					switch (m->keys[i]->size) {
					case 1: case 2: case 4:
						r_hashtable_remove (ht, m->state[i]);
						break;
					case 8: r_hashtable64_remove (ht64, m->state[i]);
						break;
					}
				}
				switch (m->keys[i]->size) {
				case 1: case 2: case 4:
					list = r_hashtable_lookup (ht, (ut32)newstate);
					if (!list) {
						list = r_list_new ();
						r_hashtable_insert (ht, (ut32)newstate, list);
					}
					r_list_append (list, p);
					break;
				case 8:
					list = r_hashtable64_lookup (ht64, newstate);
					if (!list) {
						list = r_list_new ();
						r_hashtable64_insert (ht64, newstate, list);
					}
					r_list_append (list, p);
					break;
				}
			}
		}
Ejemplo n.º 8
0
R_API int r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char *use_color) {
	int i, delta, from, to, cols, n = 0;
	const char *fmt, *fmt2, *kwhites;
	RPrint *pr = NULL;
	int colwidth = 20;
	RListIter *iter;
	RRegItem *item;
	RList *head;
	ut64 diff;
	char strvalue[256];
	if (!dbg || !dbg->reg) {
		return false;
	}
	if (dbg->corebind.core) {
		pr = ((RCore*)dbg->corebind.core)->print;
	}
	if (size != 0 && !(dbg->reg->bits & size)) {
		// TODO: verify if 32bit exists, otherwise use 64 or 8?
		size = 32;
	}
	if (dbg->bits & R_SYS_BITS_64) {
		//fmt = "%s = 0x%08"PFMT64x"%s";
		fmt = "%s = %s%s";
		fmt2 = "%s%4s%s %s%s";
		kwhites = "         ";
		colwidth = dbg->regcols? 20: 25;
		cols = 3;
	} else {
		//fmt = "%s = 0x%08"PFMT64x"%s";
		fmt = "%s = %s%s";
		fmt2 = "%s%4s%s %s%s";
		kwhites = "    ";
		colwidth = 20;
		cols = 4;
	}
	if (dbg->regcols) {
		cols = dbg->regcols;
	}
	if (rad == 'j') {
		dbg->cb_printf ("{");
	}
	// with the new field "arena" into reg items why need
	// to get all arenas.
	from = 0;
	to = R_REG_TYPE_LAST;

	int itmidx = -1;
	dbg->creg = NULL;
	for (i = from; i < to; i++) {
		head = r_reg_get_list (dbg->reg, i);
		if (!head) {
			continue;
		}
		r_list_foreach (head, iter, item) {
			ut64 value;
			utX valueBig;
			if (type != -1) {
				if (type != item->type && R_REG_TYPE_FLG != item->type) {
					continue;
				}
				if (size != 0 && size != item->size) {
					continue;
				}
			}
			// Is this register being asked?
			if (dbg->q_regs) {
				if (!r_list_empty (dbg->q_regs)) {
					RListIter *iterreg;
					RList *q_reg = dbg->q_regs;
					char *q_name;
					bool found = false;
					r_list_foreach (q_reg, iterreg, q_name) {
						if (!strcmp (item->name, q_name)) {
							found = true;
							break;
						}
					}
					if (!found) {
					        continue;
					}
					r_list_delete (q_reg, iterreg);
				} else {
					// List is empty, all requested regs were taken, no need to go further
					goto beach;
				}
			}