1. C++ / Говнокод #6640

    +147

    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
    ZeuS
    do
      {
        /*
          Тупые, притупые идусы из MS, не понимают что они тупые притупые. Дело в том, что в MSDN
          написано, что NetUserEnum может работать с уровнями 4, 23, а на практики мы получаем 
          большой индуский ХУЙ!
        */
    
        DWORD readed;
        DWORD total;
        USER_INFO_0 *buf0 = NULL;
        status = CWA(netapi32, NetUserEnum)(NULL, 0, FILTER_NORMAL_ACCOUNT, (LPBYTE *)&buf0, MAX_PREFERRED_LENGTH, &readed, &total, &handle);
    /////////////////////////////////////
    //Непонятно, может ли оно вернуть NULL. Помня фокус индусов с wsprintf, защитимся от этого.
      if(p == NULL)p = path; 
    //////////////////////////////////
    if(iSize == -1)
      {
        //Гении-индусы решили подмениь возрашаемое значение в Vista на -1, в случаи если не хватает
        //места на всю строку, однако буфер заполняется. Ума устаналивать LastError не хватило...
        iSize = _LengthW(pBuf);
      }
      else pBuf[iSize] = 0;
    ///////////////////////////////////
    //Я ибал в рот тупых уродов написавших тупой rfc и тупорлых говнокодеров,
            //Я ставлю листинг на проивзольны порт на все IP сервера, и пашел на хуй софт который не
            //сможет это прочитать. Возможно меня ввел в забулждение FlashFXP 3.6.0. Т.к. в destAddr
            //он отправляет какие то данные сервера. А по rfc, как я понел, там должны быть данные
            //сокс-сервера, где нужно ждать сединения.
            
            //Ищим свободный порт.
            ((SOCKADDR_IN6 *)destAddr)->sin6_port = 0;

    23525f567a2b456a, 12 Мая 2011

    Комментарии (17)
  2. C++ / Говнокод #6635

    +165

    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
    // header
    
        struct TMWFeatureSet
        {        
            TMWFeatureSet();
            ~TMWFeatureSet();
            
            enum TFeatureSetBitMask
            {
                EBackUpBitMask = 1, 
                ERestoreBitMask = 1 << 1, 
                EWipeBitMask = 1 << 2, 
                ELockBitMask = 1 << 3, 
                ELocateBitMask = 1 << 4, 
                EMessageBitMask = 1 << 5, 
                EScreamBitMask = 1 << 6, 
                EPrintBitMask = 1 << 7, 
                EShareBitMask = 1 << 8
            };
            
            enum TFeatureSet
            {
                EBackUp = 0, 
                ERestore, 
                EWipe, 
                ELock, 
                ELocate, 
                EMessage, 
                EScream,
                EPrint, 
                EShare,
                         
                ECount
            };
            
            
            void SetFeatureAttr( TInt iIndex, TBool aValue );
            
            void Reset( void );
             
            void ExternalizeL( RWriteStream & aOutputStream );
            
            void InternalizeL( RReadStream & aInputStream );
            
            RArray<TFeatureSetBitMask> iBitMasks;
            
            TFixedArray<TBool,ECount> iFeatureSetArr;       
        };        
    
    // implementation
    
        TMWFeatureSet::TMWFeatureSet()
        {
            iBitMasks.Append( EBackUpBitMask );
            iBitMasks.Append( ERestoreBitMask );
            iBitMasks.Append( EWipeBitMask );
            iBitMasks.Append( ELockBitMask );
            iBitMasks.Append( ELocateBitMask );
            iBitMasks.Append( EMessageBitMask );
            iBitMasks.Append( EScreamBitMask );
            iBitMasks.Append( EPrintBitMask );
            iBitMasks.Append( EShareBitMask );         
        }
        
        TMWFeatureSet::~TMWFeatureSet()
        {
            iBitMasks.Close();
        }
        
        void TMWFeatureSet::SetFeatureAttr( TInt iIndex, TBool aValue )
        {
            iFeatureSetArr[ iIndex ] = aValue;
        }
    
        void TMWFeatureSet::Reset( void )
        {
            for( TInt i = ( TInt ) TMWFeatureSet::EBackUp; i < ( TInt ) TMWFeatureSet::ECount; i++ )
            {
                SetFeatureAttr( i, EFalse );
            }
        }
    
        void TMWFeatureSet::ExternalizeL( RWriteStream & aOutputStream )
        {
            for( TInt i = ( TInt ) TMWFeatureSet::EBackUp; i < ( TInt ) TMWFeatureSet::ECount; i++ )
            {
                aOutputStream.WriteUint8L((TUint)iFeatureSetArr[ i ]);
            }
        }
    
        void TMWFeatureSet::InternalizeL( RReadStream & aInputStream )
        {
            for( TInt i = ( TInt ) TMWFeatureSet::EBackUp; i < ( TInt ) TMWFeatureSet::ECount; i++ )
            {
                iFeatureSetArr[ i ] = (TBool) aInputStream.ReadUint8L();
            }
        }

    Это реализация битовой маски и по шаблону Simpleton: реализация простейшей функциональности самым сложным способом известным разработчику.
    По идее надо было как то так:
    int mask;
    .....
    bool IsFeatureAvailable( feature )
    {
    return ( ( mask & feature ) == feature );
    }

    zurg, 12 Мая 2011

    Комментарии (58)
  3. C++ / Говнокод #6624

    +152

    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
    QString generateGuid( const std::string &tDeviceSerial,
            const std::string &nDatetime, const std::string &licnum,
            const char *violation )
    {
        std::ostringstream s;
        s << tDeviceSerial;
        s << nDatetime;
        s << licnum;
        s << violation;
        
        QCryptographicHash hash( QCryptographicHash::Md5 );
        hash.addData( QByteArray( s.str().c_str() ) );
        QByteArray result = hash.result();
        return convToHex( (unsigned char*)result.data(), result.size() );
    }

    Оно, конечно, работает. Но разобраться в таком коде....

    panter_dsd, 11 Мая 2011

    Комментарии (16)
  4. C++ / Говнокод #6623

    +161

    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
    QString convToHex( unsigned char *bytes, int size )
    {
    	if( size > 16 )
    		size = 16;
    	QString ret;
    	for( int i = 0; i < size; i++ )
    	{
    		char buf[3];
    		::sprintf( buf,"%02x", (unsigned int) bytes[i] );
    		ret += buf;
    	}	
    	return ret;
    }

    panter_dsd, 11 Мая 2011

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

    +170

    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
    int key;
    float ar1[3];
    int ar2[3];
    int cnt = 0;
    if (P[min][0] > 0) {ar1[cnt] = P[0][0]/P[min][0]; ar2[cnt++] = 0;}
    if (P[min][1] > 0) {ar1[cnt] = P[0][1]/P[min][1]; ar2[cnt++] = 1;}
    if (P[min][2] > 0) {ar1[cnt] = P[0][2]/P[min][2]; ar2[cnt++] = 2;}
    if (cnt == 1)
        key = ar2[0];
    else if (cnt == 2)
        key = (ar1[0] < ar1[1] ? ar2[0] : ar2[1]);
    else
        key = (ar1[0] < ar1[1] ? (ar1[0] < ar1[2] ? ar2[0] : ar2[2]) : (ar1[1] < ar1[2] ? ar2[1] : ar2[2]));

    Нужно было определить номер наименьшего положительного числа из трех.

    Kona-chan, 11 Мая 2011

    Комментарии (3)
  6. C++ / Говнокод #6608

    +159

    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
    class CVal
    {
    private:
        int m_val;
    public:
        __declspec(property(get=get_Val, put=put_Val)) int Val;
        int get_Val()
        {
            return m_val;
        }
        void put_Val(int val)
        {
            m_val = val;
        }
    };

    Говно в рамках стандарта C++.

    Говногость, 10 Мая 2011

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

    +167

    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
    struct LexicalToken
            {
            public:
                LexicalToken(DataStructs::Lexem &lex,
                             SyntaxTree::SyntaxNode::Type type,
                             const IOSystem::Position &pos = IOSystem::Position()) :
                    lexem(lex), position(pos), type(type)
                {}
    
                LexicalToken(const LexicalToken &other) :
                    lexem(other.lexem), position(other.position), type(other.type)
                {}
    
                LexicalToken& operator = (const LexicalToken &other)
                {
                    memcpy(this, &other, sizeof(LexicalToken));
                    return *this;
                }
    
                DataStructs::Lexem &lexem;
                IOSystem::Position position;
                SyntaxTree::SyntaxNode::Type type;
            };

    Use pointers, Luke

    Elvenfighter, 09 Мая 2011

    Комментарии (80)
  8. C++ / Говнокод #6581

    +160

    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
    #include <stdio.h>
    #include <boost/typeof/typeof.hpp>
    
    template<class T>
    struct __macro
    {
    	__declspec(thread) static T _;
    };
    
    template<class T>
    T __macro<T>::_;
    
    #define def(c) (__macro<typeof(c)>::_ = c)
    #define acc(c) (__macro<typeof(c)>::_)
    
    #define is_digit(x) (def(x),(acc(x) >= '0' && acc(x) <= '9') ? true : false)
    #define is_bugit(x) ((x >= '0' && x <= '9') ? true : false)
    
    int main()
    {
    	char hj;
    	
    	hj = '9';
    	printf("test->") && is_bugit(hj++) && printf("ok\n") || puts("no");
    
    	hj = '9';
    	printf("test->") && is_digit(hj++) && printf("ok\n") || puts("no");
    }

    e113c08d6cf14afb, 07 Мая 2011

    Комментарии (43)
  9. C++ / Говнокод #6536

    +147

    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
    /*Windows 8 source code.*/
    /*
    TOP SECRET Microsoft(c) Code
    Project: Cairo(tm)
    Projected release-date: Summer 2012
    */
    
    #include "winnt.h"
    #include "evenmore.h"
    #include "oldstuff.h"
    #include "billrulz.h"
    #define INSTALL_HARD_C
    #define INSTALL_DIR_WINDOWS
    
    char make_prog_look_big[160000000] ;
    
    void main()
    {
        while(!CRASHED)
        {
             display_copyright_message();
             display_bill_rules_message();
             do_nothing_loop();
    
             if (first_time_installation)
             {
                 make_4gb_megabyte_swapfile();
                 do_nothing_loop();
                 display_funny_3d();
                 hang_system();
             }
     
             write_something(anything);
             display_copyright_message();
             do_nothing_loop();
             do_some_stuff();
             if (still_not_crashed)
             {
                 display_copyright_message();
                 do_nothing_loop();
                 basically_run_windows_vista();
                 show3d_in_loop();
                 do_nothing_loop();
                 do_nothing_loop();
             }
         }
     
         if (detect_cache())
             disable_cache();
     
         if (fast_cpu())
         {
             set_wait_states(lots);
             set_mouse(speed, very_slow);
             set_mouse(action, jumpy);
             set_mouse(reaction, sometimes);
         }
        
         if (fast_gpu())
         {
             setitonfire(dx12);
         }
    
         if (lotofmemory()) 
         {  
            //achtung: red alert!
            /* allocateforfutureuse(200mb); */
             allocateforfutureuse(2gb);
    
         }
     
         /* printf("Welcome to Windows Vista"); */
         /* printf("Welcome to Windows 7"); */
         printf("Welcome to Windows 8");
     
         if (system_ok())
             crashex(aero3denalbed());
         else;
         /*    system_memory = open("a:\swp0001.swp", O_CREATE); */
    
     
         while(something)
         {
             allocate_random_memory();
             sleep(5);
             get_user_input();
             sleep(5);
             display_uac_prompt();
             act_on_user_input();
             sleep(5);
         }
         draw_3d_bsod();
         die();
    }

    wwwww, 03 Мая 2011

    Комментарии (15)
  10. C++ / Говнокод #6531

    +168

    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
    typedef union Variant
        {
        public:
            Variant() {}
    
            Variant(signed int val) :
                v_int(val)
            {}
            operator signed int &() { return const_cast<signed int&>(this->operator const signed int &()); }
            operator const signed int&() const { return v_int; }
    
            Variant(unsigned int val) :
                v_uint(val)
            {}
            operator unsigned int &() { return const_cast<unsigned int&>(this->operator const unsigned int &()); }
            operator const unsigned int &() const { return v_uint; }
    
            Variant(char val) :
                v_char(val)
            {}
            operator char &() { return const_cast<char&>(this->operator const char &()); }
            operator const char&() const { return v_char; }
    
            Variant(double val) :
                v_float(val)
            {}
            operator double &() { return const_cast<double&>(this->operator const double &()); }
            operator const double &() const { return v_float; }
    
            Variant(void *val) :
                v_ptr(val)
            {}
            operator void*& () { return const_cast<void*&>(this->operator void *&()); }
            operator const void* const& () const { return v_ptr; }
    
            static size_t getValueSize(const Type::OfType &type)
            {
                size_t result = 0;
                switch ( type )
                {
                case Type::Pointer:
                case Type::CharPtr:
                case Type::IntPtr:
                case Type::UIntPtr:
                case Type::RealPtr:
                case Type::String:
                    result = sizeof(v_ptr);
                    break;
                case Type::Char:
                    result = sizeof(v_char);
                    break;
                case Type::Int:
                    result = sizeof(v_int);
                    break;
                case Type::UInt:
                    result = sizeof(v_uint);
                    break;
                case Type::Real:
                    result = sizeof(v_float);
                    break;
                case Type::Void:
                    result = 0;
                    break;
                }
                return result;
            }
    
        private:
            void* v_ptr;
            char v_char;
            unsigned int v_uint;
            signed int v_int;
            double v_float;
        } Variant;

    Небольшая имплементация безтиповости ;-[

    Elvenfighter, 02 Мая 2011

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