Advertisement
imk0tter
Oct 13th, 2023
54
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. template<typename T>
  4. void handle_open_port(unsigned int x, T (*open_port)(unsigned int port));
  5. template<typename T>
  6. void handle_close_port(unsigned int x, T (*close_port)(unsigned int port));
  7. template<typename T>
  8. void handle_connect_to_port(unsigned int x,
  9.                             T (*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, print_open);
  27.     ++x;
  28.     kernel_recursion(previous_x);
  29.     --x;
  30.     handle_close_port(x, print_close);
  31.   } else if (previous_x < x) {
  32.     handle_open_port(previous_x, print_open);
  33.     kernel_recursion(previous_x + 1);
  34.     --x;
  35.     handle_close_port(previous_x, print_close);
  36.   } else {
  37.     handle_open_port(previous_x, print_open);
  38.     handle_close_port(previous_x, print_close);
  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. template<typename T>
  49. void handle_open_port(unsigned int x, T (*open_port)(unsigned int port)) {
  50.   open_port(x);
  51. }
  52.  
  53. template<typename T>
  54. void handle_close_port(unsigned int x, T (*close_port)(unsigned int port)) {
  55.   handle_connect_to_port(x, print_connect);
  56.   close_port(x);
  57. }
  58.  
  59. template<typename T>
  60. void handle_connect_to_port(unsigned int x,
  61.                             T (*connect_to_port)(unsigned int port)) {
  62.   connect_to_port(x);
  63. }
  64.  
  65. void print_open(unsigned int x) { printf("Opened port %u\n", x); }
  66. void print_close(unsigned int x) { printf("Closed port %u\n", x); }
  67. void print_connect(unsigned int x) { printf("Connected port %u\n", x); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement