migrate all

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-05 00:00:00 +00:00
parent ecef42be81
commit 0ef494b681
27 changed files with 280 additions and 230 deletions

View 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;
}

View 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;
}

View 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
View File

@@ -0,0 +1 @@
../build

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -5,7 +5,7 @@
#include <unistd.h>
int main(void) {
puts(__FILE__);
while (1)
sleep(0xFFFFFFFF);
puts(__FILE__);
while (1)
sleep(0xFFFFFFFF);
}

View File

@@ -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;
}

View File

@@ -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;
}