Skip to content

Commit

Permalink
Add test for eoi insn in it block
Browse files Browse the repository at this point in the history
  • Loading branch information
bet4it committed May 16, 2020
1 parent f72fdd3 commit 45caf29
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/core/arch-arm/thumbrelocator.c
Expand Up @@ -30,6 +30,7 @@ TESTLIST_BEGIN (thumbrelocator)
TESTENTRY (it_block_with_pc_relative_load_should_be_rewritten)
TESTENTRY (it_block_with_b_should_be_rewritten)
TESTENTRY (it_block_should_be_rewritten_as_a_whole)
TESTENTRY (it_block_with_eoi_insn_should_be_rewritten)
TESTENTRY (eob_and_eoi_on_ret)
TESTLIST_END ()

Expand Down Expand Up @@ -760,6 +761,52 @@ TESTCASE (it_block_should_be_rewritten_as_a_whole)
sizeof (expected_output));
}

TESTCASE (it_block_with_eoi_insn_should_be_rewritten)
{
const guint16 input[] = {
GUINT16_TO_LE (0x2800), /* cmp r0, #0 */
GUINT16_TO_LE (0xbf18), /* it ne */
GUINT16_TO_LE (0xe8bd), /* ... */
GUINT16_TO_LE (0x8010), /* pop.w {r4, pc} */
GUINT16_TO_LE (0x3001), /* adds r0, #1 */
};
const guint16 expected_output[] = {
GUINT16_TO_LE (0x2800), /* cmp r0, #0 */
GUINT16_TO_LE (0xd100), /* bne.n .L1 */
GUINT16_TO_LE (0xe001), /* b.n .L2 */
GUINT16_TO_LE (0xe8bd), /* .L1 ... */
GUINT16_TO_LE (0x8010), /* pop.w {r4, pc} */
GUINT16_TO_LE (0x3001), /* .L2: adds r0, #1 */
};
const cs_insn * insn;

SETUP_RELOCATOR_WITH (input);

insn = NULL;
g_assert_cmpuint (gum_thumb_relocator_read_one (&fixture->rl, &insn), ==, 2);
g_assert_cmpint (insn->id, ==, ARM_INS_CMP);
assert_outbuf_still_zeroed_from_offset (0);

insn = NULL;
g_assert_cmpuint (gum_thumb_relocator_read_one (&fixture->rl, &insn), ==, 8);
g_assert_cmpint (insn->id, ==, ARM_INS_IT);
assert_outbuf_still_zeroed_from_offset (0);

insn = NULL;
g_assert_cmpuint (gum_thumb_relocator_read_one (&fixture->rl, &insn), ==, 10);
g_assert_cmpint (insn->id, ==, ARM_INS_ADD);
assert_outbuf_still_zeroed_from_offset (0);

g_assert_true (gum_thumb_relocator_write_one (&fixture->rl));
g_assert_true (gum_thumb_relocator_write_one (&fixture->rl));
g_assert_true (gum_thumb_relocator_write_one (&fixture->rl));
g_assert_true (gum_thumb_relocator_write_one (&fixture->rl));
g_assert_false (gum_thumb_relocator_write_one (&fixture->rl));

g_assert_cmpint (memcmp (fixture->output, expected_output,
sizeof (expected_output)), ==, 0);
}

TESTCASE (eob_and_eoi_on_ret)
{
const guint16 input[] = {
Expand Down

0 comments on commit 45caf29

Please sign in to comment.