-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
230 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
ifndef TARGET_COMPILE | ||
$(error TARGET_COMPILE not set) | ||
endif | ||
QBC_VERSION := 1.0.2 | ||
|
||
ifndef KP_DIR | ||
KP_DIR = ../KernelPatch | ||
endif | ||
|
||
OS_NAME = $(shell uname | tr A-Z a-z) | ||
MACHINE = $(shell uname -m) | ||
NDK_BIN_DIR := toolchains/llvm/prebuilt/$(OS_NAME)-$(MACHINE)/bin | ||
ifdef ANDROID_NDK_LATEST_HOME | ||
NDK_PATH ?= $(ANDROID_NDK_LATEST_HOME)/$(NDK_BIN_DIR) | ||
else ifdef ANDROID_NDK | ||
NDK_PATH ?= $(ANDROID_NDK)/$(NDK_BIN_DIR) | ||
endif | ||
|
||
ifdef TARGET_COMPILE | ||
CC := $(TARGET_COMPILE)gcc | ||
LD := $(TARGET_COMPILE)ld | ||
else ifdef NDK_PATH | ||
CC := $(NDK_PATH)/aarch64-linux-android31-clang | ||
LD := $(NDK_PATH)/ld.lld | ||
endif | ||
|
||
CC = $(TARGET_COMPILE)gcc | ||
LD = $(TARGET_COMPILE)ld | ||
CFLAGS = -Wall -O2 -fno-PIC -fno-asynchronous-unwind-tables -fno-stack-protector -fno-common -DQBC_VERSION=\"$(QBC_VERSION)$(QBC_VER)\" | ||
|
||
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 := qti_battery_charger.o | ||
|
||
all: qti_battery_charger.kpm | ||
all: qti_battery_charger_$(QBC_VERSION).kpm | ||
|
||
debug: CFLAGS += -DDEBUG | ||
debug: QBC_VER := _d | ||
debug: qti_battery_charger_$(QBC_VERSION)_debug.kpm | ||
|
||
qti_battery_charger_$(QBC_VERSION).kpm: ${objs} | ||
${CC} -r -o $@ $^ | ||
|
||
qti_battery_charger.kpm: ${objs} | ||
qti_battery_charger_$(QBC_VERSION)_debug.kpm: ${objs} | ||
${CC} -r -o $@ $^ | ||
|
||
%.o: %.c | ||
${CC} $(CFLAGS) $(INCLUDE_FLAGS) -T../demo.lds -c -O2 -o $@ $< | ||
${CC} $(CFLAGS) $(INCLUDE_FLAGS) -c -o $@ $< | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf *.kpm | ||
find . -name "*.o" | xargs rm -f | ||
find . -name "*.o" | xargs rm -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright (C) 2024 bmax121. All Rights Reserved. | ||
* Copyright (C) 2024 lzghzr. All Rights Reserved. | ||
*/ | ||
#ifndef __QBC_UTILS_H | ||
#define __QBC_UTILS_H | ||
|
||
#include <hook.h> | ||
#include <ksyms.h> | ||
#include <linux/cred.h> | ||
#include <linux/sched.h> | ||
#include <uapi/asm-generic/errno.h> | ||
|
||
#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 /* __QBC_UTILS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
ifndef TARGET_COMPILE | ||
$(error TARGET_COMPILE not set) | ||
endif | ||
XIIBA_VERSION := 1.1.2 | ||
|
||
ifndef KP_DIR | ||
KP_DIR = ../KernelPatch | ||
endif | ||
|
||
OS_NAME = $(shell uname | tr A-Z a-z) | ||
MACHINE = $(shell uname -m) | ||
NDK_BIN_DIR := toolchains/llvm/prebuilt/$(OS_NAME)-$(MACHINE)/bin | ||
ifdef ANDROID_NDK_LATEST_HOME | ||
NDK_PATH ?= $(ANDROID_NDK_LATEST_HOME)/$(NDK_BIN_DIR) | ||
else ifdef ANDROID_NDK | ||
NDK_PATH ?= $(ANDROID_NDK)/$(NDK_BIN_DIR) | ||
endif | ||
|
||
ifdef TARGET_COMPILE | ||
CC := $(TARGET_COMPILE)gcc | ||
LD := $(TARGET_COMPILE)ld | ||
else ifdef NDK_PATH | ||
CC := $(NDK_PATH)/aarch64-linux-android31-clang | ||
LD := $(NDK_PATH)/ld.lld | ||
endif | ||
|
||
CC = $(TARGET_COMPILE)gcc | ||
LD = $(TARGET_COMPILE)ld | ||
CFLAGS = -Wall -O2 -fno-PIC -fno-asynchronous-unwind-tables -fno-stack-protector -fno-common -DXIIBA_VERSION=\"$(XIIBA_VERSION)$(XIIBA_VER)\" | ||
|
||
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 := xperia_ii_battery_age.o | ||
|
||
all: xperia_ii_battery_age.kpm | ||
all: xperia_ii_battery_age_$(XIIBA_VERSION).kpm | ||
|
||
debug: CFLAGS += -DDEBUG | ||
debug: XIIBA_VER := _d | ||
debug: xperia_ii_battery_age_$(XIIBA_VERSION)_debug.kpm | ||
|
||
xperia_ii_battery_age_$(XIIBA_VERSION).kpm: ${objs} | ||
${CC} -r -o $@ $^ | ||
|
||
xperia_ii_battery_age.kpm: ${objs} | ||
xperia_ii_battery_age_$(XIIBA_VERSION)_debug.kpm: ${objs} | ||
${CC} -r -o $@ $^ | ||
|
||
%.o: %.c | ||
${CC} $(CFLAGS) $(INCLUDE_FLAGS) -T../demo.lds -c -O2 -o $@ $< | ||
${CC} $(CFLAGS) $(INCLUDE_FLAGS) -c -o $@ $< | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf *.kpm | ||
find . -name "*.o" | xargs rm -f | ||
find . -name "*.o" | xargs rm -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright (C) 2024 bmax121. All Rights Reserved. | ||
* Copyright (C) 2024 lzghzr. All Rights Reserved. | ||
*/ | ||
#ifndef __XIIBA_UTILS_H | ||
#define __XIIBA_UTILS_H | ||
|
||
#include <hook.h> | ||
#include <ksyms.h> | ||
#include <linux/cred.h> | ||
#include <linux/sched.h> | ||
#include <uapi/asm-generic/errno.h> | ||
|
||
#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 /* __XIIBA_UTILS_H */ |
Oops, something went wrong.