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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    try
    {
    }
    catch(...) { /*um, nice weather!*/}

    kcalbCube, 27 Мая 2022

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    #include <iostream>
    
    int main() {
        const char* pituh = {};
        std::cout << pituh;
    }

    Нахуя?

    3_dar, 26 Мая 2022

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

    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
    #define _CRT_SECURE_NO_WARNINGS
    #pragma comment(lib, "ntdll.lib")
    
    #include <Windows.h>
    #include <string>
    
    #define FLG_HEAP_ENABLE_TAIL_CHECK 0x10
    #define FLG_HEAP_ENABLE_FREE_CHECK 0x20
    #define FLG_HEAP_VALIDATE_PARAMETERS 0x40
    #define NT_GLOBAL_FLAG_DEBUGGED (FLG_HEAP_ENABLE_TAIL_CHECK | FLG_HEAP_ENABLE_FREE_CHECK | FLG_HEAP_VALIDATE_PARAMETERS)
    
    typedef NTSTATUS(NTAPI* pfnNtSetInformationThread)(
    	_In_ HANDLE	ThreadHandle,
    	_In_ ULONG ThreadInformationClass,
    	_In_ PVOID ThreadInformation,
    	_In_ ULONG ThreadInformationLenght);
    
    const ULONG ThreadHideFromDebugger = 0x11;
    
    typedef NTSTATUS(NTAPI* pfnNtQueryInformationProcess)(
    	_In_ HANDLE	ProcessHandle,
    	_In_ ULONG ProcessInformationClass,
    	_In_ PVOID ProcessInformation,
    	_In_ ULONG ProcessInformationLenght,
    	_Out_opt_ PULONG ReturnLenght);
    
    const UINT ProcessDebugPort = 7;
    
    void HideFromDebugger()
    {
    	HMODULE hNtDll = LoadLibrary("ntdll.dll");
    
    	if (!hNtDll)
    		throw std::exception("can't load kernel");
    
    	pfnNtSetInformationThread NtSetInformatioThread = (pfnNtSetInformationThread)
    		GetProcAddress(hNtDll, "NtSetInformationThread");
    
    	NTSTATUS status = NtSetInformatioThread(GetCurrentThread(), ThreadHideFromDebugger, NULL, NULL);
    }
    
    PVOID GetPEB()
    {
    	return (PVOID)__readfsword(0x0C * sizeof(PVOID));
    }
    
    int main()
    {
    	pfnNtQueryInformationProcess NtQueryInformationProcess = nullptr;
    	NTSTATUS status;
    	DWORD IsDebuggerPresent = 0;
    	HMODULE hNtDll = LoadLibrary("ntdll.dll");
    
    	if (!hNtDll)
    		throw std::exception("can't load kernel");
    	
    	NtQueryInformationProcess = (pfnNtQueryInformationProcess)GetProcAddress(hNtDll, "NtQueryInformationProcess");
    	void HideFromDebugger();
    
    	while (true)
    	{
    		PVOID pPEB = GetPEB();
    		DWORD offsetNtGlobalFlag = 0x68;
    		DWORD NtGlobalFlag = (DWORD)((PBYTE)pPEB + offsetNtGlobalFlag);
    
    		NTSTATUS stat = NtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
    			&IsDebuggerPresent, sizeof(DWORD), NULL);
    
    		if ((NtGlobalFlag & NT_GLOBAL_FLAG_DEBUGGED) || (stat == 0x00000000 && IsDebuggerPresent != 0))
    		{
    			MessageBox(NULL, "Close your fucking debuger!", "FUCK YOU", MB_OK);
    			return -1;
    		}
    	}
    
    	return 0;
    }

    PVOID, 23 Мая 2022

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

    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
    class Memory 
     { 
     public: 
             Memory() : hProcess{ nullptr }, pID{ 0 } {} 
             ~Memory() { SafeCloseHandle(hProcess); } 
      
             bool Attach(const char* _Process, DWORD rights) 
             { 
                     HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 
      
                     if (hSnap == INVALID_HANDLE_VALUE) 
                             return false; 
      
                     PROCESSENTRY32 pe{ sizeof(PROCESSENTRY32) }; 
      
                     while (Process32Next(hSnap, &pe)) 
                             if (!strcmp(pe.szExeFile, _Process)) 
                             { 
                                     SafeCloseHandle(hSnap); 
                                     pID = pe.th32ProcessID; 
      
                                     hProcess = OpenProcess(rights, 0, pe.th32ProcessID); 
      
     #ifdef _DEBUG || DEBUG 
                                     if (hProcess) // Ok 
                                     { 
                                             std::cout << "Attaching to process: " << _Process << " -> "; 
                                             ColoredMessage("OK!", LGREEN, true); 
                                     } 
     #endif // DEBUG 
      
                                     return true; 
                             } 
      
     #ifdef _DEBUG || DEBUG 
                     std::cout << "Attaching to process: " << _Process << " -> "; 
                     ColoredMessage("FAIL!", LRED, true); 
     #endif // DEBUG 
      
                     SafeCloseHandle(hSnap); 
                     return false; 
             } 
      
             PModule GetModule(const char* _Module) 
             { 
                     HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pID); 
      
                     if (hSnap == INVALID_HANDLE_VALUE) 
                             return PModule{ 0, 0 }; 
      
                     MODULEENTRY32 mEntry{ sizeof(MODULEENTRY32) }; 
      
                     while (Module32Next(hSnap, &mEntry)) 
                             if (!strcmp(mEntry.szModule, _Module)) 
                             { 
                                     SafeCloseHandle(hSnap); 
      
                                     return PModule{ (DWORD)mEntry.hModule, mEntry.modBaseSize }; 
                             } 
      
     #ifdef _DEBUG || DEBUG 
                     std::cout << "Getting module: "; ColoredMessage("FAIL!", LRED, true); 
     #endif // DEBUG 
      
      
                     SafeCloseHandle(hSnap); 
                     return PModule{ 0, 0 }; 
             } 
      
             template <class _Ty> 
             _Ty read(DWORD _Addr) 
             { 
                     DWORD _dwRead; 
                     _Ty _Val; 
      
     #ifdef _DEBUG || DEBUG  
                     if (!ReadProcessMemory(hProcess, (LPCVOID)_Addr, &_Val, sizeof(_Ty), &_dwRead)) 
                     { 
                             std::cout << "Reading the memory: "; 
                             ColoredMessage("FAIL!", LRED, true); 
                     } 
     #else // DEBUG  
                     ReadProcessMemory(hProcess, (LPCVOID)_Addr, &_Val, sizeof(_Ty), &_dwRead) 
     #endif 
                             return _Val; 
             } 
      
             template <class _Ty> 
             void write(DWORD _Addr, _Ty _Val) 
             { 
                     DWORD _dwWrite; 
      
     #ifdef _DEBUG || DEBUG  
                     if (!WriteProcessMemory(hProcess, (LPVOID)_Addr, &_Val, sizeof(_Ty), &_dwWrite)) 
                     { 
                             std::cout << "Writing the memory: "; 
                             ColoredMessage("FAIL!", LRED, true);

    Ладно.

    Ddddddddd, 22 Мая 2022

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

    0

    1. 1
    #define $(x) [&](void)->auto{try{return (x);}catch(...){return decltype(x){};}}()

    Собачка

    kcalbCube, 09 Мая 2022

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

    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
    #include <iostream>
    #include <vector>
    #include <string>
    
    int main()
    {
        int n = 6;
        std::vector<int> vec;
    
        for (int i = 0; i < n; i++)
        {
            if ((i % 2) == 0)
            {
                std::reverse(vec.begin(), vec.end());
            }
    
            vec.push_back(i);
    
            if ((i % 2) != 0)
            {
                std::reverse(vec.begin(), vec.end());
            }
    
            for (int j = 0; j < vec.size(); j++)
            {
                std::cout << vec[j] + 1;
                if (j != vec.size() - 1)
                {
                    std::cout << "-";
                }
            }
            std::cout << "\n";
    
        }
    }

    Цель напечатать на экране следующее:
    1
    2-1
    1-2-3
    4-3-2-1
    1-2-3-4-5
    6-5-4-3-2-1

    насколько это говнокод от 0 до 10?

    pistael, 05 Мая 2022

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

    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
    // Ручной режим
        if (!botMode) {
            cout << "Manual mode activated\n";
            Sleep(1000);
    
            while (1) {                                             // Основной цикл
    
                MAP = modMap(pos, MAP, PVM);
                auto moveField =  moveMapField(MAP);
                auto TVM = waveViewCheck(pos, MAP);                 // Вызов функции проверки видимости элементов
                PVM = refreshMap(PVM, TVM);
    
                system("cls");                                      // Очистка поля с каждой итерацией
                coutMAP(pos, MAP);                                  // Вывод всей карты
                cout << endl;
                coutMAP(pos, PVM);                                  // Вывод видимой карты
    
                if (MAP[pos.y][pos.x] == END) {
                    cout << endl << "Level Complete!\n";
                    Sleep(3000);
                    return 0;
                }
    
                int k = getch();
                if (k == 113 || k == 81) break;                     // Press Q - exit
                if (k == 224) k = getch();
                switch (k) {                                // Перемещение стрелочками
                    case 72:                                // Вверх
                        if ((moveField[pos.y-1][pos.x] == BLANK || (moveField[pos.y-1][pos.x] > 0 && MAP[pos.y-1][pos.x] % 2 == 1)) && pos.y > 0) {
                            pos.y -= 1;
                        }
                        break;
                    case 75:                                // Влево
                        if ((moveField[pos.y][pos.x-1] != WALL || (moveField[pos.y][pos.x-1] > 0 && MAP[pos.y][pos.x-1] % 2 == 1)) && pos.y > 0) {
                            pos.x -= 1;
                        }
                        break;
                    case 77:                                // Вправо
                        if ((moveField[pos.y][pos.x+1] != WALL || (moveField[pos.y][pos.x+1] > 0 && MAP[pos.y][pos.x+1] % 2 == 1)) && pos.y > 0) {
                            pos.x += 1;
                        }
                        break;
                    case 80:                                // Вниз
                        if ((moveField[pos.y+1][pos.x] != WALL || (moveField[pos.y+1][pos.x] > 0 && MAP[pos.y+1][pos.x] % 2 == 1)) && pos.y > 0) {
                            pos.y += 1;
                        }
                        break;
                }
            }
        }

    kcalbCube, 01 Мая 2022

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

    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
    #include <iostream>
    #include <string_view>
    #include <source_location>
     
    void log(const std::string_view message,
             const std::source_location location = 
                   std::source_location::current())
    {
        std::cout << "file: "
                  << location.file_name() << "("
                  << location.line() << ":"
                  << location.column() << ") `"
                  << location.function_name() << "`: "
                  << message << '\n';
    }
     
    template <typename T> void fun(T x)
    {
        log(x);
    }
     
    int main(int, char*[])
    {
        log("Hello world!");
        fun("Hello C++20!");
    }
    
    file: main.cpp(23:8) `int main(int, char**)`: Hello world!
    file: main.cpp(18:8) `void fun(T) [with T = const char*]`: Hello C++20!

    Previously, functions that desire to obtain this information about the call site (for logging, testing, or debugging purposes) must use macros so that predefined macros like __LINE__ and __FILE__ are expanded in the context of the caller. The source_location class provides a better alternative.

    kcalbCube, 27 Апреля 2022

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

    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
    #include <iostream>
    #include <vector>
    #include <thread>
    int f()
    {
        static int i = 0;
        synchronized { // begin synchronized block
            std::cout << i << " -> ";
            ++i;       // each call to f() obtains a unique value of i
            std::cout << i << '\n';
            return i; // end synchronized block
        }
    }
    int main()
    {
        std::vector<std::thread> v(10);
        for(auto& t: v)
            t = std::thread([]{ for(int n = 0; n < 10; ++n) f(); });
        for(auto& t: v)
            t.join();
    }
    
    0 -> 1
    1 -> 2
    2 -> 3
    ...
    99 -> 100

    https://en.cppreference.com/w/cpp/language/transactional_memory

    kcalbCube, 27 Апреля 2022

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

    −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
    #include "property.hpp"
    
    class person {
    public:
       person() = default;
       ~person() = default;
    
       SETTER_PRIM(int, id);
       SETTER_FLAG(bool, merried);
       SETTER_ENUM(human, type);
    
       SETTER_PTR(int, next);
       SETTER_ARR(std::string, address, 3);
    
       SETTER_OBJ_LR(std::string,  name);
       SETTER_OBJ_CLR(std::string, name);
       SETTER_OBJ_RR(std::string,  name);
    
       GETTER_PRIM(int, id);
       GETTER_FLAG(bool, merried);
       GETTER_ENUM(human, type);
    
       GETTER_OBJ_LR(std::string,  name);
       GETTER_OBJ_CLR(std::string, name);
    
       GETTER_PTR(int, next);
       GETTER_ARR(std::string, address);
    
    private:
       int id;
       human type;
    
       std::string name;
       std::string address[5];
    
       bool merried;
       int* next;
    };

    https://habr.com/ru/post/459212/

    kcalbCube, 26 Апреля 2022

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