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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #define IMAGE_BASE_RELOC_TYPE 0x0C
    #define IMAGE_BASE_RELOC_OFFSET 0x0FFF
    #define IMAGE_GET_BASE_RELOC_TYPE(entry) entry >> IMAGE_BASE_RELOC_TYPE
    #define IMAGE_GET_BASE_RELOC_OFFSET(entry) entry & IMAGE_BASE_RELOC_OFFSET
    
    __declspec(safebuffers) __declspec(noinline) DWORD mapping_code(LPVOID map_struct)
    {
    	auto map = static_cast<MM_DATA*>(map_struct);
    
    	auto base = map->base;
    
    	auto dos = reinterpret_cast<PIMAGE_DOS_HEADER>(base);
    	auto nt_headers = reinterpret_cast<PIMAGE_NT_HEADERS>(base + dos->e_lfanew);
    
    	auto opt_header = &nt_headers->OptionalHeader;
    	auto file_header = &nt_headers->FileHeader;
    
    	const bool has_entry_point = opt_header->AddressOfEntryPoint != 0;
    	auto dll_main = reinterpret_cast<DllMainFn>(base + opt_header->AddressOfEntryPoint);
    
    	auto load_library			= map->load_library;
    	auto get_proc_address		= map->get_proc_address;
    	auto virtual_protect		= map->virtual_protect;
    	auto rtl_add_function_table = map->rtl_add_function_table;
    	
    	auto reloc_dir = opt_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
    	auto location_delta = reinterpret_cast<uintptr_t>(base) - static_cast<uintptr_t>(opt_header->ImageBase);
    	
    	if (location_delta && reloc_dir.Size)
    	{
    		auto reloc_begin = reinterpret_cast<PIMAGE_BASE_RELOCATION>(base + reloc_dir.VirtualAddress);
    		auto reloc_end = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<std::byte*>(reloc_begin) + reloc_dir.Size);
    
    		while (reloc_begin < reloc_end && reloc_begin->SizeOfBlock)
    		{
    			auto amount_of_entries = (reloc_begin->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD);
    
    			auto entries = reinterpret_cast<PWORD>(reloc_begin + 1);
    
    			for (size_t i = 0; i < amount_of_entries; i++)
    			{
    				WORD type = IMAGE_GET_BASE_RELOC_TYPE(entries[i]);
    				WORD offset = IMAGE_GET_BASE_RELOC_OFFSET(entries[i]);
    
    				if (type == IMAGE_REL_BASED_DIR64)
    				{
    					uintptr_t* path_at = reinterpret_cast<uintptr_t*>(base + reloc_begin->VirtualAddress + offset);
    					*path_at += location_delta;
    				}
    			}
    			reloc_begin = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<std::byte*>(reloc_begin) + reloc_begin->SizeOfBlock);
    		}
    	}
    
    	auto import_dir = opt_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
    
    	if (import_dir.Size)
    	{
    		auto import_desc = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(base + import_dir.VirtualAddress);
    
    		while (import_desc->Name)
    		{
    			auto module_name = reinterpret_cast<char*>(base + import_desc->Name);
    			HMODULE module = load_library(module_name);
    
    			if (!module)
    			{
    				map->status = LOAD_LIBRARY_FAILED;
    				return -2;
    			}
    
    			auto INT_TABLE = reinterpret_cast<PIMAGE_THUNK_DATA>(base + (import_desc->OriginalFirstThunk ? import_desc->OriginalFirstThunk : import_desc->FirstThunk));
    			auto IAT_TABLE = reinterpret_cast<PIMAGE_THUNK_DATA>(base + (import_desc->FirstThunk));
    
    			for (; INT_TABLE->u1.AddressOfData ; INT_TABLE++, IAT_TABLE++)
    			{
    				FARPROC address = IMAGE_SNAP_BY_ORDINAL(INT_TABLE->u1.Ordinal) ? 
    					get_proc_address(module, reinterpret_cast<char*>(IMAGE_ORDINAL(INT_TABLE->u1.Ordinal))) :
    					get_proc_address(module, reinterpret_cast<PIMAGE_IMPORT_BY_NAME>(base + INT_TABLE->u1.AddressOfData)->Name);
    
    				if (!address)
    				{
    					map->status = GET_PROC_ADDRESS_FAILED;
    					return -3;
    				}
    
    				IAT_TABLE->u1.Function = reinterpret_cast<uintptr_t>(address);
    			}
    			++import_desc;
    		}
    	}
    
    	auto delay_dir = opt_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT];
    
    	if (delay_dir.Size)
    	{
    		auto delay_desc = reinterpret_cast<PIMAGE_DELAYLOAD_DESCRIPTOR>(base + delay_dir.VirtualAddress);
    
    		while (delay_desc->DllNameRVA)
    		{

    0xDEADBEEF, 09 Мая 2026

    Комментарии (0)
  2. Pascal / Говнокод #29255

    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
    const proc: if (in integer: a) cmp (in integer: b) then
                  lt: (in proc: ltPart)
                  eq: (in proc: eqPart)
                  gt: (in proc: gtPart)
                end if                   is func
      begin
        if a < b then
          ltPart;
        elsif a = b then
          eqPart;
        else
          gtPart;
        end if;
      end func;
    
    if yourAge cmp myAge then
      lt: writeln("You are yonger than me");
      eq: writeln("We have the same age");
      gt: writeln("You are older than me");
    end if;

    Desktop, 06 Мая 2026

    Комментарии (37)
  3. Python / Говнокод #29254

    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
    Counting Sort - O(n + k)
    
    Counting Sort	O(n + k)	O(n + k)	O(n + k)	O(k)	✅	Маленький диапазон значений
    def counting_sort(nums):
        count = defaultdict(int)
        minVal, maxVal = min(nums), max(nums)
        for val in nums:
            count[val] += 1
    
        index = 0
        for val in range(minVal, maxVal + 1):
            while count[val] > 0:
                nums[index] = val
                index += 1
                count[val] -= 1
    
    
    
    from collections import defaultdict
    
    def stable_counting_sort(nums):
        if not nums:
            return nums
    
        # 1. Считаем сколько раз встретилось каждое число
        count = defaultdict(int)
        for val in nums:
            count[val] += 1
    
        # 2. Получаем отсортированные ключи
        sorted_keys = sorted(count.keys())
    
        # 3. Считаем префиксные суммы (позиции для стабильности)
        positions = {}
        total = 0
        for key in sorted_keys:
            positions[key] = total
            total += count[key]
    
        # 4. Создаём массив результата
        output = [0] * len(nums)
        for val in nums:
            index = positions[val]
            output[index] = val
            positions[val] += 1  # увеличиваем позицию для следующего одинакового элемента
    
        return output

    storvus, 03 Мая 2026

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

    0

    1. 1
    IT Оффтоп #233

    #203: https://govnokod.ru/28954 https://govnokod.xyz/_28954
    #204: https://govnokod.ru/28971 https://govnokod.xyz/_28971
    #205: https://govnokod.ru/28986 https://govnokod.xyz/_28986
    #206: https://govnokod.ru/28991 https://govnokod.xyz/_28991
    #207: https://govnokod.ru/29002 https://govnokod.xyz/_29002
    #208: https://govnokod.ru/29060 https://govnokod.xyz/_29060
    #209: https://govnokod.ru/29070 https://govnokod.xyz/_29070
    #210: https://govnokod.ru/29079 https://govnokod.xyz/_29079
    #211: https://govnokod.ru/29092 https://govnokod.xyz/_29092
    #212: https://govnokod.ru/29093 https://govnokod.xyz/_29093
    #213: https://govnokod.ru/29104 https://govnokod.xyz/_29104
    #214: https://govnokod.ru/29114 https://govnokod.xyz/_29114
    #215: https://govnokod.ru/29125 https://govnokod.xyz/_29125
    #216: https://govnokod.ru/29132 https://govnokod.xyz/_29132
    #217: https://govnokod.ru/29147 https://govnokod.xyz/_29147
    #218: https://govnokod.ru/29156 https://govnokod.xyz/_29156
    #219: https://govnokod.ru/29166 https://govnokod.xyz/_29166
    #220: https://govnokod.ru/29181 https://govnokod.xyz/_29181
    #221: https://govnokod.ru/29185 https://govnokod.xyz/_29185
    #222: https://govnokod.ru/29190 https://govnokod.xyz/_29190
    #223: https://govnokod.ru/29203 https://govnokod.xyz/_29203
    #224: https://govnokod.ru/29211 https://govnokod.xyz/_29211
    #225: https://govnokod.ru/29212 https://govnokod.xyz/_29212
    #226: https://govnokod.ru/29218 https://govnokod.xyz/_29218
    #227: https://govnokod.ru/29220 https://govnokod.xyz/_29220
    #228: https://govnokod.ru/29230 https://govnokod.xyz/_29230
    #229: https://govnokod.ru/29235 https://govnokod.xyz/_29235
    #230: https://govnokod.ru/29241 https://govnokod.xyz/_29241
    #231: https://govnokod.ru/29246 https://govnokod.xyz/_29246
    #232: https://govnokod.ru/29249 https://govnokod.xyz/_29249

    nepeKamHblu_nemyx, 02 Мая 2026

    Комментарии (126)
  5. PHP / Говнокод #29252

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public function getResource(): ResourceInterface
    {
        $locale = $this->localeRepository->getByKey($this->getCurrentLocaleKey());
    
        return new Resource($locale->getKey());
    }

    tre, 29 Апреля 2026

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

    0

    1. 1
    Пиздец-оффтоп #128

    #98: https://govnokod.ru/28932 https://govnokod.xyz/_28932
    #99: https://govnokod.ru/28936 https://govnokod.xyz/_28936
    #100: https://govnokod.ru/28940 https://govnokod.xyz/_28940
    #101: https://govnokod.ru/28949 https://govnokod.xyz/_28949
    #102: https://govnokod.ru/28978 https://govnokod.xyz/_28978
    #103: https://govnokod.ru/28982 https://govnokod.xyz/_28982
    #104: https://govnokod.ru/28989 https://govnokod.xyz/_28989
    #105: https://govnokod.ru/29052 https://govnokod.xyz/_29052
    #106: https://govnokod.ru/29069 https://govnokod.xyz/_29069
    #107: https://govnokod.ru/29086 https://govnokod.xyz/_29086
    #108: https://govnokod.ru/29102 https://govnokod.xyz/_29102
    #109: https://govnokod.ru/29126 https://govnokod.xyz/_29126
    #110: https://govnokod.ru/29136 https://govnokod.xyz/_29136
    #111: https://govnokod.ru/29142 https://govnokod.xyz/_29142
    #112: https://govnokod.ru/29155 https://govnokod.xyz/_29155
    #113: https://govnokod.ru/29160 https://govnokod.xyz/_29160
    #114: https://govnokod.ru/29165 https://govnokod.xyz/_29165
    #115: https://govnokod.ru/29173 https://govnokod.xyz/_29173
    #116: https://govnokod.ru/29174 https://govnokod.xyz/_29174
    #117: https://govnokod.ru/29182 https://govnokod.xyz/_29182
    #118: https://govnokod.ru/29191 https://govnokod.xyz/_29191
    #119: https://govnokod.ru/29196 https://govnokod.xyz/_29196
    #120: https://govnokod.ru/29205 https://govnokod.xyz/_29205
    #121: https://govnokod.ru/29216 https://govnokod.xyz/_29216
    #122: https://govnokod.ru/29219 https://govnokod.xyz/_29219
    #123: https://govnokod.ru/29232 https://govnokod.xyz/_29232
    #124: https://govnokod.ru/29237 https://govnokod.xyz/_29237
    #125: https://govnokod.ru/29239 https://govnokod.xyz/_29239
    #126: https://govnokod.ru/29244 https://govnokod.xyz/_29244
    #127: https://govnokod.ru/29248 https://govnokod.xyz/_29248

    nepeKamHblu_nemyx, 28 Апреля 2026

    Комментарии (330)
  7. Haskell / Говнокод #29250

    +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
    {-# LANGUAGE OverloadedStrings #-}
    import qualified Data.Text.Lazy.IO as LIO
    import GHC.IO.StdHandles
    import Text.Regex.TDFA
    import qualified Text.Regex.TDFA.Text.Lazy as RL
    import Data.Array
    import qualified Data.Text.Lazy as TL
    import System.Environment
    import System.Exit
    import System.IO
    import qualified Language.C.Syntax.Constants as CC
    import Data.Char
    
    printMatch t matches i =
        let (offset, len) = matches ! i in
        let offset' = fromIntegral offset in
        let len' = fromIntegral len in
        LIO.putStr $ TL.take len' $ TL.drop offset' t
    
    printHead t matches =
        let (offset, len) = matches ! 0 in
        let offset' = fromIntegral offset in
        let len' = fromIntegral len in
        LIO.putStr $ TL.take offset' t
    
    printTrail t matches =
        let (offset, len) = matches ! 0 in
        let offset' = fromIntegral offset in
        let len' = fromIntegral len in
        LIO.putStr $ TL.drop (offset' + len') t
    
    need_capture_trail acc ".*" = (False, reverse acc)
    need_capture_trail acc [] = (True, reverse acc)
    need_capture_trail acc (c : rest) = need_capture_trail (c : acc) rest
    
    getRE :: [String] -> Either String (RL.Regex, Bool, String)
    getRE args =
        case args of
          (re_str : repl_str : _) ->
              let (trail_needed, re_str') = need_capture_trail [] re_str in
              let re_text = TL.pack $ CC.unescapeString re_str' in
              case RL.compile defaultCompOpt defaultExecOpt re_text of
                Right re ->
                    Right (re, trail_needed, CC.unescapeString repl_str)
                Left err ->
                    Left err
          _ ->
              Left "Regexp expected"
    
    -- replacement :: TL.Text -> Int -> _ -> String -> IO ()
    replacement _ _ _ [] = return ()
    replacement t n_matches matches (c : rest)
        | ord c <= n_matches = do
               printMatch t matches (ord c)
               replacement t n_matches matches rest
        | True = do
            putChar c
            replacement t n_matches matches rest
    
    exitError :: String -> IO ()
    exitError msg = do
      hPutStrLn stderr msg
      exitWith (ExitFailure 1)
    
    main :: IO ()
    main = do
        args <- getArgs
        case getRE args of
          Right (re, trail_needed, repl) -> do
              t <- LIO.hGetContents stdin
              case RL.execute re t of
                Right (Just matches) ->
                    do
                      let n_matches = snd $ bounds matches
                      -- print matches
                      printHead t matches
                      replacement t n_matches matches repl
                      if trail_needed then
                          printTrail t matches
                      else
                          return ()
                Right Nothing -> do
                    exitError "Pattern not found"
                Left err -> do
                    exitError err
          Left err -> do
             exitError err

    Текст UNIX-way утилиты fed
    Капча: p2ux

    CHayT, 25 Апреля 2026

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

    0

    1. 1
    IT Оффтоп #232

    #202: https://govnokod.ru/28951 https://govnokod.xyz/_28951
    #203: https://govnokod.ru/28954 https://govnokod.xyz/_28954
    #204: https://govnokod.ru/28971 https://govnokod.xyz/_28971
    #205: https://govnokod.ru/28986 https://govnokod.xyz/_28986
    #206: https://govnokod.ru/28991 https://govnokod.xyz/_28991
    #207: https://govnokod.ru/29002 https://govnokod.xyz/_29002
    #208: https://govnokod.ru/29060 https://govnokod.xyz/_29060
    #209: https://govnokod.ru/29070 https://govnokod.xyz/_29070
    #210: https://govnokod.ru/29079 https://govnokod.xyz/_29079
    #211: https://govnokod.ru/29092 https://govnokod.xyz/_29092
    #212: https://govnokod.ru/29093 https://govnokod.xyz/_29093
    #213: https://govnokod.ru/29104 https://govnokod.xyz/_29104
    #214: https://govnokod.ru/29114 https://govnokod.xyz/_29114
    #215: https://govnokod.ru/29125 https://govnokod.xyz/_29125
    #216: https://govnokod.ru/29132 https://govnokod.xyz/_29132
    #217: https://govnokod.ru/29147 https://govnokod.xyz/_29147
    #218: https://govnokod.ru/29156 https://govnokod.xyz/_29156
    #219: https://govnokod.ru/29166 https://govnokod.xyz/_29166
    #220: https://govnokod.ru/29181 https://govnokod.xyz/_29181
    #221: https://govnokod.ru/29185 https://govnokod.xyz/_29185
    #222: https://govnokod.ru/29190 https://govnokod.xyz/_29190
    #223: https://govnokod.ru/29203 https://govnokod.xyz/_29203
    #224: https://govnokod.ru/29211 https://govnokod.xyz/_29211
    #225: https://govnokod.ru/29212 https://govnokod.xyz/_29212
    #226: https://govnokod.ru/29218 https://govnokod.xyz/_29218
    #227: https://govnokod.ru/29220 https://govnokod.xyz/_29220
    #228: https://govnokod.ru/29230 https://govnokod.xyz/_29230
    #229: https://govnokod.ru/29235 https://govnokod.xyz/_29235
    #230: https://govnokod.ru/29241 https://govnokod.xyz/_29241
    #231: https://govnokod.ru/29246 https://govnokod.xyz/_29246

    nepeKamHblu_nemyx, 23 Апреля 2026

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

    0

    1. 1
    Пиздец-оффтоп #127

    #97: https://govnokod.ru/28918 https://govnokod.xyz/_28918
    #98: https://govnokod.ru/28932 https://govnokod.xyz/_28932
    #99: https://govnokod.ru/28936 https://govnokod.xyz/_28936
    #100: https://govnokod.ru/28940 https://govnokod.xyz/_28940
    #101: https://govnokod.ru/28949 https://govnokod.xyz/_28949
    #102: https://govnokod.ru/28978 https://govnokod.xyz/_28978
    #103: https://govnokod.ru/28982 https://govnokod.xyz/_28982
    #104: https://govnokod.ru/28989 https://govnokod.xyz/_28989
    #105: https://govnokod.ru/29052 https://govnokod.xyz/_29052
    #106: https://govnokod.ru/29069 https://govnokod.xyz/_29069
    #107: https://govnokod.ru/29086 https://govnokod.xyz/_29086
    #108: https://govnokod.ru/29102 https://govnokod.xyz/_29102
    #109: https://govnokod.ru/29126 https://govnokod.xyz/_29126
    #110: https://govnokod.ru/29136 https://govnokod.xyz/_29136
    #111: https://govnokod.ru/29142 https://govnokod.xyz/_29142
    #112: https://govnokod.ru/29155 https://govnokod.xyz/_29155
    #113: https://govnokod.ru/29160 https://govnokod.xyz/_29160
    #114: https://govnokod.ru/29165 https://govnokod.xyz/_29165
    #115: https://govnokod.ru/29173 https://govnokod.xyz/_29173
    #116: https://govnokod.ru/29174 https://govnokod.xyz/_29174
    #117: https://govnokod.ru/29182 https://govnokod.xyz/_29182
    #118: https://govnokod.ru/29191 https://govnokod.xyz/_29191
    #119: https://govnokod.ru/29196 https://govnokod.xyz/_29196
    #120: https://govnokod.ru/29205 https://govnokod.xyz/_29205
    #121: https://govnokod.ru/29216 https://govnokod.xyz/_29216
    #122: https://govnokod.ru/29219 https://govnokod.xyz/_29219
    #123: https://govnokod.ru/29232 https://govnokod.xyz/_29232
    #124: https://govnokod.ru/29237 https://govnokod.xyz/_29237
    #125: https://govnokod.ru/29239 https://govnokod.xyz/_29239
    #126: https://govnokod.ru/29244 https://govnokod.xyz/_29244

    nepeKamHblu_nemyx, 15 Апреля 2026

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    &#x1f437;&#x1f437;&#x1f437;
    
    Рант-тред, иди!
    
    Вахтер, багровей!

    MOPCKAR_CBNHNHA, 07 Апреля 2026

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