Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darwin-grafter: Use Arm64Relocator to support PIC #744

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions gum/gumdarwingrafter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2021-2023 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2021-2023 Francesco Tamagni <mrmacete@protonmail.ch>
*
* Licence: wxWindows Library Licence, Version 3.1
Expand All @@ -10,6 +10,7 @@
#include "gumdarwingrafter-priv.h"
#include "gumdarwinmodule-priv.h"
#include "gumleb.h"
#include "arch-arm64/gumarm64relocator.h"

#include <glib/gprintf.h>
#include <errno.h>
Expand Down Expand Up @@ -1228,9 +1229,11 @@ gum_darwin_grafter_emit_segments (gpointer output,
{
gboolean success = FALSE;
GumArm64Writer cw;
GumArm64Relocator rl;
guint i, j;

gum_arm64_writer_init (&cw, NULL);
gum_arm64_relocator_init (&rl, NULL, &cw);

for (j = 0; j != layout->segment_pair_descriptors->len; j++)
{
Expand Down Expand Up @@ -1351,9 +1354,12 @@ gum_darwin_grafter_emit_segments (gpointer output,

g_assert (cw.pc == trampoline_addr +
G_STRUCT_OFFSET (GumGraftedHookTrampoline, on_invoke));
/* TODO: use Arm64Relocator */
gum_arm64_writer_put_instruction (&cw, overwritten_insn);
gum_arm64_writer_put_b_imm (&cw, code_addr + sizeof (overwritten_insn));
gum_arm64_relocator_reset (&rl, code_instructions, &cw);
rl.input_pc = code_addr;
gum_arm64_relocator_read_one (&rl, NULL);
gum_arm64_relocator_write_one (&rl);
if (!rl.eoi)
gum_arm64_writer_put_b_imm (&cw, code_addr + sizeof (overwritten_insn));

gum_arm64_writer_flush (&cw);
g_assert (
Expand Down Expand Up @@ -1448,6 +1454,7 @@ gum_darwin_grafter_emit_segments (gpointer output,
"LDR target too far away; please file a bug");

beach:
gum_arm64_relocator_clear (&rl);
gum_arm64_writer_clear (&cw);

return success;
Expand Down
Loading