Skip to content

Commit

Permalink
stalker-arm: add another test and fix previous one
Browse files Browse the repository at this point in the history
  • Loading branch information
s1341 committed Feb 13, 2024
1 parent 3e13506 commit cf3604f
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/core/arch-arm/stalker-arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ TESTLIST_BEGIN (stalker)

TESTENTRY (custom_transformer)
TESTENTRY (arm_transformer_should_be_able_to_replace_call_with_callout)
TESTENTRY (arm_transformer_should_be_able_to_replace_jumpout_with_callout)
TESTENTRY (arm_callout)
TESTENTRY (thumb_callout)
TESTENTRY (unfollow_should_be_allowed_before_first_transform)
Expand Down Expand Up @@ -141,6 +142,8 @@ static void duplicate_adds (GumStalkerIterator * iterator,
GumStalkerOutput * output, gpointer user_data);
static void replace_call_with_callout (GumStalkerIterator * iterator,
GumStalkerOutput * output, gpointer user_data);
static void replace_jumpout_with_callout (GumStalkerIterator * iterator,
GumStalkerOutput * output, gpointer user_data);
static void callout_set_cool (GumCpuContext * cpu_context, gpointer user_data);
static void transform_arm_return_value (GumStalkerIterator * iterator,
GumStalkerOutput * output, gpointer user_data);
Expand Down Expand Up @@ -3238,7 +3241,7 @@ TESTCASE (arm_transformer_should_be_able_to_replace_call_with_callout)
memcpy (code, arm_simple_call, CODE_SIZE (arm_simple_call));

fixture->transformer = gum_stalker_transformer_make_from_callback (
insert_callout_after_cmp, NULL, NULL);
replace_call_with_callout, NULL, NULL);

INVOKE_ARM_EXPECTING (GUM_EXEC, code, 0xc001);
}
Expand All @@ -3264,6 +3267,48 @@ replace_call_with_callout (GumStalkerIterator * iterator,
}
}

TESTCODE (arm_simple_jumpout,
0x14, 0x05, 0x00, 0xe3, /* mov r0, 1300 */
0xff, 0xff, 0xff, 0xea, /* b bump_number */
/* bump_number: */
0x25, 0x00, 0x80, 0xe2, /* add r0, 37 */
0x1e, 0xff, 0x2f, 0xe1, /* bx lr */
);

TESTCASE (arm_transformer_should_be_able_to_replace_jumpout_with_callout)
{
guint32 code[CODE_SIZE (Arm_simple_jumpout) / sizeof (guint32)], val;

memcpy (code, arm_simple_jumpout, CODE_SIZE (arm_simple_jumpout));

fixture->transformer = gum_stalker_transformer_make_from_callback (
replace_jumpout_with_callout, NULL, NULL);

INVOKE_ARM_EXPECTING (GUM_EXEC, code, 0xc001);
}

static void
replace_jumpout_with_callout (GumStalkerIterator * iterator,
GumStalkerOutput * output,
gpointer user_data)
{
gint * num_cmp_callouts = user_data;
GumMemoryAccess access;
const cs_insn * insn;

while (gum_stalker_iterator_next (iterator, &insn))
{
if (insn->id == ARM_INS_B)
{
gum_stalker_iterator_put_callout (iterator, callout_set_cool,
NULL, NULL);
gum_stalker_iterator_put_chaining_return (iterator);
continue;
}
gum_stalker_iterator_keep (iterator);
}
}

static void
callout_set_cool (GumCpuContext * cpu_context,
gpointer user_data)
Expand Down

0 comments on commit cf3604f

Please sign in to comment.