Skip to content

Commit

Permalink
Revert "Initial part of a large refactoring using RBinName, unified a…
Browse files Browse the repository at this point in the history
…ttributes ##bin"

This reverts commit 1a173e9.
  • Loading branch information
radare committed Nov 6, 2023
1 parent eff936e commit 88c9dc3
Show file tree
Hide file tree
Showing 20 changed files with 999 additions and 927 deletions.
8 changes: 4 additions & 4 deletions libr/bin/bfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ R_API RList *r_bin_file_set_hashes(RBin *bin, RList/*<RBinFileHash*/ *new_hashes
return prev_hashes;
}

R_API RBinClass *r_bin_class_new(const char *name, const char *super, ut64 attr) {
R_API RBinClass *r_bin_class_new(const char *name, const char *super, int visibility) {
r_return_val_if_fail (name, NULL);
RBinClass *c = R_NEW0 (RBinClass);
if (c) {
Expand All @@ -1065,7 +1065,7 @@ R_API RBinClass *r_bin_class_new(const char *name, const char *super, ut64 attr)
// TODO: use vectors!
c->methods = r_list_newf (r_bin_symbol_free);
c->fields = r_list_newf (r_bin_field_free);
c->attr = attr;
c->visibility = visibility;
}
return c;
}
Expand All @@ -1081,7 +1081,7 @@ R_API void r_bin_class_free(RBinClass *k) {
}
}

