updating the way prototypes are created

This commit is contained in:
Adam Pridgen 2014-04-14 00:58:15 -05:00
parent 7cd412f6c9
commit a88218dd16
2 changed files with 27 additions and 93 deletions

View File

@ -1578,6 +1578,11 @@ static char * r_cmd_java_get_descriptor (RCore *core, RBinJavaObj *bin, ut16 idx
const char *type = NULL;
char * prototype = NULL;
if (idx == 0) {
prototype = strdup ("NULL");
return prototype;
}
if (obj->tag == R_BIN_JAVA_CP_INTERFACEMETHOD_REF ||
obj->tag == R_BIN_JAVA_CP_METHODREF ||
obj->tag == R_BIN_JAVA_CP_FIELDREF) {
@ -1595,25 +1600,6 @@ static char * r_cmd_java_get_descriptor (RCore *core, RBinJavaObj *bin, ut16 idx
snprintf (fullname, fn_len, "%s.%s", class_name, name);
}
if (fullname) prototype = r_bin_java_unmangle_without_flags (fullname, descriptor);
len = strlen (prototype);
/*if (len > 0 && prototype){
full_bird = malloc (len + 100);
memset (full_bird, 0, len+100);
}*/
if (full_bird && (obj->tag == R_BIN_JAVA_CP_INTERFACEMETHOD_REF ||
obj->tag == R_BIN_JAVA_CP_METHODREF)) {
if (obj->tag == R_BIN_JAVA_CP_INTERFACEMETHOD_REF) type = "INTERFACE";
else type = "FUNCTION";
snprintf (full_bird, len+100, "%s", prototype);
} else if (full_bird && obj->tag == R_BIN_JAVA_CP_FIELDREF) {
type = "FIELD";
//snprintf (full_bird, len+100, "%s", prototype);
}
//free (prototype);
free (class_name);
free (name);
free (descriptor);
@ -1641,7 +1627,7 @@ static int r_cmd_java_handle_list_code_references (RCore *core, const char *inpu
return R_TRUE;
}
const char *fmt = "addr:0x%"PFMT64x" op:\"%s\" type:\"%s\" info:\"%s\"\n";
const char *fmt = "addr:0x%"PFMT64x" method_name:\"%s\", op:\"%s\" type:\"%s\" info:\"%s\"\n";
r_list_foreach (anal->fcns, fcn_iter, fcn) {
@ -1653,7 +1639,18 @@ static int r_cmd_java_handle_list_code_references (RCore *core, const char *inpu
ut16 cp_ref_idx = -1;
char *full_bird = NULL;
// if bb_type is a call
if ( (bb->type2 & R_ANAL_EX_CODEOP_CALL) == R_ANAL_EX_CODEOP_CALL) {
if (bb->op_bytes[0] == 0x01) continue;
if (bb->op_bytes[0] == 0x12) {
// loading a constant
addr = bb->addr;
full_bird = r_bin_java_resolve_without_space(bin, bb->op_bytes[1]);
operation = "read constant";
type = r_bin_java_resolve_cp_idx_type (bin, bb->op_bytes[1]);
r_cons_printf (fmt, addr, fcn->name, operation, type, full_bird);
free (full_bird);
free (type);
operation = NULL;
} else if ( (bb->type2 & R_ANAL_EX_CODEOP_CALL) == R_ANAL_EX_CODEOP_CALL) {
ut8 op_byte = bb->op_bytes[0];
// look at the bytes determine if it belongs to this class
switch (op_byte) {
@ -1687,7 +1684,6 @@ static int r_cmd_java_handle_list_code_references (RCore *core, const char *inpu
addr = -1;
break;
}
} else if ( (bb->type2 & R_ANAL_EX_LDST_LOAD_GET_STATIC) == R_ANAL_EX_LDST_LOAD_GET_STATIC) {
operation = "read static";
type = "FIELD";
@ -1704,22 +1700,16 @@ static int r_cmd_java_handle_list_code_references (RCore *core, const char *inpu
operation = "write dynamic";
type = "FIELD";
addr = bb->addr;
} else if (bb->op_bytes[0] == 0x12) {
// loading a constant
addr = bb->addr;
full_bird = r_bin_java_resolve_without_space(bin, bb->op_bytes[1]);
operation = "read constant";
type = r_bin_java_resolve_cp_idx_type (bin, bb->op_bytes[1]);
r_cons_printf (fmt, addr, operation, type, full_bird);
free (full_bird);
free (type);
operation = NULL;
}
if (operation) {
cp_ref_idx = R_BIN_JAVA_USHORT (bb->op_bytes, 1);
full_bird = r_cmd_java_get_descriptor (core, bin, cp_ref_idx);
r_cons_printf (fmt, addr, operation, type, full_bird);
if (!full_bird) {
eprintf ("Error identifying reference @ 0x%"PFMT64x"\n", bb->addr);
full_bird = strdup ("ANALYSIS_ERROR");
}
r_cons_printf (fmt, addr, fcn->name, operation, type, full_bird);
free (full_bird);
}

View File

@ -793,11 +793,11 @@ R_API char * r_bin_java_unmangle (const char *flags, const char *name, const cha
if (flags_len > 0) {
len += (flags_len + name_len + 5); // space and null
result = malloc (len);
snprintf (result, len, "%s %s %s", flags, name, unmangle_field_desc);
snprintf (result, len, "%s %s %s", flags, unmangle_field_desc, name);
} else {
len += (name_len + 5); // space and null
result = malloc (len);
snprintf (result, len, "%s %s", name, unmangle_field_desc);
snprintf (result, len, "%s %s", unmangle_field_desc, name);
}
free (unmangle_field_desc);
} else if (l_paren_pos != (ut32) -1 &&
@ -833,68 +833,12 @@ R_API RList * r_bin_java_get_method_definitions(RBinJavaObj *bin) {
}
R_API char * r_bin_java_get_method_definition(RBinJavaField *fm_type) {
RList *the_list = NULL;
RListIter *iter = NULL;
char *str = NULL, *r_value = NULL, *prototype = NULL;
ut32 list_length = 0;
ut32 prototype_len = 0, idx = 0, bytes_written = 0;
prototype_len += strlen(fm_type->flags_str) + 1;
prototype_len += strlen(fm_type->name) + 1;
the_list = r_bin_java_extract_type_values (fm_type->descriptor);
r_list_foreach (the_list, iter, str) {
prototype_len += strlen(str);
if (str && *str != '(' && *str != ')') {
prototype_len += strlen(str) + 2; // for ", "
}
//if (str && *str == ')') break;
}
list_length = r_list_length(the_list);
r_value = r_list_get_n( the_list, list_length-1);
prototype = malloc(prototype_len + 2);
bytes_written = snprintf(prototype, prototype_len, "%s %s %s", fm_type->flags_str, r_value, fm_type->name );
for (idx = 0; list_length > 0 && idx < list_length-1; idx++) {
ut8 *tstr = r_list_get_n( the_list, idx),
*nstr = r_list_get_n( the_list, idx+1);
if (tstr) {
bytes_written += snprintf(prototype+bytes_written, prototype_len-bytes_written, "%s", tstr );
if (*tstr == '(' ) {}
else if ( *nstr == ')' ) { }
else if ( *tstr == ')' ) { }
else {
bytes_written += snprintf(prototype+bytes_written, prototype_len-bytes_written, ", " );
}
}
}
r_list_free (the_list);
char * prototype = r_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor);
return prototype;
}
R_API char * r_bin_java_get_field_definition(RBinJavaField *fm_type) {
char *prototype = NULL, *desc = NULL;
ut32 prototype_len = 0;
extract_type_value (fm_type->descriptor, &desc);
prototype_len += strlen(fm_type->flags_str) + 1;
prototype_len += strlen(fm_type->name) + 1;
prototype_len += strlen(desc) + 1;
prototype = malloc(prototype_len + 1);
//eprintf ("Field descriptor: %s\n", fm_type->descriptor);
if (desc) {
snprintf(prototype, prototype_len, "%s %s %s", fm_type->flags_str,
desc, fm_type->name );
} else {
snprintf(prototype, prototype_len, "%s UNKNOWN %s", fm_type->flags_str, fm_type->name );
}
char * prototype = r_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor);
return prototype;
}