R_API bool r_oids_sort (ROIDStorage *storage, void *user) { ut32 od, id, ptop, *permutation; void *incoming; if(!storage || !storage->ptop || !storage->cmp) { return false; } if(storage->ptop == 1) { return true; } permutation = storage->permutation; storage->permutation = R_NEWS0 (ut32, storage->psize); if (!storage->permutation) { storage->permutation = permutation; return false; } storage->permutation[0] = permutation[0]; ptop = storage->ptop; storage->ptop = 1; while (storage->ptop != ptop) { id = permutation[storage->ptop]; incoming = r_id_storage_get (storage->data, id); if (!oids_od_binsert (storage, id, &od, incoming, user)) { goto beach; } } free (permutation); return true; beach: free (storage->permutation); storage->permutation = permutation; storage->ptop = ptop; return false; }
R_API int r_core_lines_initcache(RCore *core, ut64 start_addr, ut64 end_addr) { int i, line_count; int bsz = core->blocksize; char *buf; ut64 off = start_addr; ut64 baddr; if (start_addr == UT64_MAX || end_addr == UT64_MAX) { return -1; } free (core->print->lines_cache); core->print->lines_cache = R_NEWS0 (ut64, bsz); if (!core->print->lines_cache) { return -1; } { RIOSection *s = r_io_section_mget_in (core->io, core->offset); baddr = s? s->paddr: r_config_get_i (core->config, "bin.baddr"); } line_count = start_addr? 0: 1; core->print->lines_cache[0] = start_addr? 0: baddr; buf = malloc (bsz); if (!buf) { return -1; } r_cons_break_push (NULL, NULL); while (off < end_addr) { if (r_cons_is_breaked ()) { break; } r_io_read_at (core->io, off, (ut8 *) buf, bsz); for (i = 0; i < bsz; i++) { if (buf[i] == '\n') { core->print->lines_cache[line_count] = start_addr? off + i + 1: off + i + 1 + baddr; line_count++; if (line_count % bsz == 0) { ut64 *tmp = realloc (core->print->lines_cache, (line_count + bsz) * sizeof (ut64)); if (tmp) { core->print->lines_cache = tmp; } else { R_FREE (core->print->lines_cache); goto beach; } } } } off += bsz; } free (buf); r_cons_break_pop (); return line_count; beach: free (buf); r_cons_break_pop (); return -1; }
static ut8 *get_bytes(RBuffer *buffer, ut32 size) { ut8 *ret = R_NEWS0 (ut8, size + 1); if (!ret) return NULL; if (r_buf_read (buffer, ret, size) < size) { free (ret); return NULL; } return ret; }