commit 6eb74aad4613f223d833406fa59d67a41471d2e6 Author: Evan Reichard Date: Fri Oct 3 14:26:34 2025 -0400 initial commit diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..ae4f146 --- /dev/null +++ b/.clangd @@ -0,0 +1,9 @@ +CompileFlags: + Add: + - -I./lib/kernel/. + - -I./lib/kernel/include + - -I./lib/kernel/patch/include + - -I./lib/kernel/linux/include + - -I./lib/kernel/linux/arch/arm64/include + - -I./lib/kernel/linux/tools/arch/arm64/include + diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6695d62 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "KernelPatch"] + path = lib + url = git@github.com:bmax121/KernelPatch.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b939472 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +ifndef TARGET_COMPILE + TARGET_COMPILE = aarch64-none-elf- +endif + +ifndef KP_DIR + KP_DIR = ./lib +endif + +CC = $(TARGET_COMPILE)gcc +LD = $(TARGET_COMPILE)ld + +INCLUDE_DIRS := . include patch/include linux/include linux/arch/arm64/include linux/tools/arch/arm64/include + +INCLUDE_FLAGS := $(foreach dir,$(INCLUDE_DIRS),-I$(KP_DIR)/kernel/$(dir)) + +objs := sam_hid_kbd_rem.c + +all: sam_hid_kbd_rem.kpm + +sam_hid_kbd_rem.kpm: ${objs} + ${CC} $(CFLAGS) $(INCLUDE_FLAGS) -O2 $^ -r -o $@ + + +.PHONY: clean +clean: + rm -rf *.kpm + find . -name "*.o" | xargs rm -f diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0ccacef --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1759281824, + "narHash": "sha256-FIBE1qXv9TKvSNwst6FumyHwCRH3BlWDpfsnqRDCll0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b5be50345d4113d04ba58c444348849f5585b4a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..911419d --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "ARM cross-compilation environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + }; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.${system}.default = pkgs.mkShell { + buildInputs = with pkgs; [ + gnumake + android-tools + pkgsCross.aarch64-embedded.buildPackages.gcc + pkgsCross.aarch64-embedded.buildPackages.binutils + ]; + }; + }; +} diff --git a/lib b/lib new file mode 160000 index 0000000..0d80e99 --- /dev/null +++ b/lib @@ -0,0 +1 @@ +Subproject commit 0d80e994f26b7c25fc03a45753ed2c93be430554 diff --git a/sam_hid_kbd_rem.c b/sam_hid_kbd_rem.c new file mode 100644 index 0000000..267d038 --- /dev/null +++ b/sam_hid_kbd_rem.c @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2025 Evan Reichard. All Rights Reserved. + */ +#include "sam_hid_kbd_rem.h" +#include +#include +#include +#include +#include +#include + +KPM_NAME("samsung-kbd-remove"); +KPM_VERSION("1.0.0"); +KPM_LICENSE("GPL v2"); +KPM_AUTHOR("Evan Reichard"); +KPM_DESCRIPTION( + "Fix Generic Keyboards - Remove Samsung Wireless Keyboard Support"); + +// Ignored Devices +static const struct hid_device_id ignore_list[] = { + {HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, + USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD)}, + {}}; + +// Function Pointers +static unsigned long (*hid_lookup_quirk)(const struct hid_device *hdev); +static const struct hid_device_id *(*hid_match_device)(struct hid_device *hdev, + struct hid_driver *hdrv); +static const struct hid_device_id *(*hid_match_id)( + const struct hid_device *hdev, const struct hid_device_id *id); + +static void before_hid_lookup_quirk(hook_fargs1_t *args, void *udata) { + const struct hid_device *hdev = (const struct hid_device *)args->arg0; + if (hid_match_id(hdev, ignore_list)) { + logkd("blocking samsung quirk\n"); + args->ret = 0; + args->skip_origin = true; + } +} + +static void before_hid_match_device(hook_fargs2_t *args, void *udata) { + struct hid_device *hdev = (struct hid_device *)args->arg0; + struct hid_driver *hdrv = (struct hid_driver *)args->arg1; + + if (strcmp(hdrv->name, "samsung") == 0 && hid_match_id(hdev, ignore_list)) { + logkd("blocking samsung driver match\n"); + args->ret = (unsigned long)NULL; + args->skip_origin = true; + } +} + +static long inline_hook_hid_gets_squirk_init(const char *args, + const char *event, + void *__user reserved) { + // Hook Quirk Lookup + lookup_name(hid_match_id); + lookup_name(hid_lookup_quirk); + hook_func(hid_lookup_quirk, 1, before_hid_lookup_quirk, 0, 0); + + // Hook Device Match + lookup_name(hid_match_device); + hook_func(hid_match_device, 2, before_hid_match_device, 0, 0); + + return 0; +} + +static long inline_hook_hid_gets_squirk_exit(void *__user reserved) { + unhook_func(hid_match_device); + unhook_func(hid_lookup_quirk); + unhook_func(hid_match_id); + + return 0; +} + +KPM_INIT(inline_hook_hid_gets_squirk_init); +KPM_EXIT(inline_hook_hid_gets_squirk_exit); diff --git a/sam_hid_kbd_rem.h b/sam_hid_kbd_rem.h new file mode 100644 index 0000000..0fbdce3 --- /dev/null +++ b/sam_hid_kbd_rem.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2025 Evan Reichard. All Rights Reserved. + */ +#ifndef SAM_HID_KBD_REM_H +#define SAM_HID_KBD_REM_H + +#include +#include +#include +#include + +#define BUS_BLUETOOTH 0x05 +#define USB_VENDOR_ID_SAMSUNG_ELECTRONICS 0x04e8 +#define USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD 0x7021 + +struct device {}; + +struct device_driver { + const char *name; +}; + +struct hid_driver { + char *name; +}; + +struct hid_device_id { + __u16 bus; + __u16 group; + __u32 vendor; + __u32 product; + unsigned long driver_data; +}; + +struct hid_device { + __u16 bus; + __u16 group; + __u32 vendor; + __u32 product; + struct device dev; +}; + +#define HID_BLUETOOTH_DEVICE(ven, prod) \ + .bus = BUS_BLUETOOTH, .vendor = (ven), .product = (prod) + +#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev); + +#define lookup_name(func) \ + func = 0; \ + func = (typeof(func))kallsyms_lookup_name(#func); \ + pr_info("kernel function %s addr: %llx\n", #func, func); \ + if (!func) { \ + return -21; \ + } + +#define hook_func(func, argv, before, after, udata) \ + if (!func) { \ + return -22; \ + } \ + hook_err_t hook_err_##func = hook_wrap(func, argv, before, after, udata); \ + if (hook_err_##func) { \ + func = 0; \ + pr_err("hook %s error: %d\n", #func, hook_err_##func); \ + return -23; \ + } else { \ + pr_info("hook %s success\n", #func); \ + } + +#define unhook_func(func) \ + if (func && !is_bad_address(func)) { \ + unhook(func); \ + func = 0; \ + } + +#endif diff --git a/sam_hid_kbd_rem.kpm b/sam_hid_kbd_rem.kpm new file mode 100644 index 0000000..e87a529 Binary files /dev/null and b/sam_hid_kbd_rem.kpm differ