Skip to content

Instantly share code, notes, and snippets.

@BrotherJing
BrotherJing / testwrite.c
Created June 1, 2016 14:37
test write to process memory space
#include<stdio.h>
#include<string.h>
int main(){
FILE *fp;
int v=0;
int val;
char s[20],ch;
fp = fopen("/proc/mtest","w+");
@BrotherJing
BrotherJing / mtest.c
Created June 1, 2016 14:22
a kernel module for process memory management
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/string.h>
#include<linux/vmalloc.h>
#include<linux/mm.h>
#include<linux/init.h>
#include<linux/proc_fs.h>
#include<linux/sched.h>
#include<linux/uaccess.h>
#include<linux/fs.h>
@BrotherJing
BrotherJing / romfs.c
Last active May 15, 2017 05:10
romfs: hide file, encrypt file, add execution bit...
/*
#
# Makefile for the linux RomFS filesystem routines.
#
obj-m := romfs.o
romfs-y := storage.o super.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
@BrotherJing
BrotherJing / taskstruct.c
Last active January 30, 2021 11:35
add a param to task_struct to record process schedule
// include/linux/sched.h
struct task_struct {
int ctx;
volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
void *stack;
atomic_t usage;
unsigned int flags; /* per process flags, defined below */
unsigned int ptrace;
//...
@BrotherJing
BrotherJing / helloproc.c
Created June 1, 2016 10:43
write a kernel module, which create a read/write proc file
#include<linux/module.h>
#include<linux/init.h>
#include<linux/proc_fs.h>
#include<linux/sched.h>
#include<linux/uaccess.h>
#include<linux/fs.h>
#include<linux/seq_file.h>
#include<linux/slab.h>
static char *str = NULL;