From 6eb74aad4613f223d833406fa59d67a41471d2e6 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Fri, 3 Oct 2025 14:26:34 -0400 Subject: [PATCH] initial commit --- .clangd | 9 ++++++ .envrc | 1 + .gitmodules | 3 ++ Makefile | 27 ++++++++++++++++ flake.lock | 27 ++++++++++++++++ flake.nix | 23 +++++++++++++ lib | 1 + sam_hid_kbd_rem.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ sam_hid_kbd_rem.h | 75 ++++++++++++++++++++++++++++++++++++++++++ sam_hid_kbd_rem.kpm | Bin 0 -> 5232 bytes 10 files changed, 243 insertions(+) create mode 100644 .clangd create mode 100644 .envrc create mode 100644 .gitmodules create mode 100644 Makefile create mode 100644 flake.lock create mode 100644 flake.nix create mode 160000 lib create mode 100644 sam_hid_kbd_rem.c create mode 100644 sam_hid_kbd_rem.h create mode 100644 sam_hid_kbd_rem.kpm 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 0000000000000000000000000000000000000000..e87a529e5ce0981ee8594273f46436b6e6327e22 GIT binary patch literal 5232 zcmbtYU2GIp6h6CCek>?86pO*g6u}@rn-&ToBn=A)jR6f(h$LwCcS72Dp3x zqVuyWV1Cws>#!|4ABBB)%n(eH4Z6~WcF}ng@v$v{vT{7$4qwl%h|VvJet&Jsh}~Il z8o$!DF#2tkc;`|^buIdK;T1BFe=t;?3&Z6{r^D4Xh`oT$i zINJP%c}yUFAIE2m&g*d;pTM!oGRz6NzCat|_!8xevF7^NQlEqT$@e~DyC_%6(f99CaVZYPti@{gV^JLChjGY0iMWc@ zj`a&S#@dfHlUS87?4r4oANc_0GdsAy`snn5>RjqzbzyW`)wB|>T>0nm<1U&X#@j;n z$f4GQ{HAdHFB-?#t;YYvaakLGeQv7tq4l7ee}wamW6p7a$@KsaKM%nPsu%U6h<$*1 z1?wYv26f7na+bBnoW>~!%0=}t-&yW|it8xz6Z>X+kn*AZ*I7AKrTqwaMX5GeE7`BK zrm|mY?5XxB<|=V9H&}w#A8i2LMbe(!PH%nBJaWu@-ArZ+sf?XJW4ei)TS9rZWILI5 zVHmd4v0TDS4ae*>VWHg_%gI|=bEuS0d3GUhZgR~;I_>N=H)XTsMSj^rAyX>G6ru2i zb`B#-PL|^o$SbXULc0ZbOR1FQy3ACMpSDKqlqEczEwr9T+ObD0$5hF;L)vmvj$NdT z`w!b?bHK`5j-4`(Sm%<3gp+p7?dEYSR~WI(K`z8Qwqs>6lbVe=SSl6^jt7a7H(YS~ z4~-=9=wzpckpQxoUEa0&2aX*zM|J?lb}3kIq$kn?`9#j@=bX1^lIiV^iY2qr+l#1%HT;weqbcEW*2mekm+dd$!%3~|3pk5X@i2aY zaX+8NI=_MAA+7$hjJ|zi9Zo9yI=-CwO~yqRxrgx%wiDdvZ(Nt8vajP}e?{SRdid>4 zmUs|i{!2h~d|#;c4dcW|ZIv(JCzN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