* Fix java class parser for javac -g files

- Show debug information in sdb format
  - Fix null pointer segfault
  - Still work-in-progress for proper debug info
* Some work on r_egg
  - Fix windows and osx default syscall tables
* Export version number in vapi R2_VERSION
* Hide ccache error if not found in sys/install
This commit is contained in:
pancake 2011-09-18 18:56:11 +02:00
parent d72d66f143
commit 838e6b7466
15 changed files with 187 additions and 95 deletions

View File

@ -1,3 +1,6 @@
puts@global() {
/* do nothing */
}
main@global(128)
{
.var0 = 3;
@ -6,9 +9,7 @@ main@global(128)
puts(.var4);
.var0 -= 1;
} while(.var0);
:
: /* comment */
:
/* comment */
.var0 = 3;
.var4 = "coconut";
while(.var0) {
@ -17,3 +18,4 @@ main@global(128)
}
0;
}

View File

@ -218,8 +218,8 @@ static int attributes_walk(FILE *fd, int sz2, int fields, int verbose) {
fread(buf, UINT(buf, 4), 1, fd); // READ CODE
sz = read_short(fd);
printf(" Exception table length: %d\n", sz);
for(k=0;k<sz;k++) {
V printf(" Exception table length: %d\n", sz);
for (k=0;k<sz;k++) {
fread(buf, 8, 1, fd);
V printf(" start_pc: 0x%04x\n", USHORT(buf,0));
V printf(" end_pc: 0x%04x\n", USHORT(buf,2));
@ -245,6 +245,17 @@ static int attributes_walk(FILE *fd, int sz2, int fields, int verbose) {
fread (buf, 2, 1, fd);
V printf(" StackMapTable: %d\n", USHORT(buf, 0));
} else
if (!strcmp (name, "LocalVariableTable")) {
int i;
ut32 lvtl = (ut32)read_short (fd);
for (i=0; i<lvtl; i++) {
int start_pc = start_pc = read_short (fd);
int length = length = read_short (fd);
int name_idx = name_idx = read_short (fd);
int desc_idx = desc_idx = read_short (fd);
int index = index = read_short (fd);
}
} else
if (!strcmp(name, "ConstantValue")) {
fread(buf, 2, 1, fd);
#if 0
@ -297,9 +308,9 @@ int java_classdump(const char *file, int verbose) {
}
cf.cp_count--;
V printf("ConstantPoolCount %d\n", cf.cp_count);
V printf ("ConstantPoolCount %d\n", cf.cp_count);
cp_items = malloc (sizeof (struct cp_item)*(cf.cp_count+1));
for(i=0;i<cf.cp_count;i++) {
for (i=0;i<cf.cp_count;i++) {
struct constant_t *c;
fread (buf, 1, 1, fd);
c = NULL;
@ -310,7 +321,7 @@ int java_classdump(const char *file, int verbose) {
}
}
if (c == NULL) {
fprintf(stderr, "Invalid tag '%d'\n", buf[0]);
eprintf ("Invalid tag '%d'\n", buf[0]);
return 0;
}
V printf(" %3d %s: ", i+1, c->name);
@ -339,7 +350,7 @@ int java_classdump(const char *file, int verbose) {
/* parse value */
switch(c->tag) {
case 1:
printf ("%s\n", buf);
V printf ("%s\n", buf);
cp_items[i].value = strdup(buf);
break;
case 7:
@ -363,21 +374,21 @@ int java_classdump(const char *file, int verbose) {
}
}
fread(&cf2, sizeof(struct classfile2), 1, fd);
fread (&cf2, sizeof (struct classfile2), 1, fd);
check_eof(fd);
V printf("Access flags: 0x%04x\n", cf2.access_flags);
this_class = r_ntohs(cf2.this_class);
V printf("This class: %d\n", this_class);
check_eof(fd);
V printf ("This class: %d\n", this_class);
check_eof (fd);
//printf("This class: %d (%s)\n", ntohs(cf2.this_class), cp_items[ntohs(cf2.this_class)-1].value); // XXX this is a double pointer !!1
//printf("Super class: %d (%s)\n", ntohs(cf2.super_class), cp_items[ntohs(cf2.super_class)-1].value);
sz = read_short(fd);
V printf("Interfaces count: %d\n", sz);
sz = read_short (fd);
V printf ("Interfaces count: %d\n", sz);
if (sz>0) {
fread(buf, sz*2, 1, fd);
sz = read_short(fd);
for(i=0;i<sz;i++) {
fprintf(stderr, "interfaces: TODO\n");
fread (buf, sz*2, 1, fd);
sz = read_short (fd);
for (i=0; i<sz; i++) {
eprintf ("interfaces: TODO\n");
}
}
@ -409,7 +420,7 @@ int java_classdump(const char *file, int verbose) {
V printf(" Descriptor Index: %d (%s)\n", USHORT(buf, 4), get_cp(USHORT(buf, 4)-1)->value);
sz2 = USHORT(buf, 6);
printf(" method Attributes Count: %d\n", sz2);
V printf(" method Attributes Count: %d\n", sz2);
attributes_walk(fd, sz2, 0, verbose);
}
}

View File

@ -14,6 +14,7 @@
#include <r_types.h>
#include <r_util.h>
//#define IFDBG if(1)
static struct constant_t {
char *name;
int tag;
@ -33,21 +34,21 @@ static struct constant_t {
{ NULL, 0, 0 }
};
static struct r_bin_java_cp_item_t cp_null_item; // NOTE: must be initialized for safe use
static struct r_bin_java_cp_item_t cp_null_item = {0}; // NOTE: must be initialized for safe use
static unsigned short read_short(struct r_bin_java_obj_t *bin) {
unsigned short sh=0;
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)&sh, 2);
static unsigned short read_short(RBinJavaObj *bin) {
ut16 sh = 0;
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)&sh, 2);
return R_BIN_JAVA_SWAPUSHORT(sh);
}
static struct r_bin_java_cp_item_t* get_cp(struct r_bin_java_obj_t *bin, int i) {
static struct r_bin_java_cp_item_t* get_cp(RBinJavaObj *bin, int i) {
if (i<0||i>bin->cf.cp_count)
return &cp_null_item;
return &bin->cp_items[i];
}
static int attributes_walk(struct r_bin_java_obj_t *bin, struct r_bin_java_attr_t *attr, int sz2, int fields) {
static int attributes_walk(RBinJavaObj *bin, struct r_bin_java_attr_t *attr, int sz2, int fields) {
char buf[0xffff+1]; // that's kinda ugly :)
int sz3, sz4;
int j=0,k;
@ -61,7 +62,7 @@ static int attributes_walk(struct r_bin_java_obj_t *bin, struct r_bin_java_attr_
attr->name_idx = R_BIN_JAVA_USHORT(buf,0);
name = get_cp (bin, attr->name_idx-1)->value;
// XXX: if name is null.. wat?
attr->name = strdup (name?name:"");
attr->name = strdup (name? name: "");
name = (get_cp(bin, attr->name_idx-1))->value;//cp_items[R_BIN_JAVA_USHORT(buf,0)-1].value;
IFDBG printf(" %2d: Name Index: %d (%s)\n", j, attr->name_idx, name);
// TODO add comment with constant pool index
@ -112,34 +113,55 @@ static int attributes_walk(struct r_bin_java_obj_t *bin, struct r_bin_java_attr_
attributes_walk(bin, attr->attributes, sz4, fields);
}
} else
if (!strcmp(name, "LineNumberTable")) {
if (!strcmp (name, "LineNumberTable")) {
attr->type = R_BIN_JAVA_TYPE_LINENUM;
sz4 = (unsigned int)read_short(bin);
sz4 = (unsigned int)read_short (bin);
attr->info.linenum.table_length = sz4;
IFDBG printf(" Table Length: %d\n", attr->info.linenum.table_length);
for(k=0;k<sz4;k++) {
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)buf, 4);
attr->info.linenum.start_pc = R_BIN_JAVA_USHORT(buf, 0);
IFDBG printf(" %2d: start_pc: 0x%04x\n", k, attr->info.linenum.start_pc);
attr->info.linenum.line_number = R_BIN_JAVA_USHORT(buf, 2);
IFDBG printf(" line_number: %d\n", attr->info.linenum.line_number);
eprintf ("line.%d.sym=%s\n", bin->midx, bin->methods[bin->midx].name);
for (k=0; k<sz4; k++) {
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 4);
attr->info.linenum.start_pc = R_BIN_JAVA_USHORT (buf, 0);
//eprintf (" %2d: start_pc: 0x%04x\n", k, attr->info.linenum.start_pc);
attr->info.linenum.line_number = R_BIN_JAVA_USHORT (buf, 2);
//eprintf (" line_number: %d\n", attr->info.linenum.line_number);
eprintf ("line.%d.%d.%d=0x%x\n", bin->midx, k,
attr->info.linenum.line_number,
attr->info.linenum.start_pc);
}
} else
if (!strcmp(name, "StackMapTable")) {
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)buf, 2); // XXX: this is probably wrong
if (!strcmp (name, "StackMapTable")) {
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 2); // XXX: this is probably wrong
//printf(" StackMapTable: %d\n", USHORT(buf, 0));
} else
if (!strcmp(name, "ConstantValue")) {
if (!strcmp (name, "LocalVariableTable")) {
int i;
ut32 lvtl = (ut32)read_short (bin);
eprintf ("local.%d.sym=%s\n", bin->midx, bin->methods[bin->midx].name);
for (i=0; i<lvtl; i++) {
int start_pc = read_short (bin);
int length = read_short (bin);
int name_idx = read_short (bin);
int desc_idx = read_short (bin);
int index = read_short (bin);
const char *name = get_cp (bin, name_idx-1)->value;
const char *desc = get_cp (bin, desc_idx-1)->value;
eprintf ("local.%d.%d.type=%s\n", bin->midx, i, desc);
eprintf ("local.%d.%d.name=%s\n", bin->midx, i, name);
}
} else
if (!strcmp (name, "ConstantValue")) {
attr->type = R_BIN_JAVA_TYPE_CONST;
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)buf, 2);
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 2);
#if 0
printf(" Name Index: %d\n", R_BIN_JAVA_USHORT(buf, 0)); // %s\n", R_BIN_JAVA_USHORT(buf, 0), cp_items[R_BIN_JAVA_USHORT(buf,0)-1].value);
printf(" AttributeLength: %d\n", R_BIN_JAVA_UINT(buf, 2));
#endif
attr->info.const_value_idx = R_BIN_JAVA_USHORT(buf, 0);
IFDBG printf(" ConstValueIndex: %d\n", attr->info.const_value_idx);
IFDBG printf (" ConstValueIndex: %d\n", attr->info.const_value_idx);
} else {
IFDBG fprintf(stderr, "** ERROR ** Unknown section '%s'\n", name);
eprintf ("** ERROR ** Unknown section '%s'\n", name);
return R_FALSE;
}
}
@ -147,10 +169,10 @@ static int attributes_walk(struct r_bin_java_obj_t *bin, struct r_bin_java_attr_
return R_TRUE;
}
static int javasm_init(struct r_bin_java_obj_t *bin) {
static int javasm_init(RBinJavaObj *bin) {
unsigned short sz, sz2;
char buf[0x9999];
int i,j;
int i, j;
/* Initialize structs */
bin->cp_items = NULL;
@ -184,7 +206,7 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 1);
c = NULL;
for (j=0;constants[j].name;j++) {
for (j=0; constants[j].name; j++) {
if (constants[j].tag == buf[0]) {
c = &constants[j];
break;
@ -212,20 +234,20 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
bin->cp_items[i].length = sz;
bin->cp_items[i].off += 3;
if (sz > 0)
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)buf, sz);
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, sz);
buf[sz] = '\0';
break;
default:
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)buf, c->len);
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, c->len);
}
memcpy(bin->cp_items[i].bytes, buf, 5);
memcpy (bin->cp_items[i].bytes, buf, 5);
/* parse value */
switch (c->tag) {
case 1:
IFDBG printf("%s\n", buf);
bin->cp_items[i].value = strdup(buf);
// eprintf ("%s\n", buf);
bin->cp_items[i].value = strdup (buf);
break;
case 5:
case 6:
@ -248,14 +270,14 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
IFDBG printf("descriptor = %d\n", R_BIN_JAVA_USHORT(buf,2));
break;
default:
printf("%d\n", R_BIN_JAVA_UINT(buf, 40));
printf ("%d\n", R_BIN_JAVA_UINT (buf, 40));
}
}
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)&bin->cf2, sizeof(struct r_bin_java_classfile2_t));
IFDBG printf("Access flags: 0x%04x\n", bin->cf2.access_flags);
r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)&bin->cf2, sizeof(struct r_bin_java_classfile2_t));
IFDBG printf ("Access flags: 0x%04x\n", bin->cf2.access_flags);
bin->cf2.this_class = R_BIN_JAVA_SWAPUSHORT(bin->cf2.this_class);
IFDBG printf("This class: %d\n", bin->cf2.this_class);
IFDBG printf ("This class: %d\n", bin->cf2.this_class);
//printf("This class: %d (%s)\n", R_BIN_JAVA_SWAPUSHORT(bin->cf2.this_class), bin->cp_items[R_BIN_JAVA_SWAPUSHORT(bin->cf2.this_class)-1].value); // XXX this is a double pointer !!1
//printf("Super class: %d (%s)\n", R_BIN_JAVA_SWAPUSHORT(bin->cf2.super_class), bin->cp_items[R_BIN_JAVA_SWAPUSHORT(bin->cf2.super_class)-1].value);
sz = read_short(bin);
@ -280,7 +302,7 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
bin->fields[i].flags = R_BIN_JAVA_USHORT(buf, 0);
IFDBG printf("%2d: Access Flags: %d\n", i, bin->fields[i].flags);
bin->fields[i].name_idx = R_BIN_JAVA_USHORT(buf, 2);
bin->fields[i].name = strdup((get_cp(bin, R_BIN_JAVA_USHORT(buf,2)-1))->value);
bin->fields[i].name = r_str_dup (NULL, (get_cp (bin, R_BIN_JAVA_USHORT(buf,2)-1))->value);
IFDBG printf(" Name Index: %d (%s)\n", bin->fields[i].name_idx, bin->fields[i].name);
bin->fields[i].descriptor_idx = R_BIN_JAVA_USHORT(buf, 4);
bin->fields[i].descriptor = NULL;
@ -308,24 +330,26 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
IFDBG printf("%2d: Access Flags: %d\n", i, bin->methods[i].flags);
bin->methods[i].name_idx = R_BIN_JAVA_USHORT(buf, 2);
#if OLD
bin->methods[i].name = strdup((get_cp(bin, R_BIN_JAVA_USHORT(buf, 2)-1))->value);
bin->methods[i].name = r_str_dup (NULL, (get_cp(bin, R_BIN_JAVA_USHORT(buf, 2)-1))->value);
#else
bin->methods[i].name = malloc (1024);
// XXX: can null ptr here
snprintf (bin->methods[i].name, 1023, "%s%s",
(get_cp(bin, R_BIN_JAVA_USHORT(buf, 2)-1))->value,
(get_cp(bin, R_BIN_JAVA_USHORT(buf, 2)))->value);
(get_cp (bin, R_BIN_JAVA_USHORT(buf, 2)-1))->value,
(get_cp (bin, R_BIN_JAVA_USHORT(buf, 2)))->value);
#endif
bin->midx = i;
IFDBG printf(" Name Index: %d (%s)\n", bin->methods[i].name_idx, bin->methods[i].name);
bin->methods[i].descriptor_idx = R_BIN_JAVA_USHORT(buf, 4);
bin->methods[i].descriptor = strdup((get_cp(bin, R_BIN_JAVA_USHORT(buf, 4)-1))->value);
bin->methods[i].descriptor = r_str_dup (NULL, (get_cp(bin, R_BIN_JAVA_USHORT(buf, 4)-1))->value);
IFDBG printf(" Descriptor Index: %d (%s)\n", bin->methods[i].descriptor_idx, bin->methods[i].descriptor);
sz2 = R_BIN_JAVA_USHORT(buf, 6);
bin->methods[i].attr_count = sz2;
IFDBG printf(" method Attributes Count: %d\n", sz2);
if (sz2 > 0) {
bin->methods[i].attributes = malloc(1+sz2 * sizeof(struct r_bin_java_attr_t));
for(j=0;j<sz2;j++) {
bin->methods[i].attributes = malloc (1+sz2 * sizeof (struct r_bin_java_attr_t));
for (j=0; j<sz2; j++) {
if (!attributes_walk (bin, &bin->methods[i].attributes[j], sz2, 0))
return R_FALSE;
}
@ -336,13 +360,13 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
return R_TRUE;
}
char* r_bin_java_get_version(struct r_bin_java_obj_t* bin) {
char* r_bin_java_get_version(RBinJavaObj* bin) {
return r_str_dup_printf("0x%02x%02x 0x%02x%02x",
bin->cf.major[1],bin->cf.major[0],
bin->cf.minor[1],bin->cf.minor[0]);
}
ut64 r_bin_java_get_entrypoint(struct r_bin_java_obj_t* bin) {
ut64 r_bin_java_get_entrypoint(RBinJavaObj* bin) {
int i, j;
for (i=0; i < bin->methods_count; i++)
if (!strcmp(bin->methods[i].name, "<init>"))
@ -352,7 +376,7 @@ ut64 r_bin_java_get_entrypoint(struct r_bin_java_obj_t* bin) {
return 0;
}
struct r_bin_java_sym_t* r_bin_java_get_symbols(struct r_bin_java_obj_t* bin) {
struct r_bin_java_sym_t* r_bin_java_get_symbols(RBinJavaObj* bin) {
struct r_bin_java_sym_t *symbols;
int i, j, ctr = 0;
@ -373,7 +397,7 @@ struct r_bin_java_sym_t* r_bin_java_get_symbols(struct r_bin_java_obj_t* bin) {
return symbols;
}
struct r_bin_java_str_t* r_bin_java_get_strings(struct r_bin_java_obj_t* bin) {
struct r_bin_java_str_t* r_bin_java_get_strings(RBinJavaObj* bin) {
struct r_bin_java_str_t *strings = NULL;
int i, ctr = 0;
@ -396,7 +420,7 @@ struct r_bin_java_str_t* r_bin_java_get_strings(struct r_bin_java_obj_t* bin) {
return strings;
}
void* r_bin_java_free(struct r_bin_java_obj_t* bin) {
void* r_bin_java_free(RBinJavaObj* bin) {
if (!bin) return NULL;
if (bin->cp_items) free (bin->cp_items);
if (bin->fields) free (bin->fields);
@ -406,34 +430,31 @@ void* r_bin_java_free(struct r_bin_java_obj_t* bin) {
return NULL;
}
struct r_bin_java_obj_t* r_bin_java_new(const char* file) {
struct r_bin_java_obj_t *bin;
RBinJavaObj* r_bin_java_new(const char* file) {
RBinJavaObj *bin;
ut8 *buf;
if (!(bin = malloc(sizeof(struct r_bin_java_obj_t))))
if (!(bin = malloc(sizeof(RBinJavaObj))))
return NULL;
memset (bin, 0, sizeof (struct r_bin_java_obj_t));
memset (bin, 0, sizeof (RBinJavaObj));
bin->file = file;
if (!(buf = (ut8*)r_file_slurp(file, &bin->size)))
return r_bin_java_free(bin);
bin->b = r_buf_new();
bin->b = r_buf_new ();
if (!r_buf_set_bytes(bin->b, buf, bin->size))
return r_bin_java_free(bin);
free (buf);
if (!javasm_init(bin))
if (!javasm_init (bin))
return r_bin_java_free(bin);
return bin;
}
struct r_bin_java_obj_t* r_bin_java_new_buf(struct r_buf_t *buf) {
struct r_bin_java_obj_t *bin;
if (!(bin = malloc(sizeof(struct r_bin_java_obj_t))))
return NULL;
memset (bin, 0, sizeof (struct r_bin_java_obj_t));
RBinJavaObj* r_bin_java_new_buf(struct r_buf_t *buf) {
RBinJavaObj *bin = R_NEW0 (RBinJavaObj);
if (!bin) return NULL;
bin->b = buf;
bin->size = buf->length;
if (!javasm_init(bin))
if (!javasm_init (bin))
return r_bin_java_free(bin);
return bin;
}

View File

@ -77,18 +77,19 @@ struct r_bin_java_fm_t {
struct r_bin_java_attr_t *attributes;
};
struct r_bin_java_obj_t {
typedef struct r_bin_java_obj_t {
struct r_bin_java_classfile_t cf;
struct r_bin_java_classfile2_t cf2;
struct r_bin_java_cp_item_t *cp_items;
unsigned int fields_count;
ut32 fields_count;
struct r_bin_java_fm_t *fields;
unsigned int methods_count;
ut32 methods_count;
struct r_bin_java_fm_t *methods;
int size;
const char* file;
struct r_buf_t* b;
};
const char* file;
struct r_buf_t*b;
int midx;
} RBinJavaObj;
struct r_bin_java_sym_t {
char name[R_BIN_JAVA_MAXSTR];

View File

@ -8,7 +8,7 @@
#include "java/java.h"
static int load(RBinArch *arch) {
if(!(arch->bin_obj = r_bin_java_new_buf(arch->buf)))
if (!(arch->bin_obj = r_bin_java_new_buf (arch->buf)))
return R_FALSE;
return R_TRUE;
}
@ -107,7 +107,7 @@ static RBinInfo* info(RBinArch *arch) {
strncpy (ret->machine, "Java VM", R_BIN_SIZEOF_STRINGS);
strncpy (ret->arch, "java", R_BIN_SIZEOF_STRINGS);
ret->bits = 32;
ret->big_endian= 0;
ret->big_endian = 0;
ret->dbg_info = 4 | 8; /* LineNums | Syms */
return ret;
}
@ -121,7 +121,7 @@ static int check(RBinArch *arch) {
r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);
if (off > 0 && off < arch->buf->length) {
memmove (arch->buf->buf, arch->buf->buf+off, 4);
if (!memcmp (arch->buf->buf, "\xce\xfa\xed\xfe", 4) ||
if ( !memcmp (arch->buf->buf, "\xce\xfa\xed\xfe", 4) ||
!memcmp (arch->buf->buf, "\xfe\xed\xfa\xce", 4) ||
!memcmp (arch->buf->buf, "\xfe\xed\xfa\xcf", 4) ||
!memcmp (arch->buf->buf, "\xcf\xfa\xed\xfe", 4))

View File

@ -206,3 +206,9 @@ R_API char *r_egg_get_assembly(REgg *egg) {
R_API void r_egg_append(REgg *egg, const char *src) {
r_buf_append_bytes (egg->src, (const ut8*)src, strlen (src));
}
// TODO: accept arguments
R_API int r_egg_run(REgg *egg) {
/* JIT */
return 0;
}

View File

@ -401,7 +401,7 @@ static void rcc_context(REgg *egg, int delta) {
static int parsedatachar(REgg *egg, char c) {
static int inlinectr = 0;
char *str;
int i,j;
int i, j;
/* skip until '{' */
if (c == '{') { /* XXX: repeated code!! */

41
libr/egg/t/loop.r Normal file
View File

@ -0,0 +1,41 @@
/* TODO: all bins must contain a jmp main */
/* entrypoint */
:jmp main
puts@global() {
/* do nothing */
: mov edx, 3
/* : mov ecx, 0x10000002a */
: mov ecx, `.arg0`
: mov ebx, 1
: mov eax, 4
: push eax
: int 0x80
: pop eax
}
exit@global() {
: mov eax, 1
: push eax
: int 0x80
}
main@global(128)
{
.var0 = 3;
.var4 = "counter";
{
puts(.var4);
.var0 -= 1;
} while(.var0);
exit()
/* comment */
.var0 = 3;
.var4 = "coconut";
while(.var0) {
puts(.var4);
.var0 -= 1;
}
0;
}

View File

@ -1,4 +1,7 @@
main@global(128) {
#// printf ("Hello World\n");
: nop
: mov eax, 1
: push eax
: int 0x80
}

View File

@ -18,6 +18,7 @@ typedef struct r_egg_t {
ut32 os;
} REgg;
/* XXX: this may fail in different arches */
#define R_EGG_OS_LINUX 0xcd21ce66
#define R_EGG_OS_OSX 0x1bf9e4
#define R_EGG_OS_DARWIN 0x5e417f87
@ -27,11 +28,11 @@ typedef struct r_egg_t {
#if __APPLE__
#define R_EGG_OS_DEFAULT R_EGG_OS_OSX
#define R_EGG_OS_NAME "osx"
#define R_EGG_OS_NAME "darwin"
#define R_EGG_FORMAT_DEFAULT "mach0"
#elif __WINDOWS__
#define R_EGG_OS_DEFAULT R_EGG_OS_W32
#define R_EGG_OS_NAME "w32"
#define R_EGG_OS_NAME "windows"
#define R_EGG_FORMAT_DEFAULT "pe"
#else
#define R_EGG_OS_DEFAULT R_EGG_OS_LINUX

View File

@ -62,7 +62,7 @@ R_API int r_syscall_setup(RSyscall *ctx, const char *arch, const char *os, int b
snprintf (file, sizeof (file), PREFIX"/%s/%s-%s-%d.sdb",
SYSCALLPATH, os, arch, bits);
if (!r_file_exist (file)) {
eprintf ("Cannot find '%s'\n", file);
eprintf ("r_syscall_setup: Cannot find '%s'\n", file);
return R_FALSE;
}

View File

@ -441,6 +441,7 @@ R_API const char *r_str_get(const char *str) {
R_API char *r_str_dup(char *ptr, const char *string) {
if (ptr) free (ptr);
if (!string) return NULL;
ptr = strdup (string);
return ptr;
}
@ -449,11 +450,11 @@ R_API char *r_str_dup(char *ptr, const char *string) {
R_API char *r_str_dup_printf(const char *fmt, ...) {
char *ret;
va_list ap;
va_start(ap, fmt);
va_start (ap, fmt);
if ((ret = malloc (1024)) == NULL)
return NULL;
vsnprintf (ret, 1024, fmt, ap);
va_end(ap);
va_end (ap);
return ret;
}
@ -489,7 +490,7 @@ R_API char *r_str_concatf(char *ptr, const char *fmt, ...) {
char string[1024];
va_list ap;
va_start (ap, fmt);
vsnprintf (string, 1023, fmt, ap);
vsnprintf (string, sizeof (string), fmt, ap);
ptr = r_str_concat (ptr, string);
va_end (ap);
return ptr;

View File

@ -1,6 +1,8 @@
/* radare - LGPL - Copyright 2009-2011 pancake<@nopcode.org> */
namespace Radare {
[CCode (cname="R2_VERSION")]
const string R2_VERSION;
#if 0
[Compact]
[CCode (cheader_filename="r_util.h", cprefix="r_hex_")]

View File

@ -4,6 +4,7 @@ public static void main(string[] args)
{
var c = new RCore();
var a = RDebug.ProcessStatus.STOP;
print ("VERSION: "+Radare.R2_VERSION+"\n");
RCore.File *f = c.file_open("/bin/ls", 0);
//stdout.printf("Filedescriptor: %d %d\n", f->fd->fd, a);
c.cmd("x", true);

View File

@ -10,7 +10,7 @@ elif [ -d .git ]; then
git pull
fi
ccache --help 2>&1 > /dev/null
ccache --help > /dev/null 2>&1
if [ $? = 0 ]; then
[ -z "${CC}" ] && CC=gcc
CC="ccache ${CC}"
@ -18,7 +18,9 @@ if [ $? = 0 ]; then
fi
# build
make mrproper && \
if [ -f config-user.mk ]; then
make mrproper
fi
./configure --prefix=/usr && \
make -j 4 && \
sudo make symstall