Skip to content

Commit

Permalink
Fix endianness in arm64 writer literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 9, 2025
1 parent e18d5cf commit c395225
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions gum/arch-arm64/gumarm64writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1992,15 +1992,21 @@ gum_arm64_writer_commit_literals (GumArm64Writer * self)
if (r->width != GUM_LITERAL_64BIT)
continue;

/*
* Whilst instructions in aarch64 are always in little endian (even on
* big-endian systems), the data is in native endian. Thus we don't need
* to make use of the GINT64_FROM_LE and GINT64_TO_LE when accessing the
* "slot" below.
*/
for (slot = first_slot; slot != last_slot; slot++)
{
if (GINT64_FROM_LE (*slot) == r->val)
if (*slot == r->val)
break;
}

if (slot == last_slot)
{
*slot = GINT64_TO_LE (r->val);
*slot = r->val;
last_slot = slot + 1;
}

Expand All @@ -2024,15 +2030,21 @@ gum_arm64_writer_commit_literals (GumArm64Writer * self)
if (r->width != GUM_LITERAL_32BIT)
continue;

/*
* Whilst instructions in aarch64 are always in little endian (even on
* big-endian systems), the data is in native endian. Thus we don't need
* to make use of the GINT64_FROM_LE and GINT64_TO_LE when accessing the
* "slot" below.
*/
for (slot = first_slot; slot != last_slot; slot++)
{
if (GINT32_FROM_LE (*slot) == r->val)
if (*slot == r->val)
break;
}

if (slot == last_slot)
{
*slot = GINT32_TO_LE (r->val);
*slot = r->val;
last_slot = slot + 1;
}

Expand Down

0 comments on commit c395225

Please sign in to comment.