feat: initial commit
This commit is contained in:
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
*.order
|
||||||
|
*.symvers
|
||||||
|
Revird
|
||||||
|
*.ko
|
||||||
|
TaxiDriver.mod.c
|
||||||
|
*.o
|
||||||
|
*.cmd
|
||||||
35
Makefile
Normal file
35
Makefile
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Makefile for Linux Kernel Driver
|
||||||
|
|
||||||
|
# Source files and object files
|
||||||
|
SRC_DIR := src
|
||||||
|
SOURCE_FILES := $(wildcard $(SRC_DIR)/*.c)
|
||||||
|
OBJ_FILES := src/TaxiDriver.o
|
||||||
|
obj-m := $(OBJ_FILES)
|
||||||
|
# KERNELDIR ?= /home/maxime/Downloads/linux-6.5.7-arch1/
|
||||||
|
KERNELDIR ?= /lib/modules/6.5.8-arch1-1/build/
|
||||||
|
|
||||||
|
# Kernel module name
|
||||||
|
MODULE_NAME := TaxiDriver
|
||||||
|
|
||||||
|
all: default
|
||||||
|
|
||||||
|
default:
|
||||||
|
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
|
||||||
|
mv src/TaxiDriver.ko .
|
||||||
|
$(MAKE) clean
|
||||||
|
cd src/client && $(MAKE)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
find src/ -maxdepth 1 -type f ! -name "*.h" ! -name "*.c" -exec rm {} \;
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
find . -maxdepth 1 -type f ! -name "Makefile" -exec rm {} \;
|
||||||
|
|
||||||
|
load:
|
||||||
|
sudo insmod $(MODULE_NAME).ko
|
||||||
|
sudo mknod /dev/TaxiDriver c 506 0
|
||||||
|
|
||||||
|
unload:
|
||||||
|
sudo rmmod $(MODULE_NAME)
|
||||||
|
|
||||||
|
.PHONY: all clean fclean load unload
|
||||||
117
src/TaxiDriver.c
Normal file
117
src/TaxiDriver.c
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
#include <linux/init.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/fs.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/sched.h>
|
||||||
|
#include <linux/uaccess.h>
|
||||||
|
|
||||||
|
#define DRIVER_NAME "TaxiDriver"
|
||||||
|
#define DRIVER
|
||||||
|
#include "client/communication_struct.h"
|
||||||
|
|
||||||
|
static int major_number;
|
||||||
|
static struct task_struct *task;
|
||||||
|
|
||||||
|
static int device_open(struct inode *inode, struct file *file)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int device_release(struct inode *inode, struct file *file)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int init_process_by_pid(int target_pid) {
|
||||||
|
printk(KERN_INFO "TaxiDriver: Accessing process with PID: %d\n", target_pid);
|
||||||
|
|
||||||
|
struct pid *pid_struct;
|
||||||
|
pid_struct = find_get_pid(target_pid);
|
||||||
|
if (pid_struct != NULL) {
|
||||||
|
task = get_pid_task(pid_struct, PIDTYPE_PID);
|
||||||
|
if (task != NULL) {
|
||||||
|
const char *process_name = task->comm;
|
||||||
|
printk(KERN_INFO "TaxiDriver: Process with PID %d has name: %s\n", target_pid, process_name);
|
||||||
|
// Access and manipulate the process here
|
||||||
|
put_task_struct(task);
|
||||||
|
} else {
|
||||||
|
printk(KERN_INFO "TaxiDriver: Process with PID %d not found\n", target_pid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
put_pid(pid_struct);
|
||||||
|
} else {
|
||||||
|
printk(KERN_INFO "TaxiDriver: Process with PID %d not found\n", target_pid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1; // A successful module initialization
|
||||||
|
}
|
||||||
|
|
||||||
|
static long device_ioctl(struct file *file, unsigned int ioctl_num, unsigned long arg)
|
||||||
|
{
|
||||||
|
struct s_WPM wpm_args;
|
||||||
|
struct s_RPM rpm_args;
|
||||||
|
int pid;
|
||||||
|
int return_value = 0;
|
||||||
|
|
||||||
|
switch (ioctl_num) {
|
||||||
|
case IOCTL_OPENPROC:
|
||||||
|
if (copy_from_user(&pid, (int *)arg, sizeof(int)))
|
||||||
|
return -EFAULT;
|
||||||
|
return_value = init_process_by_pid(pid);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IOCTL_RPM:
|
||||||
|
if (copy_from_user(&rpm_args, (int *)arg, sizeof(t_RPM)))
|
||||||
|
return -EFAULT;
|
||||||
|
printk(KERN_ALERT "TaxiDriver: RPM --> addr : %ld, size : %ld\n", rpm_args.addr, rpm_args.size);
|
||||||
|
return_value = 1337;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IOCTL_WPM:
|
||||||
|
if (copy_from_user(&wpm_args, (int *)arg, sizeof(t_WPM)))
|
||||||
|
return -EFAULT;
|
||||||
|
printk(KERN_ALERT "TaxiDriver: WPM --> addr : %ld, size : %ld, value : %ld\n",
|
||||||
|
wpm_args.addr, wpm_args.size, wpm_args.value);
|
||||||
|
return_value = 1337;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return -ENOTTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct file_operations fops = {
|
||||||
|
.unlocked_ioctl = device_ioctl,
|
||||||
|
.open = device_open,
|
||||||
|
.release = device_release,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int __init driver_init(void)
|
||||||
|
{
|
||||||
|
printk(KERN_ALERT "TaxiDriver: Loaded\n");
|
||||||
|
|
||||||
|
// Dynamically allocate the major number
|
||||||
|
major_number = register_chrdev(0, DRIVER_NAME, &fops);
|
||||||
|
|
||||||
|
if (major_number < 0) {
|
||||||
|
printk(KERN_ALERT "TaxiDriver: Failed to register the driver.\n");
|
||||||
|
return major_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
printk(KERN_ALERT "TaxiDriver: Registered %s with major number %d\n", DRIVER_NAME, major_number);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __exit driver_exit(void)
|
||||||
|
{
|
||||||
|
unregister_chrdev(major_number, DRIVER_NAME);
|
||||||
|
printk(KERN_ALERT "TaxiDriver: Unloaded\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
module_init(driver_init);
|
||||||
|
module_exit(driver_exit);
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
21
src/client/Makefile
Normal file
21
src/client/Makefile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
SRC = main.c \
|
||||||
|
memory.c
|
||||||
|
OBJ = $(SRC:.c=.o)
|
||||||
|
NAME = Revird
|
||||||
|
CFLAGS = -Wall -Wextra -Wpedantic
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
gcc $(SRC) $(CFLAGS) -o $(NAME)
|
||||||
|
mv $(NAME) ../../.
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
rm -f $(NAME)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY : all $(NAME) clean fclean re
|
||||||
23
src/client/communication_struct.h
Normal file
23
src/client/communication_struct.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef DRIVER
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define IOCTL_OPENPROC _IOW('k', 1, int)
|
||||||
|
#define IOCTL_RPM _IOW('k', 1, t_RPM)
|
||||||
|
#define IOCTL_WPM _IOW('k', 2, t_WPM)
|
||||||
|
|
||||||
|
typedef struct s_RPM
|
||||||
|
{
|
||||||
|
uintptr_t addr;
|
||||||
|
ssize_t size;
|
||||||
|
} t_RPM;
|
||||||
|
|
||||||
|
typedef struct s_WPM
|
||||||
|
{
|
||||||
|
uintptr_t addr;
|
||||||
|
ssize_t size;
|
||||||
|
uintptr_t value;
|
||||||
|
} t_WPM;
|
||||||
25
src/client/main.c
Normal file
25
src/client/main.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
if (!open_device())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int pid = 25801;
|
||||||
|
if (!open_process(pid))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
struct s_RPM args;
|
||||||
|
args.addr = 0x420;
|
||||||
|
args.size = 4;
|
||||||
|
int val = (int)RPM(args);
|
||||||
|
printf("Value from RPM: %d\n", val);
|
||||||
|
|
||||||
|
struct s_WPM args_wpm;
|
||||||
|
args_wpm.addr = 0x420;
|
||||||
|
args_wpm.size = 4;
|
||||||
|
args_wpm.value = (uintptr_t)667;
|
||||||
|
WPM(args_wpm);
|
||||||
|
|
||||||
|
close_device();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
62
src/client/memory.c
Normal file
62
src/client/memory.c
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#include "memory.h"
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define DEVICE_FILE "/dev/TaxiDriver"
|
||||||
|
|
||||||
|
static int file_desc;
|
||||||
|
int open_device(void)
|
||||||
|
{
|
||||||
|
file_desc = open(DEVICE_FILE, O_RDWR);
|
||||||
|
if (file_desc < 0) {
|
||||||
|
perror("Revird: Failed to open the device.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close_device(void)
|
||||||
|
{
|
||||||
|
close(file_desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *RPM(t_RPM args)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ioctl(file_desc, IOCTL_RPM, &args);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("Revird: RPM failed.");
|
||||||
|
close(file_desc);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (void *)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WPM(t_WPM args)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ioctl(file_desc, IOCTL_WPM, &args);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("Revird: WPM failed.");
|
||||||
|
close(file_desc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int open_process(int pid)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ioctl(file_desc, IOCTL_OPENPROC, &pid);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("Revird: openprocess failed.");
|
||||||
|
close(file_desc);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
9
src/client/memory.h
Normal file
9
src/client/memory.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "communication_struct.h"
|
||||||
|
|
||||||
|
int open_device(void);
|
||||||
|
void close_device(void);
|
||||||
|
void *RPM(t_RPM args);
|
||||||
|
void WPM(t_WPM args);
|
||||||
|
int open_process(int pid);
|
||||||
Reference in New Issue
Block a user