initial commit
This commit is contained in:
commit
6eb74aad46
9
.clangd
Normal file
9
.clangd
Normal file
@ -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
|
||||||
|
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "KernelPatch"]
|
||||||
|
path = lib
|
||||||
|
url = git@github.com:bmax121/KernelPatch.git
|
27
Makefile
Normal file
27
Makefile
Normal file
@ -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
|
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@ -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
|
||||||
|
}
|
23
flake.nix
Normal file
23
flake.nix
Normal file
@ -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
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
1
lib
Submodule
1
lib
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 0d80e994f26b7c25fc03a45753ed2c93be430554
|
77
sam_hid_kbd_rem.c
Normal file
77
sam_hid_kbd_rem.c
Normal file
@ -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 <compiler.h>
|
||||||
|
#include <hook.h>
|
||||||
|
#include <kpmodule.h>
|
||||||
|
#include <linux/container_of.h>
|
||||||
|
#include <linux/string.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
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);
|
75
sam_hid_kbd_rem.h
Normal file
75
sam_hid_kbd_rem.h
Normal file
@ -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 <hook.h>
|
||||||
|
#include <ksyms.h>
|
||||||
|
#include <ktypes.h>
|
||||||
|
#include <linux/printk.h>
|
||||||
|
|
||||||
|
#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
|
BIN
sam_hid_kbd_rem.kpm
Normal file
BIN
sam_hid_kbd_rem.kpm
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user