* Fix OS identification in ELF on r_bin

* Add missing OSABI definitions
* Fix r_str_case()
* Remove already defined or useless commented config code from r1
This commit is contained in:
pancake 2011-09-08 15:10:46 +02:00
parent aebf800b8e
commit 1732541915
6 changed files with 26 additions and 52 deletions

2
TODO
View File

@ -5,6 +5,8 @@
====[[ 0.9 ]]====
* Fix identification of OS.. which is not OSABI
- more work maybe?
* Test r_search_delta()
* libmagic internal :? -- find a decent implementation and adopt it

View File

@ -494,8 +494,18 @@ int Elf_(r_bin_elf_get_bits)(struct Elf_(r_bin_elf_obj_t) *bin) {
}
}
static inline int needle(struct Elf_(r_bin_elf_obj_t) *bin, const char *s) {
return r_mem_mem ((const ut8*)bin->shstrtab, bin->shstrtab_size,
(const ut8*)s, strlen (s)) != NULL;
}
// TODO: must return const char * all those strings must be const char os[LINUX] or so
char* Elf_(r_bin_elf_get_osabi_name)(struct Elf_(r_bin_elf_obj_t) *bin) {
/* Hack to identify OS */
if (needle (bin, "openbsd")) return strdup ("openbsd");
if (needle (bin, "netbsd")) return strdup ("netbsd");
if (needle (bin, "freebsd")) return strdup ("freebsd");
if (needle (bin, "GNU")) return strdup ("linux");
// XXX: this is wrong. openbsd bins are identified as linux ones.
switch (bin->ehdr.e_ident[EI_OSABI]) {
case ELFOSABI_NONE: return strdup ("linux"); // sysv
@ -510,6 +520,7 @@ char* Elf_(r_bin_elf_get_osabi_name)(struct Elf_(r_bin_elf_obj_t) *bin) {
case ELFOSABI_MODESTO: return strdup ("modesto");
case ELFOSABI_OPENBSD: return strdup ("openbsd");
case ELFOSABI_STANDALONE: return strdup ("standalone");
case ELFOSABI_ARM_AEABI:
case ELFOSABI_ARM: return strdup ("arm");
default: return r_str_dup_printf ("<unknown: %x>", bin->ehdr.e_ident[EI_OSABI]);
}

View File

@ -174,6 +174,8 @@ typedef struct
#define ELFOSABI_HPUX 1 /* HP-UX */
#define ELFOSABI_NETBSD 2 /* NetBSD. */
#define ELFOSABI_LINUX 3 /* Linux. */
#define ELFOSABI_HURD 4 /* GNU/HURD */
#define ELFOSABI_86OPEN 5 /* 86open */
#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */
#define ELFOSABI_AIX 7 /* IBM AIX. */
#define ELFOSABI_IRIX 8 /* SGI Irix. */
@ -181,6 +183,8 @@ typedef struct
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */
#define ELFOSABI_MODESTO 11 /* Novell Modesto. */
#define ELFOSABI_OPENBSD 12 /* OpenBSD. */
#define ELFOSABI_OPENVMS 13 /* OpenVMS */
#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
#define ELFOSABI_ARM 97 /* ARM */
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */

View File

@ -389,6 +389,7 @@ R_API int r_core_config_init(RCore *core) {
r_config_set (cfg, "asm.lbytes", "true");
r_config_set (cfg, "asm.middle", "false"); // jump in the middle because of antidisasm tricks
r_config_set (cfg, "asm.comments", "true");
r_config_set (cfg, "asm.case", "false");
r_config_set (cfg, "asm.stackptr", "true");
r_config_set (cfg, "asm.dwarf", "false");
r_config_set_i (cfg, "asm.nbytes", 8);
@ -405,7 +406,6 @@ R_API int r_core_config_init(RCore *core) {
r_config_set (cfg, "asm.lineswide", "false");
r_config_set_i_cb (cfg, "asm.lineswidth", 10, &config_asmlineswidth_callback);
r_config_set (cfg, "asm.linescall", "false");
r_config_set (cfg, "asm.offset", "true");
r_config_set_cb (cfg, "asm.os", R_SYS_OS, &config_asmos_callback);
r_config_set (cfg, "asm.pseudo", "false"); // DEPRECATED ???
r_config_set_cb (cfg, "asm.syntax", "intel", &config_asmsyntax_callback);
@ -493,20 +493,12 @@ R_API int r_core_config_init(RCore *core) {
r_config_set_cb (cfg, "zoom.byte", "h", &config_zoombyte_callback);
/* TODO cmd */
#if 0
// node->callback = &config_arch_callback;
config_set("asm.comments", "true"); // show comments in disassembly
config_set_i("asm.cmtmargin", 10); // show comments in disassembly
config_set_i("asm.cmtlines", 0); // show comments in disassembly
config_set("asm.case", "false"); // uppercase = true
config_set("asm.objdump", "objdump -m i386 --target=binary -D");
config_set("asm.offset", "true"); // show offset
config_set("asm.section", "true");
config_set("asm.stackptr", "true");
config_set("asm.reladdr", "false"); // relative offset
config_set_i("asm.nbytes", 8); // show hex bytes
config_set("asm.bytes", "true"); // show hex bytes
config_set("asm.jmpflags", "false");
config_set("asm.flags", "true");
config_set("asm.flagsall", "true");
config_set("asm.functions", "true");
@ -514,8 +506,6 @@ R_API int r_core_config_init(RCore *core) {
config_set_i("asm.nlines", 6); // show left ref lines
config_set("asm.lineswide", "false"); // show left ref lines
config_set("asm.trace", "false"); // trace counter
config_set("asm.linesout", "false"); // show left ref lines
config_set("asm.linestyle", "false"); // foreach / prev
config_set("asm.split", "true"); // split code blocks
config_set("asm.splitall", "false"); // split code blocks
config_set("asm.size", "false"); // opcode size
@ -679,42 +669,6 @@ R_API int r_core_config_init(RCore *core) {
config_set("graph.render", "cairo"); // aalib/ncurses/text
config_set("graph.layout", "default"); // graphviz
/* gui */
config_set("gui.top", "gtk-topbar"); // graphviz
config_set("gui.tabs", "gtk-prefs"); // graphviz
config_set("gui.left", "scriptedit gtk-actions"); // graphviz
config_set("gui.right", "gtk-hello"); // graphviz
config_set("gui.bottom", "gtk-hello"); // graphviz
node = config_set("scr.palette", cons_palette_default);
node->callback = &config_palette_callback;
cons_palette_init(config_get("scr.palette"));
#define config_set_scr_pal(x,y) \
node = config_set("scr.pal."x"", y); \
node->callback = &config_palette_callback; \
node->callback(node);
config_set_scr_pal("prompt","yellow")
config_set_scr_pal("default","white")
config_set_scr_pal("changed","green")
config_set_scr_pal("jumps","green")
config_set_scr_pal("calls","green")
config_set_scr_pal("push","green")
config_set_scr_pal("trap","red")
config_set_scr_pal("cmp","yellow")
config_set_scr_pal("ret","red")
config_set_scr_pal("nop","gray")
config_set_scr_pal("metadata","gray")
config_set_scr_pal("header","green")
config_set_scr_pal("printable","bwhite")
config_set_scr_pal("lines0","white")
config_set_scr_pal("lines1","yellow")
config_set_scr_pal("lines2","bwhite")
config_set_scr_pal("address","green")
config_set_scr_pal("ff","red")
config_set_scr_pal("00","white")
config_set_scr_pal("7f","magenta")
config_set("scr.grephigh", "");
node = config_set("scr.buf", "false");
node->callback = &config_scrbuf_callback;

View File

@ -42,6 +42,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
// TODO: All those options must be print flags
int show_color = r_config_get_i (core->config, "scr.color");
int acase = r_config_get_i (core->config, "asm.case");
int decode = r_config_get_i (core->config, "asm.decode");
int pseudo = r_config_get_i (core->config, "asm.pseudo");
int filter = r_config_get_i (core->config, "asm.filter");
@ -151,6 +152,8 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
sprintf (asmop.buf_hex, "%02x", buf[idx]);
//continue;
} else lastfail = 0;
if (acase)
r_str_case (asmop.buf_asm, 1);
if (core->inc == 0)
core->inc = ret;

View File

@ -167,11 +167,11 @@ R_API const char *r_str_bool(int b) {
R_API void r_str_case(char *str, int up) {
if (up) {
while (*str)
*str = tolower (*str);
} else {
while (*str)
for (;*str;str++)
*str = toupper (*str);
} else {
for (;*str; str++)
*str = tolower (*str);
}
}