Advertisement
imk0tter

Kernel Port Code by Imk0tter

Oct 13th, 2023 (edited)
1,056
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void handle_open_port(unsigned int x);
  4. void handle_close_port(unsigned int x);
  5.  
  6. #define PREVIOUS_FRAME(x, y) *(unsigned int *)(x + y)
  7.  
  8. long gap_between_x = 0;
  9.  
  10. void kernel_recursion(unsigned int x) {
  11.   long current_offset = gap_between_x - (long)(char *)&x;
  12.   gap_between_x = (long)(char *)&x;
  13.  
  14.   unsigned int previous_x = PREVIOUS_FRAME((char *)&x, current_offset);
  15.  
  16.   if (x < previous_x) {
  17.     handle_open_port(x); ++x;
  18.     kernel_recursion(previous_x);--x;
  19.     handle_close_port(x);
  20.   } else if (previous_x < x) {
  21.     handle_open_port(previous_x);
  22.     kernel_recursion(previous_x + 1); --x;
  23.     handle_close_port(previous_x);
  24.   } else {
  25.     handle_open_port(previous_x);
  26.     handle_close_port(previous_x);
  27.   }
  28. }
  29. void kernel(unsigned int x) {
  30.   gap_between_x = (long)&x;
  31.   kernel_recursion(0);
  32. }
  33.  
  34. int main() { kernel(666); }
  35.  
  36. void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
  37. void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
Tags: Kernel
Advertisement
Comments
  • imk0tter
    1 year
    # C++ 1.95 KB | 0 0
    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); }
  • imk0tter
    1 year
    # C++ 2.16 KB | 0 0
    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); }
  • imk0tter
    1 year
    # C++ 2.03 KB | 0 0
    1. #include "PORT_IO.h"
    2.  
    3. // NAME OF PORT OPENING FUNCTION FROM PORT_IO.h
    4. #define OPEN_PORT_FUNCTION print_open
    5. // NAME OF PORT CLOSING FUNCTION FROM PORT_IO.h
    6. #define CLOSE_PORT_FUNCTION print_close
    7. // NAME OF PORT CONNECTING FUNCTION FROM PORT_IO.h
    8. #define CONNECT_PORT_FUNCTION print_connect
    9.  
    10. void handle_open_port(unsigned int x, void *(*open_port)(unsigned int port));
    11. void handle_close_port(unsigned int x, void *(*close_port)(unsigned int port));
    12. void handle_connect_to_port(unsigned int x,
    13.                             void *(*connect_to_port)(unsigned int port));
    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(1337); }
    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. }
    • imk0tter
      1 year (edited)
      # C++ 0.24 KB | 0 0
      1. //PORT_IO.h
      2. #include <stdio.h>
      3.  
      4. void print_open(unsigned int x) { printf("Opened port %u\n", x); }
      5. void print_close(unsigned int x) { printf("Closed port %u\n", x); }
      6. void print_connect(unsigned int x) { printf("Connected port %u\n", x); }
Add Comment
Please, Sign In to add comment
Advertisement