Advertisement
imk0tter
Oct 13th, 2023
65
0
Never
This is comment for paste Kernel Port Code by Imk0tter
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. #define OPEN_PORT_FUNCTION print_open
  4. #define CLOSE_PORT_FUNCTION print_close
  5. #define CONNECT_PORT_FUNCTION print_connect
  6.  
  7. void handle_open_port(unsigned int x, void *(*open_port)(unsigned int port));
  8. void handle_close_port(unsigned int x, void *(*close_port)(unsigned int port));
  9. void handle_connect_to_port(unsigned int x, void *(*connect_to_port)(unsigned int port));
  10.  
  11. void print_open(unsigned int x);
  12. void print_close(unsigned int x);
  13. void print_connect(unsigned int x);
  14.  
  15. #define PREVIOUS_FRAME(x, y) *(unsigned int *)(x + y)
  16.  
  17. long gap_between_x = 0;
  18.  
  19. void kernel_recursion(unsigned int x) {
  20.   long current_offset = gap_between_x - (long)(char *)&x;
  21.   gap_between_x = (long)(char *)&x;
  22.  
  23.   unsigned int previous_x = PREVIOUS_FRAME((char *)&x, current_offset);
  24.  
  25.   if (x < previous_x) {
  26.     handle_open_port(x, (void*(*)(unsigned int))OPEN_PORT_FUNCTION);
  27.     ++x;
  28.     kernel_recursion(previous_x);
  29.     --x;
  30.     handle_close_port(x, (void*(*)(unsigned int))CLOSE_PORT_FUNCTION);
  31.   } else if (previous_x < x) {
  32.     handle_open_port(previous_x, (void*(*)(unsigned int))OPEN_PORT_FUNCTION);
  33.     kernel_recursion(previous_x + 1);
  34.     --x;
  35.     handle_close_port(previous_x, (void*(*)(unsigned int))CLOSE_PORT_FUNCTION);
  36.   } else {
  37.     handle_open_port(previous_x, (void*(*)(unsigned int))OPEN_PORT_FUNCTION);
  38.     handle_close_port(previous_x, (void*(*)(unsigned int))CLOSE_PORT_FUNCTION);
  39.   }
  40. }
  41. void kernel(unsigned int x) {
  42.   gap_between_x = (long)&x;
  43.   kernel_recursion(0);
  44. }
  45.  
  46. int main() { kernel(22000); }
  47.  
  48. void handle_open_port(unsigned int x, void *(*open_port)(unsigned int port)) {
  49.   open_port(x);
  50. }
  51. void handle_close_port(unsigned int x, void *(*close_port)(unsigned int port)) {
  52.   handle_connect_to_port(x, (void*(*)(unsigned int))CONNECT_PORT_FUNCTION);
  53.   close_port(x);
  54. }
  55. void handle_connect_to_port(unsigned int x,
  56.                             void *(*connect_to_port)(unsigned int port)) {
  57.   connect_to_port(x);
  58. }
  59.  
  60. void print_open(unsigned int x) { printf("Opened port %u\n", x); }
  61. void print_close(unsigned int x) { printf("Closed port %u\n", x); }
  62. void print_connect(unsigned int x) { printf("Connected port %u\n", x); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement