mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 19:21:35 +01:00
migrate all
This commit is contained in:
26
userland/linux/ctrl_alt_del.c
Normal file
26
userland/linux/ctrl_alt_del.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#ctrl-alt-del */
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void signal_handler(int sig) {
|
||||
write(STDOUT_FILENO, "cad\n", 4);
|
||||
signal(sig, signal_handler);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int i = 0;
|
||||
/* Disable the forced reboot, enable sending SIGINT to init. */
|
||||
reboot(RB_DISABLE_CAD);
|
||||
signal(SIGINT, signal_handler);
|
||||
while (1) {
|
||||
sleep(1);
|
||||
printf("%d\n", i);
|
||||
i++;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
9
userland/linux/poweroff.c
Normal file
9
userland/linux/poweroff.c
Normal file
@@ -0,0 +1,9 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#poweroff-out */
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <sys/reboot.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void) {
|
||||
reboot(RB_POWER_OFF);
|
||||
}
|
||||
41
userland/linux/rand_check.c
Normal file
41
userland/linux/rand_check.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#rand_check-out */
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int bss = 0;
|
||||
int data = 1;
|
||||
|
||||
int main(__attribute__((unused)) int argc, char **argv) {
|
||||
int i, *ip;
|
||||
uint64_t uint64;
|
||||
FILE *fp;
|
||||
|
||||
/* Loaded addresses. */
|
||||
printf("&i = %p\n", (void *)&i);
|
||||
printf("&argv[0] = %p\n", (void *)&argv[0]);
|
||||
printf("&main = %p\n", (void *)(intptr_t)main);
|
||||
printf("&bss = %p\n", (void *)&bss);
|
||||
printf("&data = %p\n", (void *)&data);
|
||||
|
||||
/* Misc syscalls. */
|
||||
printf("time(NULL) = %ju\n", (uintmax_t)time(NULL));
|
||||
printf("pid = %ju\n", (uintmax_t)getpid());
|
||||
|
||||
/* malloc */
|
||||
ip = malloc(sizeof(*ip));
|
||||
printf("&malloc = %p\n", (void *)ip);
|
||||
free(ip);
|
||||
|
||||
/* /dev/urandom */
|
||||
fp = fopen("/dev/urandom", "rb");
|
||||
fread(&uint64, sizeof(uint64), 1, fp);
|
||||
printf("/dev/urandom = %" PRIx64 "\n", uint64);
|
||||
fclose(fp);
|
||||
}
|
||||
14
userland/linux/time_boot.c
Normal file
14
userland/linux/time_boot.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#time_boot-out */
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void) {
|
||||
FILE *fp;
|
||||
fp = fopen("/dev/kmsg", "w");
|
||||
fputs(__FILE__ "\n", fp);
|
||||
fclose(fp);
|
||||
while (1)
|
||||
sleep(0xFFFFFFFF);
|
||||
}
|
||||
Reference in New Issue
Block a user