static RList* entries(RBinArch *arch) { RBinAddr *ptr; RList *ret = r_list_new (); if (!ret) return NULL; ret->free = free; if (!(ptr = R_NEW (RBinAddr))) return ret; memset (ptr, '\0', sizeof (RBinAddr)); ptr->offset = ptr->rva = r_bin_java_get_entrypoint (arch->bin_obj); r_list_append (ret, ptr); return ret; }
static RBinAddr* binsym(RBinFile *arch, int type) { RBinAddr *ret = NULL; switch (type) { case R_BIN_SYM_MAIN: if (!(ret = R_NEW (RBinAddr))) return NULL; memset (ret, '\0', sizeof (RBinAddr)); ret->offset = ret->rva = r_bin_te_get_main_offset (arch->o->bin_obj); break; } return ret; }
R_API RAnalOp *r_anal_op_copy (RAnalOp *op) { RAnalOp *nop = R_NEW (RAnalOp); *nop = *op; nop->mnemonic = strdup (op->mnemonic); nop->src[0] = r_anal_value_copy (op->src[0]); nop->src[1] = r_anal_value_copy (op->src[1]); nop->src[2] = r_anal_value_copy (op->src[2]); nop->dst = r_anal_value_copy (op->dst); r_strbuf_init (&nop->esil); r_strbuf_set (&nop->esil, r_strbuf_get (&op->esil)); return nop; }
R_API RSyscall* r_syscall_new() { RSyscall *rs = R_NEW (RSyscall); if (rs) { rs->fd = NULL; rs->sysptr = NULL; //syscalls_linux_x86; rs->sysport = sysport_x86; rs->syspair = NULL; rs->printf = (PrintfCallback)printf; rs->regs = fastcall_x86; } return rs; }
R_API struct r_th_lock_t *r_th_lock_new() { RThreadLock *thl = R_NEW(RThreadLock); if (thl) { thl->refs = 0; #if HAVE_PTHREAD pthread_mutex_init (&thl->lock, NULL); #elif __WIN32__ //thl->lock = CreateSemaphore(NULL, 0, 1, NULL); InitializeCriticalSection(&thl->lock); #endif } return thl; }
R_API RThreadLock *r_th_lock_new() { RThreadLock *thl = R_NEW(RThreadLock); if (thl) { thl->refs = 0; #if HAVE_PTHREAD pthread_mutex_init (&thl->lock, NULL); #elif __WIN32__ || __WINDOWS__ && !defined(__CYGWIN__) //thl->lock = CreateSemaphore(NULL, 0, 1, NULL); InitializeCriticalSection(&thl->lock); #endif } return thl; }
static RList* entries(RBinFile *arch) { RList* ret = r_list_new ();; RBinAddr *ptr = NULL; if (!ret) return NULL; ret->free = free; if (!memcmp (arch->buf+0x30, "\x00\x00\x00\x00\x20\x73\x74\x64\x6f\x75\x74\x20\x21\x55\x0c\xcd", 16)) { if ((ptr = R_NEW (RBinAddr))) { ptr->rva = ptr->offset = 0x9a; r_list_append (ret, ptr); } } return ret; }
static RBinAddr* binsym(RBinArch *arch, int sym) { ut64 addr; RBinAddr *ret = NULL; switch (sym) { case R_BIN_SYM_MAIN: addr = MACH0_(r_bin_mach0_get_main) (arch->bin_obj); if (!addr || !(ret = R_NEW (RBinAddr))) return NULL; memset (ret, '\0', sizeof (RBinAddr)); ret->offset = ret->rva = addr; break; } return ret; }
R_API RAnalOp *r_anal_op_new() { RAnalOp *op = R_NEW (RAnalOp); if (op) { memset (op, 0, sizeof (RAnalOp)); op->mnemonic = NULL; op->addr = -1; op->jump = -1; op->fail = -1; op->ref = -1; op->value = -1; op->next = NULL; } return op; }
static RList* entries(RBinArch *arch) { RList *ret; RBinAddr *ptr = NULL; if (!(ret = r_list_new ())) return NULL; ret->free = free; if (!(ptr = R_NEW (RBinAddr))) return ret; memset (ptr, '\0', sizeof (RBinAddr)); ptr->offset = ptr->rva = 0xffff0; r_list_append (ret, ptr); return ret; }
R_API RStrpool* r_strpool_new (int sz) { RStrpool *p = R_NEW (RStrpool); if (!p) return NULL; if (sz<1) sz = 1024; p->size = sz; p->len = 0; p->str = malloc (sz); if (!p->str) { free (p); return NULL; } p->str[0] = 0; return p; }
static RList* lines(RBinArch *arch) { int i; char *file = strdup (arch->file); RList *list = r_list_new (); RBinJavaObj *b = arch->bin_obj; file = r_str_replace (file, ".class", ".java", 0); for (i=0; i<b->lines.count; i++) { RBinDwarfRow *row = R_NEW (RBinDwarfRow); r_bin_dwarf_line_new (row, b->lines.addr[i], file, b->lines.line[i]); r_list_append (list, row); } free (file); return list; }
static RList* entries(RBinFile *arch) { RList* ret; RBinAddr *ptr = NULL; if (!(ret = r_list_new ())) return NULL; ret->free = free; if ((ptr = R_NEW (RBinAddr))) { ptr->paddr = 8*4; ptr->vaddr = 8*4;// + baddr (arch); r_list_append (ret, ptr); } return ret; }
static RIODesc *w32__open(RIO *io, const char *pathname, int rw, int mode) { if (!memcmp (pathname, "w32://", 6)) { RIOW32 *w32 = R_NEW (RIOW32); const char *filename= pathname+6; w32->hnd = CreateFile (filename, GENERIC_READ | rw?GENERIC_WRITE:0, FILE_SHARE_READ | rw?FILE_SHARE_WRITE:0, NULL, OPEN_ALWAYS, 0, NULL); if (w32->hnd != INVALID_HANDLE_VALUE) return r_io_desc_new (&r_io_plugin_w32, getw32fd (w32), pathname, rw, mode, w32); free (w32); } return NULL; }
R_API RAnalBlock *r_anal_bb_new() { RAnalBlock *bb = R_NEW (RAnalBlock); if (!bb) return NULL; memset (bb, 0, sizeof (RAnalBlock)); bb->addr = -1; bb->jump = -1; bb->fail = -1; bb->type = R_ANAL_BB_TYPE_NULL; #if R_ANAL_BB_HAS_OPS bb->ops = r_anal_op_list_new (); #endif bb->cond = NULL; bb->fingerprint = NULL; bb->diff = r_anal_diff_new (); return bb; }
static RIODesc *shm__open(RIO *io, const char *pathname, int rw, int mode) { if (!memcmp (pathname, "shm://", 6)) { RIOShm *shm = R_NEW (RIOShm); const char *ptr = pathname+6; shm->id = getshmid (ptr); shm->buf = shmat (shm->id, 0, 0); shm->fd = getshmfd (shm); shm->size = SHMATSZ; if (shm->fd != -1) { eprintf ("Connected to shared memory 0x%08x\n", shm->id); return r_io_desc_new (&r_io_plugin_shm, shm->fd, pathname, rw, mode, shm); } eprintf ("Cannot connect to shared memory (%d)\n", shm->id); free (shm); } return NULL; }
static RList* entries(RBinFile *arch) { RList *ret = r_list_new (); RBinAddr *ptr = NULL; if (arch && arch->buf != NULL) { if (!ret) return NULL; ret->free = free; if (!(ptr = R_NEW (RBinAddr))) return ret; memset (ptr, '\0', sizeof (RBinAddr)); ptr->offset = ptr->rva = 0x100; r_list_append (ret, ptr); } return ret; }
R_API RSocket *r_socket_new (int is_ssl) { RSocket *s = R_NEW (RSocket); s->is_ssl = is_ssl; #if HAVE_LIB_SSL if (is_ssl) { s->sfd = NULL; s->ctx = NULL; s->bio = NULL; if (!SSL_library_init ()) { r_socket_free (s); return NULL; } SSL_load_error_strings (); } #endif return s; }
static RList* entries(RBinFile *arch) { RList* ret = r_list_new ();; RBinAddr *ptr = NULL; RRarBinObj *bin_obj = arch && arch->o ? arch->o->bin_obj : NULL; const ut8 *buf = bin_obj ? r_buf_buffer (bin_obj->buf) : NULL; ut64 sz = arch && bin_obj ? r_buf_size (bin_obj->buf) : 0; if (!ret) return NULL; ret->free = free; if (bin_obj && sz > 0x30 && !memcmp (buf+0x30, RAR_CONST, 16)) { if ((ptr = R_NEW (RBinAddr))) { ptr->vaddr = ptr->paddr = 0x9a; r_list_append (ret, ptr); } } return ret; }
static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) { if (__plugin_open (io, file, 0)) { char *pidpath; RIOW32Dbg *dbg = R_NEW (RIOW32Dbg); if (dbg == NULL) return NULL; dbg->pid = atoi (file+9); if (__attach (dbg) == -1) { free (dbg); return NULL; } pidpath = r_sys_pid_to_path (dbg->pid); RETURN_IO_DESC_NEW (&r_io_plugin_w32dbg, -1, pidpath, rw | R_IO_EXEC, mode, dbg); } return NULL; }
R_API struct r_io_t *r_io_new() { RIO *io = R_NEW (RIO); if (!io) return NULL; io->fd = NULL; io->write_mask_fd = -1; io->redirect = NULL; io->printf = (void*) printf; io->plugin = NULL; io->raised = -1; r_io_cache_init (io); r_io_map_init (io); r_io_section_init (io); r_io_plugin_init (io); r_io_desc_init (io); r_io_undo_init (io); return io; }
R_API RDebugMap *r_debug_map_new (char *name, ut64 addr, ut64 addr_end, int perm, int user) { RDebugMap *map; if (name == NULL || addr >= addr_end) { eprintf ("r_debug_map_new: error assert(%"PFMT64x">=%"PFMT64x")\n", addr, addr_end); return NULL; } map = R_NEW (RDebugMap); if (map) { map->name = strdup (name); map->addr = addr; map->addr_end = addr_end; map->size = addr_end-addr; map->perm = perm; map->user = user; } return map; }
SdbHash* ht_new(void) { SdbHash *ht = R_NEW (SdbHash); if (!ht) return NULL; // TODO: use slices here ht->list = ls_new (); ht->size = hash_sizes[0].size; ht->table = calloc (ht->size, sizeof (*ht->table)); if (!ht->table) { free (ht); return NULL; } ht->size_index = 0; ht->entries = 0; ht->deleted_entries = 0; ht->rehash = hash_sizes[ht->size_index].rehash; ht->max_entries = hash_sizes[ht->size_index].max_entries; return ht; }
static RList* entries(RBinFile *arch) { RList* ret; RBinAddr *ptr = NULL; struct r_bin_te_addr_t *entry = NULL; if (!(ret = r_list_new ())) return NULL; ret->free = free; if (!(entry = r_bin_te_get_entrypoint (arch->o->bin_obj))) return ret; if ((ptr = R_NEW (RBinAddr))) { ptr->paddr = entry->paddr; ptr->vaddr = entry->vaddr; r_list_append (ret, ptr); } free (entry); return ret; }
RAnalType* new_array_node(char* name, short type, short sign, short modifier, long size) { RAnalTypeArray *iarr = R_NEW (RAnalTypeArray); RAnalType *tmp; iarr->name = name; iarr->count = size; iarr->type = (type & R_ANAL_VAR_TYPE_SIZE_MASK) | ((sign << R_ANAL_VAR_TYPE_SIGN_SHIFT) & R_ANAL_VAR_TYPE_SIGN_MASK) | ((modifier << R_ANAL_VAR_TYPE_MODIFIER_SHIFT) & R_ANAL_VAR_TYPE_MODIFIER_MASK); tmp = R_NEW0 (RAnalType); tmp->next = NULL; tmp->type = R_ANAL_TYPE_ARRAY; tmp->custom.a = iarr; // FIXME: Temporary hack to use global variable // Need to remove that in next release // and provide proper way to handle global tree // outside from this file return tmp; }
R_API RMemoryPool *r_mem_pool_new(int nodesize, int poolsize, int poolcount) { RMemoryPool *mp = R_NEW (RMemoryPool); if (mp) { if (poolsize<1) poolsize = ALLOC_POOL_SIZE; if (poolcount<1) poolcount = ALLOC_POOL_COUNT; // TODO: assert nodesize?; mp->poolsize = poolsize; mp->poolcount = poolcount; mp->nodesize = nodesize; mp->npool = -1; mp->ncount = mp->poolsize; // force init mp->nodes = (ut8**) malloc (sizeof (void*) * mp->poolcount); if (mp->nodes == NULL) return NULL; } return mp; }
SDB_API SdbListIter *ls_prepend(SdbList *list, void *data) { SdbListIter *it = R_NEW (SdbListIter); if (!it) { return NULL; } if (list->head) { list->head->p = it; } it->data = data; it->n = list->head; it->p = NULL; list->head = it; if (!list->tail) { list->tail = it; } list->length++; list->sorted = false; return it; }
static RList* entries(RBinArch *arch) { RList *ret; RBinAddr *ptr = NULL; struct r_bin_mach0_addr_t *entry = NULL; if (!(ret = r_list_new ())) return NULL; ret->free = free; if (!(entry = MACH0_(r_bin_mach0_get_entrypoint) (arch->bin_obj))) return ret; if ((ptr = R_NEW (RBinAddr))) { memset (ptr, '\0', sizeof (RBinAddr)); ptr->offset = entry->offset; ptr->rva = entry->addr; r_list_append (ret, ptr); } free (entry); return ret; }
static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) { char *pidpath; int ret = -1; if (__plugin_open (io, file,0)) { int pid = atoi (file+9); ret = ptrace (PTRACE_ATTACH, pid, 0, 0); if (file[0]=='p') //ptrace ret = 0; else if (ret == -1) { #ifdef __ANDROID__ eprintf ("ptrace_attach: Operation not permitted\n"); #else switch (errno) { case EPERM: ret = pid; eprintf ("ptrace_attach: Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; } #endif } else if (__waitpid (pid)) ret = pid; else eprintf ("Error in waitpid\n"); if (ret != -1) { RIODesc *desc; RIOPtrace *riop = R_NEW (RIOPtrace); riop->pid = riop->tid = pid; open_pidmem (riop); pidpath = r_sys_pid_to_path (pid); desc = r_io_desc_new (&r_io_plugin_ptrace, pid, pidpath, R_TRUE, mode, riop); free (pidpath); return desc; } } return NULL; }
R_API int r_mixed_key(RMixed *m, int key, int size) { if (size>0 && r_mixed_key_check (m, key, size)) { if (m->keys[key]) { m->keys[key]->size = size; } else { m->keys[key] = R_NEW (RMixedData); if (!m->keys[key]) return false; m->keys[key]->size = size; switch (size) { case 1: case 2: case 4: m->keys[key]->hash.ht = r_hashtable_new (); return true; case 8: m->keys[key]->hash.ht64 = r_hashtable64_new (); return true; } } } return false; }