* Fix segfault in java disassembler
* Update compilation instructions for w32 in doc/windows * Identify new osx binaries as mach0, not java * io.va only works when there are configured sections
This commit is contained in:
parent
cb5f4f26da
commit
21d2531b7f
9 changed files with 48 additions and 35 deletions
5
TODO
5
TODO
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
Questions:
|
||||
----------
|
||||
* rabin2 doesnt works for osx-x86 mach0 bins..so io.va=1 fails
|
||||
- opening simple fiels with io.va=1 fails !!!
|
||||
- if no sections defined it should read as plain
|
||||
* Do we have to enable jump/call toggles for breaking basicblocks? (yes/no)
|
||||
- pancake: no , nibble: (WHAT DO YOU THINK ABOUT THIS? :)
|
||||
* code analysis with r_parse // isnt this already done? nibble?
|
||||
|
|
@ -24,6 +27,8 @@ Bugs:
|
|||
|
||||
TODO:
|
||||
-----
|
||||
* nibble: mach0 new binary format is not supported by bin_mach0 :(
|
||||
* java disassembler do not uses the constant pool
|
||||
* Implement r_sys_setenv stuff from r1 in core/file.c:33 (!!?)
|
||||
* pancake: Implement search.align
|
||||
* Initial analysis looking for xrefs to strings and so? ax? ./a@@entry0
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ Crosscompilation
|
|||
|
||||
ArchLinux
|
||||
---------
|
||||
./configure --with-compiler=i486-mingw32-gcc --with-ostype=windows --host=i486-unknown-windows
|
||||
./configure --without-gmp --with-compiler=i486-mingw32-gcc --with-ostype=windows --host=i486-unknown-windows
|
||||
make
|
||||
|
||||
Ubuntu
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
static struct cp_item *cp_items;
|
||||
static struct cp_item *cp_items = NULL;
|
||||
static struct cp_item cp_null_item; // NOTE: must be initialized for safe use
|
||||
|
||||
static struct constant_t {
|
||||
|
|
@ -66,21 +66,20 @@ static ut16 r_ntohs (ut16 foo) {
|
|||
return foo;
|
||||
}
|
||||
|
||||
static struct cp_item * get_cp(int i)
|
||||
{
|
||||
static struct cp_item * get_cp(int i) {
|
||||
if (i<0||i>cf.cp_count)
|
||||
return &cp_null_item;
|
||||
return &cp_items[i];
|
||||
}
|
||||
|
||||
static int java_resolve(int idx, char *str)
|
||||
{
|
||||
static int java_resolve(int idx, char *str) {
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
str[0]='\0';
|
||||
if (idx<0||idx>cf.cp_count)
|
||||
return 1;
|
||||
if (cp_items) {
|
||||
if((!strcmp(cp_items[idx].name, "MethodRef"))
|
||||
|| (!strcmp(cp_items[idx].name, "FieldRef"))) {
|
||||
int class = USHORT(get_cp(idx)->bytes,0);
|
||||
|
|
@ -94,9 +93,9 @@ static int java_resolve(int idx, char *str)
|
|||
sprintf(str, "\"%s\"", get_cp(USHORT(get_cp(idx)->bytes,0)-1)->value);
|
||||
} else
|
||||
if (!strcmp(cp_items[idx].name, "Utf8")) {
|
||||
sprintf(str, "\"%s\"", get_cp(idx)->value);
|
||||
} else
|
||||
sprintf(str, "0x%04x", USHORT(get_cp(idx)->bytes,0));
|
||||
sprintf (str, "\"%s\"", get_cp(idx)->value);
|
||||
} else sprintf (str, "0x%04x", USHORT(get_cp(idx)->bytes,0));
|
||||
} else strcpy (str, "(null)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2007, 2008, 2009
|
||||
* pancake <youterm.com>, nibbke <develsec.org>
|
||||
* Copyright (C) 2007, 2008, 2009, 2010
|
||||
* pancake <youterm.com>, nibble <develsec.org>
|
||||
*
|
||||
* radare is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@
|
|||
#include <r_util.h>
|
||||
#include "mach0.h"
|
||||
|
||||
static int MACH0_(r_bin_mach0_addr_to_offset)(struct MACH0_(r_bin_mach0_obj_t)* bin, ut64 addr)
|
||||
{
|
||||
static int MACH0_(r_bin_mach0_addr_to_offset)(struct MACH0_(r_bin_mach0_obj_t)* bin, ut64 addr) {
|
||||
ut64 section_base, section_size;
|
||||
int i;
|
||||
|
||||
|
|
@ -21,18 +20,19 @@ static int MACH0_(r_bin_mach0_addr_to_offset)(struct MACH0_(r_bin_mach0_obj_t)*
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int MACH0_(r_bin_mach0_init_hdr)(struct MACH0_(r_bin_mach0_obj_t)* bin)
|
||||
{
|
||||
static int MACH0_(r_bin_mach0_init_hdr)(struct MACH0_(r_bin_mach0_obj_t)* bin) {
|
||||
int magic, len;
|
||||
|
||||
if (r_buf_read_at(bin->b, 0, (ut8*)&magic, 4) == -1) {
|
||||
eprintf("Error: read (magic)\n");
|
||||
if (r_buf_read_at (bin->b, 0, (ut8*)&magic, 4) == -1) {
|
||||
eprintf ("Error: read (magic)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
if (magic == MH_MAGIC)
|
||||
bin->endian = !LIL_ENDIAN;
|
||||
else if (magic == MH_CIGAM)
|
||||
bin->endian = LIL_ENDIAN;
|
||||
else if (magic == FAT_CIGAM)
|
||||
bin->endian = LIL_ENDIAN;
|
||||
else return R_FALSE;
|
||||
#if R_BIN_MACH064
|
||||
len = r_buf_fread_at(bin->b, 0, (ut8*)&bin->hdr, bin->endian?"8I":"8i", 1);
|
||||
|
|
@ -40,7 +40,7 @@ static int MACH0_(r_bin_mach0_init_hdr)(struct MACH0_(r_bin_mach0_obj_t)* bin)
|
|||
len = r_buf_fread_at(bin->b, 0, (ut8*)&bin->hdr, bin->endian?"7I":"7i", 1);
|
||||
#endif
|
||||
if (len == -1) {
|
||||
eprintf("Error: read (hdr)\n");
|
||||
eprintf ("Error: read (hdr)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
return R_TRUE;
|
||||
|
|
@ -56,9 +56,9 @@ static int MACH0_(r_bin_mach0_parse_seg)(struct MACH0_(r_bin_mach0_obj_t)* bin,
|
|||
return R_FALSE;
|
||||
}
|
||||
#if R_BIN_MACH064
|
||||
len = r_buf_fread_at(bin->b, off, (ut8*)&bin->segs[seg], bin->endian?"2I16c4L4I":"2i16c4l4i", 1);
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&bin->segs[seg], bin->endian?"2I16c4L4I":"2i16c4l4i", 1);
|
||||
#else
|
||||
len = r_buf_fread_at(bin->b, off, (ut8*)&bin->segs[seg], bin->endian?"2I16c8I":"2i16c8i", 1);
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&bin->segs[seg], bin->endian?"2I16c8I":"2i16c8i", 1);
|
||||
#endif
|
||||
if (len == -1) {
|
||||
eprintf("Error: read (seg)\n");
|
||||
|
|
@ -72,10 +72,10 @@ static int MACH0_(r_bin_mach0_parse_seg)(struct MACH0_(r_bin_mach0_obj_t)* bin,
|
|||
return R_FALSE;
|
||||
}
|
||||
#if R_BIN_MACH064
|
||||
len = r_buf_fread_at(bin->b, off + sizeof(struct MACH0_(segment_command)),
|
||||
len = r_buf_fread_at (bin->b, off + sizeof(struct MACH0_(segment_command)),
|
||||
(ut8*)&bin->sects[sect], bin->endian?"16c16c2L8I":"16c16c2l8i", bin->nsects - sect);
|
||||
#else
|
||||
len = r_buf_fread_at(bin->b, off + sizeof(struct MACH0_(segment_command)),
|
||||
len = r_buf_fread_at (bin->b, off + sizeof(struct MACH0_(segment_command)),
|
||||
(ut8*)&bin->sects[sect], bin->endian?"16c16c9I":"16c16c9i", bin->nsects - sect);
|
||||
#endif
|
||||
if (len == -1) {
|
||||
|
|
@ -251,7 +251,7 @@ static int MACH0_(r_bin_mach0_parse_dylib)(struct MACH0_(r_bin_mach0_obj_t)* bin
|
|||
}
|
||||
len = r_buf_fread_at (bin->b, off, (ut8*)&dl, bin->endian?"6I":"6i", 1);
|
||||
if (len == -1) {
|
||||
eprintf("Error: read (dylib)\n");
|
||||
eprintf ("Error: read (dylib)\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
if (r_buf_read_at (bin->b, off+dl.dylib.name.offset, (ut8*)bin->libs[lib], R_BIN_MACH0_STRING_LENGTH) == -1) {
|
||||
|
|
@ -264,13 +264,13 @@ static int MACH0_(r_bin_mach0_parse_dylib)(struct MACH0_(r_bin_mach0_obj_t)* bin
|
|||
static int MACH0_(r_bin_mach0_init_items)(struct MACH0_(r_bin_mach0_obj_t)* bin)
|
||||
{
|
||||
struct load_command lc = {0, 0};
|
||||
ut64 off;
|
||||
ut64 off = 0LL;
|
||||
int i, len;
|
||||
|
||||
for (i = 0, off = sizeof(struct MACH0_(mach_header)); i < bin->hdr.ncmds; i++, off += lc.cmdsize) {
|
||||
for (i = 0, off = sizeof (struct MACH0_(mach_header)); i < bin->hdr.ncmds; i++, off += lc.cmdsize) {
|
||||
len = r_buf_fread_at(bin->b, off, (ut8*)&lc, bin->endian?"2I":"2i", 1);
|
||||
if (len == -1) {
|
||||
eprintf("Error: read (lc)\n");
|
||||
eprintf ("Error: read (lc) at 0x%08llx\n", off);
|
||||
return R_FALSE;
|
||||
}
|
||||
switch (lc.cmd) {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@
|
|||
#define MACH0_(name) name##_64
|
||||
#define MH_MAGIC 0xfeedfacf
|
||||
#define MH_CIGAM 0xcffaedfe
|
||||
#define FAT_CIGAM 0xbabefeca /* XXX */
|
||||
#else
|
||||
#define MACH0_(name) name
|
||||
#define MH_MAGIC 0xfeedface
|
||||
#define MH_CIGAM 0xcefaedfe
|
||||
#define FAT_CIGAM 0xbebafeca
|
||||
#endif
|
||||
|
||||
#ifndef _INCLUDE_MACHO_SPECS_H_
|
||||
|
|
|
|||
|
|
@ -115,8 +115,9 @@ static RBinInfo* info(RBin *bin) {
|
|||
static int check(RBin *bin) {
|
||||
ut8 *buf;
|
||||
int n, ret = R_FALSE;
|
||||
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 4, &n))) {
|
||||
if (n==4 && !memcmp (buf, "\xca\xfe\xba\xbe", 4))
|
||||
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 16, &n))) {
|
||||
if (n==16 && !memcmp (buf, "\xca\xfe\xba\xbe", 4)
|
||||
&& (buf[7]!=2 && buf[11]!=7))
|
||||
ret = R_TRUE;
|
||||
free (buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,11 +184,15 @@ static int check(RBin *bin) {
|
|||
ut8 *buf;
|
||||
int n, ret = R_FALSE;
|
||||
|
||||
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 4, &n))) {
|
||||
if (n == 4)
|
||||
if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
|
||||
!memcmp (buf, "\xfe\xed\xfa\xce", 4))
|
||||
ret = R_TRUE;
|
||||
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 8, &n))) {
|
||||
if (n == 8) {
|
||||
if (!memcmp (buf, "\xca\xfe\xba\xbe\x00\x00\x00\x02", 8))
|
||||
ret = R_TRUE;
|
||||
else
|
||||
if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
|
||||
!memcmp (buf, "\xfe\xed\xfa\xce", 4))
|
||||
ret = R_TRUE;
|
||||
}
|
||||
free (buf);
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -269,7 +269,8 @@ R_API ut64 r_io_seek(struct r_io_t *io, ut64 offset, int whence) {
|
|||
posix_whence = SEEK_END;
|
||||
break;
|
||||
}
|
||||
offset = io->va ? r_io_section_vaddr_to_offset (io, offset) : offset;
|
||||
offset = (io->va && !list_empty (&io->sections))?
|
||||
r_io_section_vaddr_to_offset (io, offset) : offset;
|
||||
// TODO: implement io->enforce_seek here!
|
||||
if (io->plugin && io->plugin->lseek)
|
||||
ret = io->plugin->lseek (io, io->fd, offset, whence);
|
||||
|
|
@ -279,7 +280,8 @@ R_API ut64 r_io_seek(struct r_io_t *io, ut64 offset, int whence) {
|
|||
io->off = ret;
|
||||
// XXX this can be tricky.. better not to use this .. must be deprecated
|
||||
// r_io_sundo_push (io);
|
||||
ret = io->va ? r_io_section_offset_to_vaddr (io, io->off) : io->off;
|
||||
ret = (io->va && !list_empty (&io->sections))?
|
||||
r_io_section_offset_to_vaddr (io, io->off) : io->off;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue