Initial implementation of RAnalDataType ##anal (#13111)

This commit is contained in:
radare 2019-02-17 23:55:10 +01:00 committed by GitHub
parent 202fb34a5e
commit f51e600340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 2 deletions

View File

@ -412,3 +412,29 @@ R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len)
}
return "data";
}
R_API const char *r_anal_datatype_to_string(RAnalDataType t) {
switch (t) {
case R_ANAL_DATATYPE_NULL:
return NULL;
case R_ANAL_DATATYPE_ARRAY:
return "array";
case R_ANAL_DATATYPE_OBJECT: // instance
return "object";
case R_ANAL_DATATYPE_STRING:
return "string";
case R_ANAL_DATATYPE_CLASS:
return "class";
case R_ANAL_DATATYPE_BOOLEAN:
return "boolean";
case R_ANAL_DATATYPE_INT16:
return "int16";
case R_ANAL_DATATYPE_INT32:
return "int32";
case R_ANAL_DATATYPE_INT64:
return "int64";
case R_ANAL_DATATYPE_FLOAT:
return "float";
}
return NULL;
}

View File

@ -139,16 +139,19 @@ static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l
break;
case 0x1a: // const-string
op->type = R_ANAL_OP_TYPE_MOV;
op->datatype = R_ANAL_DATATYPE_STRING;
if (len > 2) {
ut32 vA = data[1];
ut32 vB = (data[3]<<8) | data[2];
ut64 offset = R_ANAL_GET_OFFSET (anal, 's', vB);
op->ptr = offset;
op->refptr = 0;
esilprintf (op, "0x%"PFMT64x",v%d,=", offset, vA);
}
break;
case 0x1c: // const-class
op->type = R_ANAL_OP_TYPE_MOV;
op->datatype = R_ANAL_DATATYPE_CLASS;
break;
case 0x89: // float-to-double
case 0x8a: // double-to-int
@ -174,6 +177,7 @@ static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l
break;
case 0x8f: // int-to-short
op->type = R_ANAL_OP_TYPE_CAST;
// op->datatype = R_ANAL_DATATYPE_INT32 | R_ANAL_DATATYPE_INT16;
{
ut32 vA = (data[1] & 0x0f);
ut32 vB = (data[1] & 0xf0) >> 4;
@ -191,12 +195,12 @@ static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l
case 0x20: // instance-of
{
op->type = R_ANAL_OP_TYPE_CMP;
esilprintf (op, "%d,instanceof,%d,-,!,v%d,=", vC, vB, vA);
}
break;
case 0x21: // array-length
op->type = R_ANAL_OP_TYPE_LENGTH;
op->datatype = R_ANAL_DATATYPE_ARRAY;
break;
case 0x44: // aget
case 0x45: //aget-bool
@ -240,9 +244,20 @@ static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l
}
break;
case 0x63: // sget-boolean
{
const char *vT = "-boolean";
op->datatype = R_ANAL_DATATYPE_BOOLEAN;
op->type = R_ANAL_OP_TYPE_LOAD;
ut32 vA = (data[1] & 0x0f);
ut32 vB = (data[1] & 0xf0) >> 4;
ut32 vC = (data[2] & 0x0f);
esilprintf (op, "%d,%d,sget%s,v%d,=", vC, vB, vT, vA);
}
break;
case 0x62: // sget-object
{
const char *vT = "-object";
op->datatype = R_ANAL_DATATYPE_OBJECT;
op->type = R_ANAL_OP_TYPE_LOAD;
ut32 vA = (data[1] & 0x0f);
ut32 vB = (data[1] & 0xf0) >> 4;

View File

@ -1544,6 +1544,13 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
}
pj_ki (pj, "size", size);
pj_ks (pj, "type", r_anal_optype_to_string (op.type));
{
const char *datatype = r_anal_datatype_to_string (op.datatype);
if (datatype) {
pj_ks (pj, "datatype", datatype);
}
}
pj_ks (pj, "reg", op.reg);
pj_ks (pj, "ireg", op.ireg);
pj_ki (pj, "scale", op.scale);
@ -1625,6 +1632,10 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
printline ("size", "%d\n", size);
printline ("sign", "%s\n", r_str_bool (op.sign));
printline ("type", "%s\n", r_anal_optype_to_string (op.type));
const char *datatype = r_anal_datatype_to_string (op.datatype);
if (datatype) {
printline ("datatype", "%s\n", datatype);
}
printline ("cycles", "%d\n", op.cycles);
if (op.failcycles) {
printline ("failcycles", "%d\n", op.failcycles);

View File

@ -791,6 +791,19 @@ enum RAnalOpDirection {
R_ANAL_OP_DIR_REF = 8,
};
typedef enum r_anal_data_type_t {
R_ANAL_DATATYPE_NULL = 0,
R_ANAL_DATATYPE_ARRAY,
R_ANAL_DATATYPE_OBJECT, // instance
R_ANAL_DATATYPE_STRING,
R_ANAL_DATATYPE_CLASS,
R_ANAL_DATATYPE_BOOLEAN,
R_ANAL_DATATYPE_INT16,
R_ANAL_DATATYPE_INT32,
R_ANAL_DATATYPE_INT64,
R_ANAL_DATATYPE_FLOAT,
} RAnalDataType;
typedef struct r_anal_op_t {
char *mnemonic; /* mnemonic */
ut64 addr; /* address */
@ -830,6 +843,7 @@ typedef struct r_anal_op_t {
ut64 disp;
RAnalSwitchOp *switch_op;
RAnalHint hint;
RAnalDataType datatype;
} RAnalOp;
#define R_ANAL_COND_SINGLE(x) (!x->arg[1] || x->arg[0]==x->arg[1])
@ -1287,6 +1301,7 @@ R_API RAnalType *r_anal_type_new(void);
R_API void r_anal_type_add(RAnal *l, RAnalType *t);
R_API RAnalType *r_anal_type_find(RAnal *a, const char* name);
R_API void r_anal_type_list(RAnal *a, short category, short enabled);
R_API const char *r_anal_datatype_to_string(RAnalDataType t);
R_API RAnalType *r_anal_str_to_type(RAnal *a, const char* s);
R_API bool r_anal_op_nonlinear(int t);
R_API bool r_anal_op_ismemref(int t);

View File

@ -277,7 +277,7 @@ typedef struct r_bin_file_t {
struct r_bin_t *rbin;
} RBinFile;
typedef struct RBinFileOptions {
typedef struct r_bin_file_options_t {
int rawstr;
ut64 baddr; // base address
ut64 laddr; // load address