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

linux aarch64 (ARM) #8

Merged
merged 2 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions handler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ linux: $(BUILD_DIR)/x86_64-unknown-linux.hex
mac: $(BUILD_DIR)/x86_64-apple-darwin.hex
windows: $(BUILD_DIR)/x86_64-pc-windows.hex

linux-aarch64:
mkdir -p $(BUILD_DIR)
clang -c -O3 -Werror -target aarch64-unknown-linux -o $(BUILD_DIR)/aarch64-unknown-linux.o ./handler_ptr.c -mcmodel=tiny
ld $(BUILD_DIR)/aarch64-unknown-linux.o -o $(BUILD_DIR)/a.out
objdump -s -j .text $(BUILD_DIR)/a.out | awk '/\.text/{flag=1; next} flag{print}' | awk -F' ' '{print $$2 $$3 $$4 $$5}' | tr -d ' \n' > $(BUILD_DIR)/aarch64-unknown-linux.hex

clean:
rm -f $(BUILD_DIR)/*.o
rm -f $(BUILD_DIR)/*.hex
Expand Down
15 changes: 15 additions & 0 deletions handler/handler_ptr.c
dlshriver marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
__attribute__((section(".text")))
const void *handler_address = (void *)(0xaaaaaaaaaaaaaaaa);
__attribute__((section(".text")))
const void *PyObject_Call_address = (void *)(0xbbbbbbbbbbbbbbbb);
__attribute__((section(".text")))
__attribute__((used)) static void *
handler(void *self, void *args, void *kwargs)
{
void *result = ((void *(*)(void *, void *, void *))(PyObject_Call_address))(
(void *)(handler_address),
args,
kwargs);

return result;
}
2 changes: 1 addition & 1 deletion intercepts/_handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .base import PTR_SIZE, get_addr, replace_cfunction_base

if platform.machine() not in {"x86_64", "AMD64"}: # pragma: no cover
if platform.machine() not in {"x86_64", "AMD64", "aarch64"}: # pragma: no cover
raise ImportError(f"Unfortunately {platform.machine()} is not currently supported.")
if sys.byteorder != "little": # pragma: no cover
raise ImportError(
Expand Down
8 changes: 7 additions & 1 deletion intercepts/_handlers/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import ctypes
import os
import typing
import platform

from .base import PyObject_Call_address

INSTR_TEMPLATE = bytes.fromhex("48bfaaaaaaaaaaaaaaaa48b8bbbbbbbbbbbbbbbbffe0")
if platform.machine() == "aarch64":
INSTR_TEMPLATE = bytes.fromhex(
"c30000586000005860001fd61f2003d5aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb"
)
else:
INSTR_TEMPLATE = bytes.fromhex("48bfaaaaaaaaaaaaaaaa48b8bbbbbbbbbbbbbbbbffe0")
_i = INSTR_TEMPLATE.index(b"\xbb" * 8)
INSTR_TEMPLATE = INSTR_TEMPLATE[:_i] + PyObject_Call_address + INSTR_TEMPLATE[_i + 8 :]

Expand Down