Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
WorksButNotTested committed Jan 24, 2025
1 parent 65be963 commit eec2250
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
22 changes: 5 additions & 17 deletions gum/arch-arm64/gumarm64writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ gum_arm64_writer_init (GumArm64Writer * writer,
writer->ref_count = 1;
writer->flush_on_destroy = TRUE;

writer->data_endian = __BYTE_ORDER__;
writer->target_os = gum_process_get_native_os ();
writer->ptrauth_support = gum_query_ptrauth_support ();
writer->sign = gum_sign_code_address;

writer->label_defs = NULL;
writer->label_refs.data = NULL;
writer->literal_refs.data = NULL;
writer->data_endian = GUM_ENDIAN_NATIVE;

gum_arm64_writer_reset (writer, code_address);
}
Expand Down Expand Up @@ -1993,15 +1993,9 @@ 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 since we wish to
* support writing code for big-endian systems on little-endian targets and
* vice versa, we need to check the writer configuration.
*/
for (slot = first_slot; slot != last_slot; slot++)
{
if (self->data_endian == GUM_ENDIAN_LITTLE)
if (self->data_endian == __ORDER_LITTLE_ENDIAN__)
{
if (GINT64_FROM_LE (*slot) == r->val)
break;
Expand All @@ -2016,7 +2010,7 @@ gum_arm64_writer_commit_literals (GumArm64Writer * self)

if (slot == last_slot)
{
if (self->data_endian == GUM_ENDIAN_LITTLE)
if (self->data_endian == __ORDER_LITTLE_ENDIAN__)
{
*slot = GINT64_TO_LE (r->val);
}
Expand Down Expand Up @@ -2047,15 +2041,9 @@ 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 since we wish to
* support writing code for big-endian systems on little-endian targets and
* vice versa, we need to check the writer configuration.
*/
for (slot = first_slot; slot != last_slot; slot++)
{
if (self->data_endian == GUM_ENDIAN_LITTLE)
if (self->data_endian == __ORDER_LITTLE_ENDIAN__)
{
if (GINT32_FROM_LE (*slot) == r->val)
break;
Expand All @@ -2069,7 +2057,7 @@ gum_arm64_writer_commit_literals (GumArm64Writer * self)

if (slot == last_slot)
{
if (self->data_endian == GUM_ENDIAN_LITTLE)
if (self->data_endian == __ORDER_LITTLE_ENDIAN__)
{
*slot = GINT32_TO_LE (r->val);
}
Expand Down
23 changes: 14 additions & 9 deletions gum/arch-arm64/gumarm64writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@ G_BEGIN_DECLS

typedef struct _GumArm64Writer GumArm64Writer;
typedef guint GumArm64IndexMode;

/*
* Valid values for this field are:
* - __ORDER_LITTLE_ENDIAN__
* - __ORDER_BIG_ENDIAN__
* - __BYTE_ORDER__ (an alias for one of the above)
*/
typedef guint GumArm64DataEndian;

struct _GumArm64Writer
{
volatile gint ref_count;
gboolean flush_on_destroy;

/*
* Whilst instructions in AArch64 are always in little endian (even on
* big-endian systems), the data is in native endian. Thus since we wish to
* support writing code for big-endian systems on little-endian targets and
* vice versa, we need to check the writer configuration before writing data.
*/
GumArm64DataEndian data_endian;
GumOS target_os;
GumPtrauthSupport ptrauth_support;
GumAddress (* sign) (GumAddress value);
Expand All @@ -52,15 +66,6 @@ struct _GumArm64Writer
GumMetalArray label_refs;
GumMetalArray literal_refs;
const guint32 * earliest_literal_insn;

GumArm64DataEndian data_endian;
};

enum _GumArm64DataEndian
{
GUM_ENDIAN_LITTLE = __ORDER_LITTLE_ENDIAN__,
GUM_ENDIAN_BIG = __ORDER_BIG_ENDIAN__,
GUM_ENDIAN_NATIVE = __BYTE_ORDER__,
};

enum _GumArm64IndexMode
Expand Down

0 comments on commit eec2250

Please sign in to comment.