R_API RBinClass *r_bin_file_add_class(RBinFile *bf, const char *name, const char *super, ut64 attr) {
R_API RBinClass *r_bin_file_add_class(RBinFile *bf, const char *name, const char *super, int view) {
r_return_val_if_fail (name && bf && bf->bo, NULL);
RBinClass *c = __getClass (bf, name);
if (c) {
Expand All @@ -1092,7 +1092,7 @@ R_API RBinClass *r_bin_file_add_class(RBinFile *bf, const char *name, const char
}
return c;
}
c = r_bin_class_new (name, super, attr);
c = r_bin_class_new (name, super, view);
if (c) {
// XXX. no need for a list, the ht is iterable too
c->index = r_list_length (bf->bo->classes);
Expand Down
172 changes: 59 additions & 113 deletions libr/bin/bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,12 +1384,12 @@ R_API RBinField *r_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *n
RBinField *ptr = R_NEW0 (RBinField);
if (ptr) {
ptr->name = strdup (name);
ptr->comment = R_STR_ISNOTEMPTY (comment)? strdup (comment): NULL;
ptr->format = R_STR_ISNOTEMPTY (format)? strdup (format): NULL;
ptr->comment = (comment && *comment)? strdup (comment): NULL;
ptr->format = (format && *format)? strdup (format): NULL;
ptr->format_named = format_named;
ptr->paddr = paddr;
ptr->size = size;
// ptr->attr = default attributes for fields?
// ptr->visibility = any default visibility?
ptr->vaddr = vaddr;
}
return ptr;
Expand All @@ -1406,6 +1406,59 @@ R_API void r_bin_field_free(void *_field) {
}
}

// method name too long
// RBin.methFlagToString(RBin.Method.CLASS)
R_API const char *r_bin_get_meth_flag_string(ut64 flag, bool compact) {
switch (flag) {
case R_BIN_METH_CLASS:
return compact ? "c" : "class";
case R_BIN_METH_STATIC:
return compact ? "s" : "static";
case R_BIN_METH_PUBLIC:
return compact ? "p" : "public";
case R_BIN_METH_PRIVATE:
return compact ? "P" : "private";
case R_BIN_METH_PROTECTED:
return compact ? "r" : "protected";
case R_BIN_METH_INTERNAL:
return compact ? "i" : "internal";
case R_BIN_METH_OPEN:
return compact ? "o" : "open";
case R_BIN_METH_FILEPRIVATE:
return compact ? "e" : "fileprivate";
case R_BIN_METH_FINAL:
return compact ? "f" : "final";
case R_BIN_METH_VIRTUAL:
return compact ? "v" : "virtual";
case R_BIN_METH_CONST:
return compact ? "k" : "const";
case R_BIN_METH_MUTATING:
return compact ? "m" : "mutating";
case R_BIN_METH_ABSTRACT:
return compact ? "a" : "abstract";
case R_BIN_METH_SYNCHRONIZED:
return compact ? "y" : "synchronized";
case R_BIN_METH_NATIVE:
return compact ? "n" : "native";
case R_BIN_METH_BRIDGE:
return compact ? "b" : "bridge";
case R_BIN_METH_VARARGS:
return compact ? "g" : "varargs";
case R_BIN_METH_SYNTHETIC:
return compact ? "h" : "synthetic";
case R_BIN_METH_STRICT:
return compact ? "t" : "strict";
case R_BIN_METH_MIRANDA:
return compact ? "A" : "miranda";
case R_BIN_METH_CONSTRUCTOR:
return compact ? "C" : "constructor";
case R_BIN_METH_DECLARED_SYNCHRONIZED:
return compact ? "Y" : "declared_synchronized";
default:
return NULL;
}
}

R_IPI RBinSection *r_bin_section_new(const char *name) {
RBinSection *s = R_NEW0 (RBinSection);
if (s) {
Expand Down Expand Up @@ -1532,116 +1585,9 @@ R_API void r_bin_name_free(RBinName *bn) {
}
}

static const char *attr_bit_name(ut64 n, bool compact) {
switch (n) {
case R_BIN_ATTR_HIDDEN:
return compact? "": "hidden";
case R_BIN_ATTR_FRIENDLY:
return compact? "": "friendly";
case R_BIN_ATTR_SEALED:
return compact? "": "sealed";
case R_BIN_ATTR_GLOBAL:
return compact? "": "global";
case R_BIN_ATTR_UNSAFE:
return compact? "": "unsafe";
case R_BIN_ATTR_EXTERN:
return compact? "": "extern";
case R_BIN_ATTR_READONLY:
return compact? "": "readonly";
case R_BIN_ATTR_INTERFACE:
return compact? "": "interface";
case R_BIN_ATTR_SYMBOLIC:
return compact? "": "symbolic";
case R_BIN_ATTR_VERIFIED:
return compact? "": "verified";
case R_BIN_ATTR_GETTER:
return compact? "": "getter";
case R_BIN_ATTR_SETTER:
return compact? "": "setter";
case R_BIN_ATTR_OPTIMIZED:
return compact? "": "optimized";
#if 0
case R_BIN_ATTR_ANNOTATED:
return compact? "": "anno";
#endif
case R_BIN_ATTR_ASYNC:
return compact? "": "async";
case R_BIN_ATTR_VOLATILE:
return compact? "": "volatile";
case R_BIN_ATTR_TRANSIENT:
return compact? "": "transient";
case R_BIN_ATTR_ENUM:
return compact? "": "enum";
case R_BIN_ATTR_RACIST:
return compact? "": "racist";
case R_BIN_ATTR_SUPER:
return compact ? "S": "super";
case R_BIN_ATTR_ANNOTATION:
return compact ? "A": "annotation";
case R_BIN_ATTR_WEAK:
return compact ? "w": "weak";
case R_BIN_ATTR_CLASS:
return compact ? "c" : "class";
case R_BIN_ATTR_STATIC:
return compact ? "s" : "static";
case R_BIN_ATTR_PUBLIC:
return compact ? "p" : "public";
case R_BIN_ATTR_PRIVATE:
return compact ? "P" : "private";
case R_BIN_ATTR_PROTECTED:
return compact ? "r" : "protected";
case R_BIN_ATTR_INTERNAL:
return compact ? "i" : "internal";
case R_BIN_ATTR_OPEN:
return compact ? "o" : "open";
case R_BIN_ATTR_FILEPRIVATE:
return compact ? "e" : "fileprivate";
case R_BIN_ATTR_FINAL:
return compact ? "f" : "final";
case R_BIN_ATTR_VIRTUAL:
return compact ? "v" : "virtual";
case R_BIN_ATTR_CONST:
return compact ? "k" : "const";
case R_BIN_ATTR_MUTATING:
return compact ? "m" : "mutating";
case R_BIN_ATTR_ABSTRACT:
return compact ? "a" : "abstract";
case R_BIN_ATTR_SYNCHRONIZED:
return compact ? "Y" : "synchronized";
case R_BIN_ATTR_NATIVE:
return compact ? "n" : "native";
case R_BIN_ATTR_BRIDGE:
return compact ? "b" : "bridge";
case R_BIN_ATTR_VARARGS:
return compact ? "g" : "varargs";
case R_BIN_ATTR_SYNTHETIC:
return compact ? "h" : "synthetic";
case R_BIN_ATTR_STRICT:
return compact ? "t" : "strict";
case R_BIN_ATTR_MIRANDA:
return compact ? "A" : "miranda";
case R_BIN_ATTR_CONSTRUCTOR:
return compact ? "C" : "constructor";
case R_BIN_ATTR_DECLARED_SYNCHRONIZED:
return compact ? "y" : "declared_synchronized";
default:
return NULL;
}
}

R_API char *r_bin_attr_tostring(ut64 attr, bool singlechar) {
int i;
RStrBuf *sb = r_strbuf_new ("");
for (i = 0; i < 64; i++) {
const ut64 bit = (1ULL << i);
if (attr & bit) {
if (!singlechar && !r_strbuf_is_empty (sb)) {
r_strbuf_append (sb, " ");
}
r_strbuf_append (sb, attr_bit_name (bit, singlechar));
}
}
return r_strbuf_drain (sb);
// TODO : not implemented yet
R_API char *r_bin_attr_tostring(ut64 attr) {
return NULL;
}

// TODO : not implemented yet
Expand Down
2 changes: 1 addition & 1 deletion libr/bin/format/mach0/mach0.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,7 +2940,7 @@ static void _enrich_symbol(RBinFile *bf, struct MACH0_(obj_t) *bin, HtPP *symcac
}

sym->forwarder = "NONE";
sym->bind = sym->type && r_str_startswith (sym->type, "LOCAL")? R_BIN_BIND_LOCAL_STR: R_BIN_BIND_GLOBAL_STR;
sym->bind = sym->type && !strncmp (sym->type, "LOCAL", 5)? R_BIN_BIND_LOCAL_STR: R_BIN_BIND_GLOBAL_STR;
sym->type = R_BIN_TYPE_FUNC_STR;

if (bin->hdr.cputype == CPU_TYPE_ARM && wordsize < 64) {
Expand Down
3 changes: 1 addition & 2 deletions libr/bin/format/objc/mach0_classes.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ static void get_method_list(mach0_ut p, RBinFile *bf, char *class_name, RBinClas
}
method->type = is_static? R_BIN_TYPE_FUNC_STR: R_BIN_TYPE_METH_STR;
if (is_static) {
// it's a clas method, aka does not require an instance
method->attr |= R_BIN_ATTR_CLASS;
method->method_flags |= R_BIN_METH_CLASS;
}
if (is_thumb (bf)) {
if (method->vaddr & 1) {
Expand Down
14 changes: 7 additions & 7 deletions libr/bin/mangling/objc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) {
r_return_val_if_fail ((!bf || (bf && bf->bo && bf->bo->classes)) && sym, NULL);
char *ret = NULL;
char *clas = NULL;
char *name = NULL;
char *args = NULL;
Expand All @@ -15,19 +16,19 @@ R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) {
bf = NULL;
}
/* classes */
if (r_str_startswith (sym, "_OBJC_Class_")) {
if (!strncmp (sym, "_OBJC_Class_", 12)) {
const char *className = sym + 12;
char *ret = r_str_newf ("class %s", className);
ret = r_str_newf ("class %s", className);
if (bf) {
r_bin_file_add_class (bf, className, NULL, R_BIN_ATTR_PUBLIC);
r_bin_file_add_class (bf, className, NULL, R_BIN_CLASS_PUBLIC);
}
return ret;
}
if (r_str_startswith (sym, "_OBJC_CLASS_$_")) {
if (!strncmp (sym, "_OBJC_CLASS_$_", 14)) {
const char *className = sym + 14;
char *ret = r_str_newf ("class %s", className);
ret = r_str_newf ("class %s", className);
if (bf) {
r_bin_file_add_class (bf, className, NULL, R_BIN_ATTR_PUBLIC);
r_bin_file_add_class (bf, className, NULL, R_BIN_CLASS_PUBLIC);
}
return ret;
}
Expand Down Expand Up @@ -107,7 +108,6 @@ R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) {
type = "static";
}
}
char *ret = NULL;
if (type) {
if (!strcmp (type, "field")) {
ret = r_str_newf ("field int %s::%s", clas, name);
Expand Down
36 changes: 18 additions & 18 deletions libr/bin/p/bin_dex.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,52 @@

extern struct r_bin_dbginfo_t r_bin_dbginfo_dex;

static ut64 get_method_attr(ut64 MA) {
static ut64 get_method_flags(ut64 MA) {
ut64 flags = 0;
if (MA & R_DEX_METH_PUBLIC) {
flags |= R_BIN_ATTR_PUBLIC;
flags |= R_BIN_METH_PUBLIC;
}
if (MA & R_DEX_METH_PRIVATE) {
flags |= R_BIN_ATTR_PRIVATE;
flags |= R_BIN_METH_PRIVATE;
}
if (MA & R_DEX_METH_PROTECTED) {
flags |= R_BIN_ATTR_PROTECTED;
flags |= R_BIN_METH_PROTECTED;
}
if (MA & R_DEX_METH_STATIC) {
flags |= R_BIN_ATTR_STATIC;
flags |= R_BIN_METH_STATIC;
}
if (MA & R_DEX_METH_FINAL) {
flags |= R_BIN_ATTR_FINAL;
flags |= R_BIN_METH_FINAL;
}
if (MA & R_DEX_METH_SYNCHRONIZED) {
flags |= R_BIN_ATTR_SYNCHRONIZED;
flags |= R_BIN_METH_SYNCHRONIZED;
}
if (MA & R_DEX_METH_BRIDGE) {
flags |= R_BIN_ATTR_BRIDGE;
flags |= R_BIN_METH_BRIDGE;
}
if (MA & R_DEX_METH_VARARGS) {
flags |= R_BIN_ATTR_VARARGS;
flags |= R_BIN_METH_VARARGS;
}
if (MA & R_DEX_METH_NATIVE) {
flags |= R_BIN_ATTR_NATIVE;
flags |= R_BIN_METH_NATIVE;
}
if (MA & R_DEX_METH_ABSTRACT) {
flags |= R_BIN_ATTR_ABSTRACT;
flags |= R_BIN_METH_ABSTRACT;
}
if (MA & R_DEX_METH_STRICT) {
flags |= R_BIN_ATTR_STRICT;
flags |= R_BIN_METH_STRICT;
}
if (MA & R_DEX_METH_SYNTHETIC) {
flags |= R_BIN_ATTR_SYNTHETIC;
flags |= R_BIN_METH_SYNTHETIC;
}
if (MA & R_DEX_METH_MIRANDA) {
flags |= R_BIN_ATTR_MIRANDA;
flags |= R_BIN_METH_MIRANDA;
}
if (MA & R_DEX_METH_CONSTRUCTOR) {
flags |= R_BIN_ATTR_CONSTRUCTOR;
flags |= R_BIN_METH_CONSTRUCTOR;
}
if (MA & R_DEX_METH_DECLARED_SYNCHRONIZED) {
flags |= R_BIN_ATTR_SYNCHRONIZED;
flags |= R_BIN_METH_DECLARED_SYNCHRONIZED;
}
return flags;
}
Expand Down Expand Up @@ -1091,7 +1091,7 @@ static void parse_dex_class_fields(RBinFile *bf, RBinDexClass *c, RBinClass *cls
if (field) {
field->vaddr = field->paddr = sym->paddr;
field->name = strdup (sym->name);
field->attr = get_method_attr (accessFlags);
field->flags = get_method_flags (accessFlags);
r_list_append (cls->fields, field);
}
lastIndex = fieldIndex;
Expand Down Expand Up @@ -1354,7 +1354,7 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls
dex->code_from = R_MIN (dex->code_from, sym->paddr);
sym->lang = R_BIN_LANG_JAVA;
sym->bind = ((MA & 1) == 1) ? R_BIN_BIND_GLOBAL_STR : R_BIN_BIND_LOCAL_STR;
sym->attr = get_method_attr (MA);
sym->method_flags = get_method_flags (MA);
sym->ordinal = (*sym_count)++;
if (MC > 0) {
if (bufsz < MC || bufsz < MC + 16) {
Expand Down
2 changes: 1 addition & 1 deletion libr/bin/p/bin_java.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2023 - pancake, nibble, dso */
/* radare - LGPL - Copyright 2009-2023 - pancake, nibble, Adam Pridgen <dso@rice.edu || adam.pridgen@thecoverofnight.com> */

#define R_LOG_ORIGIN "bin.java"

Expand Down
Loading

0 comments on commit 88c9dc3

Please sign in to comment.