1. Список говнокодов пользователя bormand

    Всего: 168

  2. Python / Говнокод #28531

    −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
    key_base_len = random.randint(30,61)
    key_base = bytearray(key_base_len)
    for i in range(key_base_len):
        key_base[i] = random.randint(0,255)
    
    key = bytearray(8)
    key[0] = chip_uid_chksum ^ key_base[ 4 * (key_base_len // 7)]
    key[1] = chip_uid_chksum ^ key_base[      key_base_len // 5 ]
    key[2] = chip_uid_chksum ^ key_base[      key_base_len // 7 ]
    key[3] = chip_uid_chksum ^ key_base[ 6 * (key_base_len // 7)]
    key[4] = chip_uid_chksum ^ key_base[ 3 * (key_base_len // 7)]
    key[5] = chip_uid_chksum ^ key_base[ 3 * (key_base_len // 5)]
    key[6] = chip_uid_chksum ^ key_base[ 5 * (key_base_len // 7)]
    key[7] = (chip_id + key[0]) & 0xff
    
    return key, key_base

    Китайцы и криптография.

    Сначала программатор отдаёт контроллеру key_base, а затем юзает key чтобы ксорить с ним заливаемую прошивку.

    bormand, 31 Декабря 2022

    Комментарии (41)
  3. Java / Говнокод #28305

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    import java.security.*
    
    var keys = KeyPairGenerator.getInstance("EC").generateKeyPair();
    var blankSignature = new byte[64]; // zero bytes
    var sig = Signature.getInstance("SHA256WithECDSAInP1363Format");
    sig.initVerify(keys.getPublic());
    sig.update("Hello, World".getBytes()); // anything
    sig.verify(blankSignature); // true

    Сказка о том, как джавушки переписали код с небезопасного языка на безопасный и помножили проверку подписей на ноль (в прямом смысле).

    https://neilmadden.blog/2022/04/19/psychic-signatures-in-java/

    bormand, 31 Июля 2022

    Комментарии (35)
  4. Куча / Говнокод #27878

    +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
    EXAMPLE
    
    To specify what kind of authorization is needed to execute the program /usr/bin/pk-example-frobnicate as another user, simply write an action definition file like this
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE policyconfig PUBLIC
      "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
      "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
    <policyconfig>
    
      <vendor>Examples for the PolicyKit Project</vendor>
      <vendor_url>http://hal.freedesktop.org/docs/PolicyKit/</vendor_url>
    
      <action id="org.freedesktop.policykit.example.pkexec.run-frobnicate">
        <description>Run the PolicyKit example program Frobnicate</description>
        <description xml:lang="da">Kør PolicyKit eksemplet Frobnicate</description>
        <message>Authentication is required to run the PolicyKit example program Frobnicate (user=$(user), program=$(program), command_line=$(command_line))</message>
        <message xml:lang="da">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate (user=$(user), program=$(program), command_line=$(command_line))</message>
        <icon_name>audio-x-generic</icon_name>
        <defaults>
          <allow_any>no</allow_any>
          <allow_inactive>no</allow_inactive>
          <allow_active>auth_self_keep</allow_active>
        </defaults>
        <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pk-example-frobnicate</annotate>
      </action>
    
    </policyconfig>

    Simply write an action definition file like this, they said...

    bormand, 17 Декабря 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #define POOL_ZERO_DOWN_LEVEL_SUPPORT
    #include <wdm.h>
    
    char* p = ExAllocatePoolZero(NonPagedPool, 42, '_GK_');
    ASSERT(p[0] == 0);

    https://www.osr.com/blog/2020/07/14/bug-in-new-function-exallocatepoolzero-results-in-security-vulnerability-and-crashes/

    microsoft_real_calloc() и 100500 способов отстрела ноги с помощью него.

    bormand, 02 Декабря 2021

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

    +3

    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
    for (size_t i = 0; i < 4; ++i) {
        __m128 x0 = _mm_loadu_ps((const float*)blocks[0] + i * 4);
        __m128 x1 = _mm_loadu_ps((const float*)blocks[1] + i * 4);
        __m128 x2 = _mm_loadu_ps((const float*)blocks[2] + i * 4);
        __m128 x3 = _mm_loadu_ps((const float*)blocks[3] + i * 4);
     
        __m128 t0 = _mm_unpacklo_ps(x0, x1);
        __m128 t1 = _mm_unpackhi_ps(x0, x1);
        __m128 t2 = _mm_unpacklo_ps(x2, x3);
        __m128 t3 = _mm_unpackhi_ps(x2, x3);
     
        x[i * 4 + 0] = _mm_castps_si128(_mm_movelh_ps(t0, t2));
        x[i * 4 + 1] = _mm_castps_si128(_mm_movehl_ps(t2, t0));
        x[i * 4 + 2] = _mm_castps_si128(_mm_movelh_ps(t1, t3));
        x[i * 4 + 3] = _mm_castps_si128(_mm_movehl_ps(t3, t1));
    }

    4х MD5

    https://ideone.com/a8YcZ8

    bormand, 12 Сентября 2021

    Комментарии (197)
  7. C++ / Говнокод #27621

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    struct Foo {
    };
    
    struct Bar {
        int x[0];
    };

    https://ideone.com/upuoOg

    Какая консистентность )))

    bormand, 27 Августа 2021

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

    +4

    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
    while (1) {
        uint16_t state = in(USB_BASE + USB_ISTR);
        if (state & 0x8000) {
            uint16_t epstat = in(USB_BASE + USB_EP0R);
            if (epstat & 0x8000) {
                // RX done
                if (epstat & 0x0800) {
                    // setup
                    if ((usbRead(0x180) == 0x80) && (usbRead(0x181) == 0x06)) {
                        uint16_t maxlen = (usbRead(0x187) << 8) | usbRead(0x186);
                        if (usbRead(0x183) == 0x01) {
                            // send device descriptor
                            copyToUsb(0x0100, deviceDescriptor, sizeof(deviceDescriptor));
                            if (sizeof(deviceDescriptor) < maxlen)
                                maxlen = sizeof(deviceDescriptor);
                            out(USB_SRAM_BASE + 0x04, 0x9000 + maxlen); // TX count
                            // STAT_TX=11 (valid)
                            if ((in(USB_BASE + USB_EP0R) & 0x0010) != 0x0010)
                                out(USB_BASE + USB_EP0R, 0x0210);
                            if ((in(USB_BASE + USB_EP0R) & 0x0020) != 0x0020)
                                out(USB_BASE + USB_EP0R, 0x0220);
                        } else if (usbRead(0x183) == 0x02) {
                            // send config descriptor
                            copyToUsb(0x0100, configDescriptor, sizeof(configDescriptor));
                            if (sizeof(configDescriptor) < maxlen)
                                maxlen = sizeof(configDescriptor);
                            out(USB_SRAM_BASE + 0x04, 0x9000 + maxlen); // TX count
                            // STAT_TX=11 (valid)
                            if ((in(USB_BASE + USB_EP0R) & 0x0010) != 0x0010)
                                out(USB_BASE + USB_EP0R, 0x0210);
                            if ((in(USB_BASE + USB_EP0R) & 0x0020) != 0x0020)
                                out(USB_BASE + USB_EP0R, 0x0220);
                        } else {
    
    // ... и ещё сотня строк в том же духе ...

    Иногда в меня вселяется дух PHP...

    bormand, 13 Июля 2021

    Комментарии (30)
  9. Куча / Говнокод #27457

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Tactic Notation "sleep" integer(seconds) :=
        do seconds try solve [ timeout 1 (repeat eapply proj1) ].
    
    Goal True.
        sleep 3.
        exact I.
    Qed.

    Какой пруф )))

    bormand, 06 Июня 2021

    Комментарии (13)
  10. Куча / Говнокод #27427

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Inductive my_bool :=
    | my_false
    | my_true.
    
    Theorem shit_happens:
      (if my_false then 42 else 100500) = 42.
    Proof.
      reflexivity.
    Qed.

    Какая типизация )))

    bormand, 14 Мая 2021

    Комментарии (70)
  11. C++ / Говнокод #27029

    +5

    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
    #include <iostream>
    #include <set>
    #include <unicode/brkiter.h>
    #include <unicode/unistr.h>
    #include <unicode/coll.h>
    #include <unicode/sortkey.h>
    
    bool hasRepeatingCharacters(const icu::UnicodeString &word)
    {
        icu::Locale locale = icu::Locale::getDefault();
        UErrorCode status = U_ZERO_ERROR;
        std::unique_ptr<icu::BreakIterator> it{icu::BreakIterator::createCharacterInstance(locale, status)};
        if (U_FAILURE(status)) throw 42;
        it->setText(word);
    
        std::unique_ptr<icu::Collator> collator{icu::Collator::createInstance(status)};
        if (U_FAILURE(status)) throw 42;
        collator->setStrength(icu::Collator::SECONDARY);
    
        auto less = [](const icu::CollationKey &k1, const icu::CollationKey &k2){
            UErrorCode status = U_ZERO_ERROR;
            bool isLess = k1.compareTo(k2, status) == UCOL_LESS;
            if (U_FAILURE(status)) throw 42;
            return isLess;
        };
        std::set<icu::CollationKey, decltype(less)> cache(less);
    
        int32_t p = it->first();
        while (p != icu::BreakIterator::DONE) {
            int32_t q = it->next();
            if (q == icu::BreakIterator::DONE)
                break;
    
            icu::CollationKey key;
            collator->getCollationKey(word.tempSubStringBetween(p, q), key, status);
            if (U_FAILURE(status)) throw 42;
    
            if (cache.find(key) != cache.end())
                return true;
    
            cache.insert(key);
            p = q;
        }
    
        return false;
    }
    
    int main()
    {
        icu::UnicodeString words(u8"Example english Боб мир כוכב 民主主義語こんにちは", "utf-8");
    
        icu::Locale locale = icu::Locale::getDefault();
        UErrorCode status = U_ZERO_ERROR;
        std::unique_ptr<icu::BreakIterator> it{icu::BreakIterator::createWordInstance(locale, status)};
        if (U_FAILURE(status)) throw 42;
        it->setText(words);
    
        int32_t p = it->first();
        while (p != icu::BreakIterator::DONE) {
            int32_t q = it->next();
            if (q == icu::BreakIterator::DONE)
                break;
    
            if (it->getRuleStatus() != UBRK_WORD_NONE)
            {
                icu::UnicodeString word{words.tempSubStringBetween(p, q)};
                bool hasRepeats = hasRepeatingCharacters(word);
    
                std::string wordUtf8;
                word.toUTF8String(wordUtf8);
                std::cout << (hasRepeats ? "Has repeats: " : "No repeats: ") << wordUtf8 << std::endl;
            }
    
            p = q;
        }
    
        return 0;
    }

    По мотивам https://govnokod.ru/27025

    Сформировать строку из слов исходной строки, содержащих повторяющиеся буквы.

    В 60 строк, к сожалению, не уложился :(

    bormand, 14 Октября 2020

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