bool test_r_list_length(void) { RList* list = r_list_new (); RList* list2 = r_list_new (); RListIter *iter; int count = 0; int test1 = 33508; int test2 = 33480; int test3 = 33964; // Put in not sorted order. r_list_append (list, (void*)&test1); r_list_append (list, (void*)&test3); r_list_append (list, (void*)&test2); iter = list->head; while (iter) { count++; iter = iter->n; } mu_assert_eq (list->length, 3, "First length check"); r_list_delete_data (list, (void*)&test1); mu_assert_eq (list->length, 2, "Second length check"); r_list_append (list, (void*)&test1); mu_assert_eq (list->length, 3, "Third length check"); r_list_pop (list); mu_assert_eq (list->length, 2, "Fourth length check"); r_list_pop_head (list); mu_assert_eq (list->length, 1, "Fifth length check"); r_list_insert (list, 2, (void*)&test2); mu_assert_eq (list->length, 2, "Sixth length check"); r_list_prepend (list, (void*)&test3); mu_assert_eq (list->length, 3, "Seventh length check"); r_list_del_n (list, 2); mu_assert_eq (list->length, 2, "Eighth length check"); r_list_append (list2, (void*)&test1); r_list_append (list2, (void*)&test3); r_list_append (list2, (void*)&test2); r_list_join (list, list2); mu_assert_eq (list->length, 5, "Ninth length check"); iter = list->head; count = 0; while (iter) { count++; iter = iter->n; } mu_assert_eq (list->length, count, "Tenth length check"); r_list_free (list); r_list_free (list2); mu_end; }
char* test_r_list_join(void) { RList* list1 = r_list_new (); RList* list2 = r_list_new (); intptr_t test1 = 0x12345; intptr_t test2 = 0x88888; r_list_append (list1, (void*)test1); r_list_append (list2, (void*)test2); mu_assert("r_list_join returned non-success", r_list_join (list1, list2) == 1); mu_assert("r_list_join two single element lists result length is 1", r_list_length (list1) == 2); return NULL; }
bool test_r_list_join(void) { RList* list1 = r_list_new (); RList* list2 = r_list_new (); intptr_t test1 = 0x12345; intptr_t test2 = 0x88888; r_list_append (list1, (void*)test1); r_list_append (list2, (void*)test2); int joined = r_list_join (list1, list2); mu_assert_eq(joined, 1, "r_list_join of two lists"); mu_assert_eq(r_list_length (list1), 2, "r_list_join two single element lists result length is 1"); r_list_free (list1); r_list_free (list2); mu_end; }
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) { RAnalVar *var; RListIter *iter; char oldstr[64], newstr[64]; char *tstr = strdup (data); RList *vars, *args; if (!p->varlist) { free (tstr); return false; } vars = p->varlist (p->anal, f, 'v'); args = p->varlist (p->anal, f, 'a'); r_list_join (vars, args); switch (p->anal->bits) { case 64: r_list_foreach (vars, iter, var) { if (var->delta < 10) snprintf (oldstr, sizeof (oldstr)-1, "[%s, %d]", p->anal->reg->name[R_REG_NAME_BP], var->delta); else snprintf (oldstr, sizeof (oldstr)-1, "[%s, 0x%x]", p->anal->reg->name[R_REG_NAME_BP], var->delta); snprintf (newstr, sizeof (newstr)-1, "[%s+%s]", p->anal->reg->name[R_REG_NAME_BP], var->name); if (strstr (tstr, oldstr) != NULL) { tstr = r_str_replace (tstr, oldstr, newstr, 1); break; } // Try with no spaces snprintf (oldstr, sizeof (oldstr)-1, "[%s+0x%x]", p->anal->reg->name[R_REG_NAME_BP], var->delta); if (strstr (tstr, oldstr) != NULL) { tstr = r_str_replace (tstr, oldstr, newstr, 1); break; } } break; case 32: r_list_foreach (vars, iter, var) { if (var->delta < 10) snprintf (oldstr, sizeof (oldstr)-1, "[%s, -%d]", p->anal->reg->name[R_REG_NAME_BP], var->delta); else snprintf (oldstr, sizeof (oldstr)-1, "[%s, -0x%x]", p->anal->reg->name[R_REG_NAME_BP], var->delta); snprintf (newstr, sizeof (newstr)-1, "[%s-%s]", p->anal->reg->name[R_REG_NAME_BP], var->name); if (strstr (tstr, oldstr) != NULL) { tstr = r_str_replace (tstr, oldstr, newstr, 1); break; } // Try with no spaces snprintf (oldstr, sizeof (oldstr)-1, "[%s-0x%x]", p->anal->reg->name[R_REG_NAME_BP], var->delta); if (strstr (tstr, oldstr) != NULL) { tstr = r_str_replace (tstr, oldstr, newstr, 1); break; } } break; case 16: // break; } if (len > strlen (tstr)) { strncpy (str, tstr, strlen (tstr)); str[strlen (tstr)] = 0; } else { // TOO BIG STRING CANNOT REPLACE HERE free (tstr); return false; } free (tstr); return true; }
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) { #if USE_VARSUBS int i; char *ptr, *ptr2; for (i = 0; i < R_ANAL_VARSUBS; i++) if (f->varsubs[i].pat[0] != '\0' && \ f->varsubs[i].sub[0] != '\0' && \ (ptr = strstr (data, f->varsubs[i].pat))) { *ptr = '\0'; ptr2 = ptr + strlen (f->varsubs[i].pat); snprintf (str, len, "%s%s%s", data, f->varsubs[i].sub, ptr2); } return R_TRUE; #else RAnalVar *var; RListIter *iter; char oldstr[64], newstr[64]; char *tstr = strdup (data); RList *vars, *args; if (!p->varlist) { free(tstr); return R_FALSE; } vars = p->varlist (p->anal, f, 'v'); args = p->varlist (p->anal, f, 'a'); r_list_join (vars, args); r_list_foreach (vars, iter, var) { if (var->delta < 10) snprintf (oldstr, sizeof (oldstr)-1, "[%s - %d]", p->anal->reg->name[R_REG_NAME_BP], var->delta); else snprintf (oldstr, sizeof (oldstr)-1, "[%s - 0x%x]", p->anal->reg->name[R_REG_NAME_BP], var->delta); snprintf (newstr, sizeof (newstr)-1, "[%s-%s]", p->anal->reg->name[R_REG_NAME_BP], var->name); if (strstr (tstr, oldstr) != NULL) { tstr = r_str_replace (tstr, oldstr, newstr, 1); break; } // Try with no spaces snprintf (oldstr, sizeof (oldstr)-1, "[%s-0x%x]", p->anal->reg->name[R_REG_NAME_BP], var->delta); if (strstr (tstr, oldstr) != NULL) { tstr = r_str_replace (tstr, oldstr, newstr, 1); break; } } if (len > strlen (tstr)) { strncpy (str, tstr, strlen(tstr)); str[strlen (tstr)] = 0; } else { // TOO BIG STRING CANNOT REPLACE HERE return R_FALSE; } free (tstr); return R_TRUE; #endif }