diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index 30029597b6..d049e0044b 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -107,6 +107,24 @@ static int init_hdr(struct MACH0_(obj_t)* bin) { "xxxxddx " "magic cputype cpusubtype filetype ncmds sizeofcmds flags", 0); sdb_num_set (bin->kv, "mach0_header.offset", 0, 0); // wat about fatmach0? + sdb_set (bin->kv, "mach_filetype.cparse", "enum mach_filetype{MH_OBJECT=1," + "MH_EXECUTE=2, MH_FVMLIB=3, MH_CORE=4, MH_PRELOAD=5, MH_DYLIB=6," + "MH_DYLINKER=7, MH_BUNDLE=8, MH_DYLIB_STUB=9, MH_DSYM=10," + "MH_KEXT_BUNDLE=11}" + ,0); + sdb_set (bin->kv, "mach_flags.cparse", "enum mach_flags{MH_NOUNDEFS=1," + "MH_INCRLINK=2,MH_DYLDLINK=4,MH_BINDATLOAD=8,MH_PREBOUND=0x10," + "MH_SPLIT_SEGS=0x20,MH_LAZY_INIT=0x40,MH_TWOLEVEL=0x80," + "MH_FORCE_FLAT=0x100,MH_NOMULTIDEFS=0x200,MH_NOFIXPREBINDING=0x400," + "MH_PREBINDABLE=0x800, MH_ALLMODSBOUND=0x1000," + "MH_SUBSECTIONS_VIA_SYMBOLS=0x2000," + "MH_CANONICAL=0x4000,MH_WEAK_DEFINES=0x8000," + "MH_BINDS_TO_WEAK=0x10000,MH_ALLOW_STACK_EXECUTION=0x20000," + "MH_ROOT_SAFE=0x40000,MH_SETUID_SAFE=0x80000," + "MH_NO_REEXPORTED_DYLIBS=0x100000,MH_PIE=0x200000," + "MH_DEAD_STRIPPABLE_DYLIB=0x400000," + "MH_HAS_TLV_DESCRIPTORS=0x800000," + "MH_NO_HEAP_EXECUTION=0x1000000 }",0); if (len == -1) { eprintf ("Error: read (hdr)\n"); return false; diff --git a/libr/core/cmd_type.c b/libr/core/cmd_type.c index 13a6da53a2..d82a28ff8a 100644 --- a/libr/core/cmd_type.c +++ b/libr/core/cmd_type.c @@ -107,7 +107,21 @@ static int cmd_type(void *data, const char *input) { case 'e': { if (!input[1]) { - eprintf ("Missing value\n"); + char *name = NULL; + SdbKv *kv; + SdbListIter *iter; + SdbList *l = sdb_foreach_list (core->anal->sdb_types); + ls_foreach (l, iter, kv) { + if (!strcmp (kv->value, "enum")) { + if (!name || strcmp (kv->value, name)) { + free (name); + name = strdup (kv->key); + r_cons_printf ("%s\n", name); + } + } + } + free (name); + ls_free (l); break; } char *p, *s = strdup (input+2); @@ -125,7 +139,8 @@ static int cmd_type(void *data, const char *input) { eprintf ("This is not an enum\n"); } } else { - eprintf ("Missing value\n"); + //eprintf ("Missing value\n"); + r_core_cmdf (core, "t~&%s,=0x", s); } free (s); } @@ -186,8 +201,7 @@ static int cmd_type(void *data, const char *input) { "Usage:", "td[...]", "", "td", "[string]", "Load types from string", NULL - }; - + }; r_core_cmd_help(core, help_message); } else if (input[1] == '-') { diff --git a/libr/core/core.c b/libr/core/core.c index 9b0e21476f..aa390cbf3f 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -487,6 +487,26 @@ static int autocomplete(RLine *line) { line->completion.argc = j; line->completion.argv = tmp_argv; } else + if ((!strncmp (line->buffer.data, "te ", 3))) { + int i = 0; + SdbList *l = sdb_foreach_list (core->anal->sdb_types); + SdbListIter *iter; + SdbKv *kv; + tmp_argv_heap = true; + int chr = 3; + ls_foreach (l, iter, kv) { + int len = strlen (line->buffer.data + chr); + if (!len || !strncmp (line->buffer.data + chr, kv->key, len)) { + if (!strncmp (kv->value, "0x", 2)) { + tmp_argv[i++] = strdup (kv->key); + } + } + } + tmp_argv[i] = NULL; + ls_free (l); + line->completion.argc = i; + line->completion.argv = tmp_argv; + } else if ((!strncmp (line->buffer.data, "o ", 2)) || !strncmp (line->buffer.data, "o+ ", 3) || !strncmp (line->buffer.data, "oc ", 3) || @@ -524,7 +544,7 @@ openfile: r_sys_getdir (); p = (char *)r_str_lchr (path, '/'); if (p) { - if (p==path) { // ^/ + if (p == path) { // ^/ isroot = 1; *p = 0; p++;