- 1
- 2
- 3
- 4
try
{
}
catch(...) { /*um, nice weather!*/}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
try
{
}
catch(...) { /*um, nice weather!*/}
0
#include <iostream>
int main() {
const char* pituh = {};
std::cout << pituh;
}
Нахуя?
0
#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;
}
0
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);
Ладно.
0
#define $(x) [&](void)->auto{try{return (x);}catch(...){return decltype(x){};}}()
Собачка
0
#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?
0
// Ручной режим
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;
}
}
}
0
#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.
0
#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
−1
#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/