diff --git a/gum/arch-arm64/gumarm64writer.c b/gum/arch-arm64/gumarm64writer.c index 42683f470..55714eeb8 100644 --- a/gum/arch-arm64/gumarm64writer.c +++ b/gum/arch-arm64/gumarm64writer.c @@ -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; } @@ -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; } diff --git a/gum/gumdefs.h b/gum/gumdefs.h index afec756d8..47fb395f5 100644 --- a/gum/gumdefs.h +++ b/gum/gumdefs.h @@ -119,9 +119,10 @@ typedef GumMipsCpuContext GumCpuContext; * The only non-legacy big-endian configuration on 32-bit ARM systems is BE8. * In this configuration, whilst the data is in big-endian, the code stream is * still in little-endian. Since Capstone is disassembling the code stream, it - * should work in little-endian even on BE8 systems. + * should work in little-endian even on BE8 systems. On big-endian 64-bit ARM + * systems, the code stream is likewise in little-endian. */ -#if G_BYTE_ORDER == G_LITTLE_ENDIAN || defined (__arm__) +#if G_BYTE_ORDER == G_LITTLE_ENDIAN || defined (__arm__) || defined (__aarch64__) # define GUM_DEFAULT_CS_ENDIAN CS_MODE_LITTLE_ENDIAN #else # define GUM_DEFAULT_CS_ENDIAN CS_MODE_BIG_ENDIAN