mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 19:51:35 +01:00
migrate all
This commit is contained in:
14
userland/arch/x86_64/c/rdtsc.c
Normal file
14
userland/arch/x86_64/c/rdtsc.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#rdtsc */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <x86intrin.h>
|
||||
|
||||
int main(void) {
|
||||
uintmax_t val;
|
||||
val = __rdtsc();
|
||||
printf("%ju\n", val);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
12
userland/arch/x86_64/c/ring0.c
Normal file
12
userland/arch/x86_64/c/ring0.c
Normal file
@@ -0,0 +1,12 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#ring0 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <include/ring0.h>
|
||||
|
||||
int main(void) {
|
||||
LkmcRing0Regs ring0_regs;
|
||||
lkmc_ring0_get_control_regs(&ring0_regs);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
3
userland/libs/README.adoc
Normal file
3
userland/libs/README.adoc
Normal file
@@ -0,0 +1,3 @@
|
||||
Examples in this directory rely on non-libc libraries.
|
||||
|
||||
Each example is prefixed by an identifier of the library it depends on.
|
||||
1
userland/libs/build
Symbolic link
1
userland/libs/build
Symbolic link
@@ -0,0 +1 @@
|
||||
../build
|
||||
@@ -7,8 +7,8 @@
|
||||
int main(void) {
|
||||
FILE *fp;
|
||||
fp = fopen("/dev/kmsg", "w");
|
||||
fputs(__FILE__ "\n", fp);
|
||||
fclose(fp);
|
||||
while (1)
|
||||
sleep(0xFFFFFFFF);
|
||||
fputs(__FILE__ "\n", fp);
|
||||
fclose(fp);
|
||||
while (1)
|
||||
sleep(0xFFFFFFFF);
|
||||
}
|
||||
@@ -13,49 +13,49 @@
|
||||
#define finit_module(fd, param_values, flags) syscall(__NR_finit_module, fd, param_values, flags)
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *params;
|
||||
int fd, use_finit;
|
||||
size_t image_size;
|
||||
struct stat st;
|
||||
void *image;
|
||||
const char *params;
|
||||
int fd, use_finit;
|
||||
size_t image_size;
|
||||
struct stat st;
|
||||
void *image;
|
||||
|
||||
/* CLI handling. */
|
||||
if (argc < 2) {
|
||||
puts("Usage ./prog mymodule.ko [args="" [use_finit=0]");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (argc < 3) {
|
||||
params = "";
|
||||
} else {
|
||||
params = argv[2];
|
||||
}
|
||||
if (argc < 4) {
|
||||
use_finit = 0;
|
||||
} else {
|
||||
use_finit = (argv[3][0] != '0');
|
||||
}
|
||||
/* CLI handling. */
|
||||
if (argc < 2) {
|
||||
puts("Usage ./prog mymodule.ko [args="" [use_finit=0]");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (argc < 3) {
|
||||
params = "";
|
||||
} else {
|
||||
params = argv[2];
|
||||
}
|
||||
if (argc < 4) {
|
||||
use_finit = 0;
|
||||
} else {
|
||||
use_finit = (argv[3][0] != '0');
|
||||
}
|
||||
|
||||
/* Action. */
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (use_finit) {
|
||||
puts("finit");
|
||||
if (finit_module(fd, params, 0) != 0) {
|
||||
perror("finit_module");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
close(fd);
|
||||
} else {
|
||||
puts("init");
|
||||
fstat(fd, &st);
|
||||
image_size = st.st_size;
|
||||
image = malloc(image_size);
|
||||
read(fd, image, image_size);
|
||||
close(fd);
|
||||
if (init_module(image, image_size, params) != 0) {
|
||||
perror("init_module");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
free(image);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
/* Action. */
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (use_finit) {
|
||||
puts("finit");
|
||||
if (finit_module(fd, params, 0) != 0) {
|
||||
perror("finit_module");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
close(fd);
|
||||
} else {
|
||||
puts("init");
|
||||
fstat(fd, &st);
|
||||
image_size = st.st_size;
|
||||
image = malloc(image_size);
|
||||
read(fd, image, image_size);
|
||||
close(fd);
|
||||
if (init_module(image, image_size, params) != 0) {
|
||||
perror("init_module");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
free(image);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
#define delete_module(name, flags) syscall(__NR_delete_module, name, flags)
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 2) {
|
||||
puts("Usage ./prog mymodule");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (delete_module(argv[1], O_NONBLOCK) != 0) {
|
||||
perror("delete_module");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
if (argc != 2) {
|
||||
puts("Usage ./prog mymodule");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (delete_module(argv[1], O_NONBLOCK) != 0) {
|
||||
perror("delete_module");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void) {
|
||||
puts(__FILE__);
|
||||
while (1)
|
||||
sleep(0xFFFFFFFF);
|
||||
puts(__FILE__);
|
||||
while (1)
|
||||
sleep(0xFFFFFFFF);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#rdtsc */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
uintmax_t val;
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
val = __rdtsc();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
printf("%ju\n", val);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#ring0 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../include/ring0.h"
|
||||
|
||||
int main(void) {
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
Ring0Regs ring0_regs;
|
||||
ring0_get_control_regs(&ring0_regs);
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user