12 char *
line, *data, *str_n;
18 line = strtok(str_n,
"\n");
19 data = strchr(
line,
'=');
36 p = strtok(data,
",");
38 if (strtol(
p,
NULL, 0)) {
41 p = strtok(
NULL,
",");
50 if (!strcmp(
type,
"flg"))
64 if (!strcmp(
op,
"^")) {
65 *result = src1 ^ src2;
68 if (!strcmp(
op,
"+")) {
69 *result = src1 + src2;
72 if (!strcmp(
op,
"-")) {
74 *result =
limit + (src1 - src2);
76 *result = src1 - src2;
80 if (!strcmp(
op,
"*")) {
81 *result = src1 * src2;
84 if (!strcmp(
op,
"|")) {
85 *result = src1 | src2;
88 if (!strcmp(
op,
"/")) {
89 *result = src1 / src2;
92 if (!strcmp(
op,
"%")) {
93 *result = src1 % src2;
96 if (!strcmp(
op,
"<<")) {
97 *result = src1 << src2;
100 if (!strcmp(
op,
">>")) {
101 *result = src1 >> src2;
104 if (!strcmp(
op,
"&")) {
105 *result = src1 & src2;
108 if (!strcmp(
op,
"+=")) {
109 *result = old_src1 + src2;
112 if (!strcmp(
op,
"-=")) {
113 if (src2 > old_src1) {
114 *result =
limit + (old_src1 - src2);
116 *result = old_src1 - src2;
120 if (!strcmp(
op,
"*=")) {
121 *result = old_src1 * src2;
124 if (!strcmp(
op,
"/=")) {
125 *result = old_src1 / src2;
128 if (!strcmp(
op,
"%=")) {
129 *result = old_src1 % src2;
132 if (!strcmp(
op,
"<<")) {
133 *result = src1 << src2;
136 if (!strcmp(
op,
">>")) {
137 *result = src1 >> src2;
140 if (!strcmp(
op,
"&=")) {
141 *result = src1 & src2;
144 if (!strcmp(
op,
"^=")) {
145 *result = src1 ^ src2;
148 if (!strcmp(
op,
"|=")) {
149 *result = src1 | src2;
165 rz_list_foreach (
regs, iter_reg, reg_item) {
177 char *split = strstr(esil_str,
"f,=");
178 const int kCommaHits = 2;
182 while (hits != kCommaHits) {
188 *esil_flg =
strdup(++split);
189 *esil_main =
rz_str_ndup(esil_str, strlen(esil_str) - strlen(*esil_flg) - 1);
197 RZ_FREE(esil_main); \
198 rz_list_free(ops_list); \
200 rz_list_free(flg_read); \
202 rz_list_free(flg_write); \
204 rz_list_free(reg_read); \
206 rz_list_free(reg_write); \
208 rz_list_free(mem_read); \
210 rz_list_free(mem_write); \
215 char *esil_str, *constant;
227 if (!romem || !stats) {
232 rz_list_foreach (ropList, iter_r, esil_str) {
235 if (rz_list_empty(constants)) {
265 rz_list_foreach (
head, iter_dst, item_dst) {
266 ut64 diff_dst, value_dst;
279 if (value_dst != diff_dst) {
280 rz_list_foreach (constants, iter_const, constant) {
312 if (!romem || !stats) {
317 rz_list_foreach (ropList, iter_r, esil_str) {
347 rz_list_foreach (
head, iter_dst, item_dst) {
348 ut64 diff_dst, value_dst;
363 rz_list_foreach (
head, iter_src, item_src) {
364 ut64 diff_src, value_src;
370 if (item_src == item_dst ||
isFlag(item_src)) {
379 if (value_dst == value_src && value_dst != diff_dst) {
398 RzListIter *iter_src1, *iter_src2, *iter_r, *iter_dst, *iter_ops;
399 RzRegItem *item_src1, *item_src2, *item_dst;
409 if (!romem || !stats) {
416 rz_list_foreach (ropList, iter_r, esil_str) {
442 rz_list_foreach (ops_list, iter_ops,
op) {
443 rz_list_foreach (
head, iter_src1, item_src1) {
444 ut64 value_src1, diff_src1;
455 rz_list_foreach (
head, iter_src2, item_src2) {
456 ut64 value_src2, diff_src2;
466 if (iter_src1 == iter_src2) {
470 rz_list_foreach (
head, iter_dst, item_dst) {
472 bool redundant =
false, simulate, simulate_r;
484 simulate =
simulate_op(
op, value_src1, value_src2, diff_src1, diff_src2, op_result, item_dst->
size);
485 simulate_r =
simulate_op(
op, value_src2, value_src1, diff_src2, diff_src1, op_result_r, item_dst->
size);
486 if ( simulate && value_dst == *op_result) {
495 }
else if (!redundant && simulate_r && value_dst == *op_result_r) {
523 char *esil_str, *
op, *constant;
525 RzListIter *iter_src1, *iter_r, *iter_dst, *iter_ops, *iter_const;
536 if (!romem || !stats) {
543 rz_list_foreach (ropList, iter_r, esil_str) {
546 if (rz_list_empty(constants)) {
578 rz_list_foreach (ops_list, iter_ops,
op) {
579 rz_list_foreach (
head, iter_src1, item_src1) {
580 ut64 value_src1, diff_src1;
590 rz_list_foreach (
head, iter_dst, item_dst) {
591 ut64 value_dst, diff_dst;
592 bool redundant =
false, simulate, simulate_r;
605 if (value_dst != diff_dst) {
606 rz_list_foreach (constants, iter_const, constant) {
609 diff_src1, value_ct, op_result,
612 value_ct, diff_src1, op_result_r,
614 if (simulate && op_result && value_dst == *op_result) {
623 }
else if (!redundant && simulate_r && value_dst == *op_result_r) {
653 if (!romem || !stats) {
658 rz_list_foreach (ropList, iter_r, esil_str) {
679 char *
mov, *ct, *arithm, *arithm_ct, *
str;
683 Sdb *db_aritm =
sdb_ns(db,
"arithm",
true);
684 Sdb *db_aritm_ct =
sdb_ns(db,
"arithm_ct",
true);
686 if (!db_nop || !db_mov || !db_ct || !db_aritm || !db_aritm_ct) {
687 eprintf(
"Error: Could not create SDB 'rop' sub-namespaces\n");
715 char *str_arithm =
rz_str_newf(
"%s ARITHMETIC { %s }",
str, arithm);
721 char *str_arithm_ct =
rz_str_newf(
"%s ARITHMETIC_CONST { %s }",
str, arithm_ct);
RZ_API int rz_reg_arena_push(RzReg *reg)
RZ_API void rz_reg_arena_pop(RzReg *reg)
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
static RzILOpEffect * mov(cs_insn *insn, bool is_thumb)
static ut32 arithmetic(ArmOp *op, int k)
const lzma_allocator const uint8_t size_t uint8_t * out
static int mem_read(struct mem_file *fh, void *buffer, int bytes)
static int mem_write(struct mem_file *fh, void *buffer, int bytes)
static void cmd_analysis_esil(RzCore *core, const char *input)
static RzList * get_constants(const char *str)
static char * rop_classify_mov(RzCore *core, RzList *ropList)
static bool isFlag(RzRegItem *reg)
static void rop_classify(RzCore *core, Sdb *db, RzList *ropList, const char *key, unsigned int size)
static void fillRegisterValues(RzCore *core)
static char * rop_classify_arithmetic(RzCore *core, RzList *ropList)
static char * rop_classify_constant(RzCore *core, RzList *ropList)
static char * rop_classify_arithmetic_const(RzCore *core, RzList *ropList)
static void esil_split_flg(char *esil_str, char **esil_main, char **esil_flg)
static int rop_classify_nops(RzCore *core, RzList *ropList)
static bool simulate_op(const char *op, ut64 src1, ut64 src2, ut64 old_src1, ut64 old_src2, ut64 *result, int size)
static RzList * parse_list(const char *str)
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
RZ_API void Ht_() free(HtName_(Ht) *ht)
static void list(RzEgg *egg)
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
RZ_API char * sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd)
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static uint32_t const uint8_t uint32_t uint32_t limit
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
RZ_API const char * rz_reg_get_type(int idx)
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
int(* RzListComparator)(const void *value, const void *list_data)
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
RZ_API RzList * rz_str_split_duplist(const char *str, const char *c, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
struct rz_analysis_esil_t * esil
int size
in bits> 8,16,32,64 ... 128/256
ut64(WINAPI *w32_GetEnabledXStateFeatures)()