- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
int iseven(long long int number)
{
struct Num {
unsigned int x:1;
unsigned int y:31;
unsigned int z:32;
} num = (*(struct Num*)(&number));
return num.x; //Если результат 1, то нечётное.
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
int iseven(long long int number)
{
struct Num {
unsigned int x:1;
unsigned int y:31;
unsigned int z:32;
} num = (*(struct Num*)(&number));
return num.x; //Если результат 1, то нечётное.
}
Функция определения чётности числа посредством возврата младшего бита.
0
longlong ** FUN_14000e5a0(longlong **param_1,LPCWSTR param_2,int param_3,uint param_4)
{
uint uVar1;
longlong **pplVar2;
longlong **hFile;
longlong *plVar3;
longlong **pplVar4;
DWORD DVar5;
LONG local_38;
undefined4 uStack_34;
pplVar4 = (longlong **)0x0;
uVar1 = param_4 & 0x1f;
if ((param_4 & 0x1f) == 0) {
uVar1 = 2;
}
pplVar2 = FUN_1400119f8(DAT_1400213a0,(longlong)param_1);
if (pplVar2 == (longlong **)0x0) {
return (longlong **)0x0;
}
if (param_3 == 1) {
DVar5 = (DWORD)((param_4 >> 0x11 & 1) != 0);
if ((param_4 >> 0x12 & 1) != 0) {
DVar5 = 7;
}
hFile = (longlong **)
CreateFileW(param_2,0x80000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,3,0x80,(HANDLE)0x0);
LAB_14000e70c:
if (hFile == (longlong **)0xffffffffffffffff) goto LAB_14000e7ad;
}
else {
if (param_3 == 2) {
DVar5 = (DWORD)((param_4 >> 0x11 & 1) != 0);
if ((param_4 >> 0x12 & 1) != 0) {
DVar5 = 7;
}
hFile = (longlong **)
CreateFileW(param_2,0xc0000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,4,0x80,(HANDLE)0x0);
goto LAB_14000e70c;
}
if (param_3 != 3) {
hFile = (longlong **)CONCAT44(uStack_34,local_38);
goto LAB_14000e70c;
}
DVar5 = (DWORD)((param_4 >> 0x11 & 1) != 0);
if ((param_4 >> 0x12 & 1) != 0) {
DVar5 = 7;
}
hFile = (longlong **)
CreateFileW(param_2,0xc0000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,2,0x80,(HANDLE)0x0);
if (hFile == (longlong **)0xffffffffffffffff) {
hFile = (longlong **)
CreateFileW(param_2,0x40000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,5,0,(HANDLE)0x0);
goto LAB_14000e70c;
}
}
if (hFile != (longlong **)0x0) {
if ((DAT_14001f140 == 0) || ((param_4 >> 0x13 & 1) != 0)) {
pplVar2[1] = (longlong *)0x0;
}
else {
plVar3 = (longlong *)HeapAlloc(DAT_1400204cc,0,(longlong)DAT_14001f140);
pplVar2[1] = plVar3;
}
*pplVar2 = (longlong *)hFile;
*(int *)(pplVar2 + 2) = DAT_14001f140;
*(undefined4 *)((longlong)pplVar2 + 0x14) = 0;
*(uint *)(pplVar2 + 4) = uVar1;
*(uint *)((longlong)pplVar2 + 0x24) = (uint)(param_3 == 1);
*(undefined4 *)((longlong)pplVar2 + 0x1c) = 1;
if ((param_3 == 2) && ((param_4 >> 0x14 & 1) != 0)) {
local_38 = 0;
SetFilePointer(hFile,0,&local_38,2);
}
pplVar4 = hFile;
if (param_1 == (longlong **)0xffffffffffffffff) {
pplVar4 = pplVar2;
}
if (pplVar4 != (longlong **)0x0) {
return pplVar4;
}
}
LAB_14000e7ad:
if (param_1 == (longlong **)0xffffffffffffffff) {
param_1 = pplVar2;
}
FUN_14001192c(DAT_1400213a0,(longlong)param_1);
return pplVar4;
}
0
char main[] = { 0xf0, 0x0f, 0xc7, 0xc8 };
0
/*
Brainfuck-C ( http://github.com/kgabis/brainfuck-c )
Copyright (c) 2012 Krzysztof Gabis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdio.h>
#define OP_END 0
#define OP_INC_DP 1
#define OP_DEC_DP 2
#define OP_INC_VAL 3
#define OP_DEC_VAL 4
#define OP_OUT 5
#define OP_IN 6
#define OP_JMP_FWD 7
#define OP_JMP_BCK 8
#define SUCCESS 0
#define FAILURE 1
#define PROGRAM_SIZE 4096
#define STACK_SIZE 512
#define DATA_SIZE 65535
#define STACK_PUSH(A) (STACK[SP++] = A)
#define STACK_POP() (STACK[--SP])
#define STACK_EMPTY() (SP == 0)
#define STACK_FULL() (SP == STACK_SIZE)
struct instruction_t {
unsigned short operator;
unsigned short operand;
};
static struct instruction_t PROGRAM[PROGRAM_SIZE];
static unsigned short STACK[STACK_SIZE];
static unsigned int SP = 0;
int compile_bf(FILE* fp) {
unsigned short pc = 0, jmp_pc;
int c;
while ((c = getc(fp)) != EOF && pc < PROGRAM_SIZE) {
switch (c) {
case '>': PROGRAM[pc].operator = OP_INC_DP; break;
case '<': PROGRAM[pc].operator = OP_DEC_DP; break;
case '+': PROGRAM[pc].operator = OP_INC_VAL; break;
case '-': PROGRAM[pc].operator = OP_DEC_VAL; break;
case '.': PROGRAM[pc].operator = OP_OUT; break;
case ',': PROGRAM[pc].operator = OP_IN; break;
case '[':
PROGRAM[pc].operator = OP_JMP_FWD;
if (STACK_FULL()) {
return FAILURE;
}
STACK_PUSH(pc);
break;
case ']':
if (STACK_EMPTY()) {
return FAILURE;
}
jmp_pc = STACK_POP();
PROGRAM[pc].operator = OP_JMP_BCK;
PROGRAM[pc].operand = jmp_pc;
PROGRAM[jmp_pc].operand = pc;
break;
default: pc--; break;
}
pc++;
}
if (!STACK_EMPTY() || pc == PROGRAM_SIZE) {
return FAILURE;
}
PROGRAM[pc].operator = OP_END;
return SUCCESS;
}
int execute_bf() {
unsigned short data[DATA_SIZE], pc = 0;
unsigned int ptr = DATA_SIZE;
while (--ptr) { data[ptr] = 0; }
while (PROGRAM[pc].operator != OP_END && ptr < DATA_SIZE) {
// (...)
Интерпретатор Brainfuck.
Полный код можно посмотреть тута:
https://github.com/kgabis/brainfuck-c/blob/master/brainfuck.c
0
template <typename Key, typename Value, size_t TblPower = 2>
struct HashMap {
struct Node
{
Key k;
Value v;
Node *n;
Node(const Key &key, const Value &value) :
k(key), v(value), n(NULL) {}
Node(const Key &key) :
k(key), v(), n(NULL) {}
};
constexpr static size_t TblSize = 1U << TblPower;
Node *table[TblSize] = {nullptr};
HashMap() {
}
~HashMap() {
for(size_t i = 0; i < TblSize; i++)
{
Node *entry = table[i];
while(entry)
{
Node *prev = entry;
entry = entry->n;
delete prev;
}
table[i] = NULL;
}
}
size_t HashFunc(const Key &key) const
{
/// TODO: string hash?
// handle hash: handle pointers usually aligned
return (((size_t) key) >> 8) & (TblSize - 1);
}
// just in case: check existance or constant access
forceinline Value *GetPtr(const Key &key) const
{
size_t hashValue = HashFunc(key);
Node *entry = table[hashValue];
while(likely(entry))
{
if(entry->k == key)
return &entry->v;
entry = entry->n;
}
return nullptr;
}
Value &operator [] (const Key &key)
{
return GetOrAllocate(key);
}
#define HASHFIND(key) \
size_t hashValue = HashFunc(key); \
Node *prev = NULL; \
Node *entry = table[hashValue]; \
\
while(entry && entry->k != key) \
{ \
prev = entry; \
entry = entry->n; \
}
Node * noinline _Allocate(Key key, size_t hashValue, Node *prev, Node *entry)
{
entry = new Node(key);
if(unlikely(!entry))
{
static Node error(key);
return &error;
}
if(prev == NULL)
table[hashValue] = entry;
else
prev->n = entry;
return entry;
}
Value& GetOrAllocate(const Key &key)
{
HASHFIND(key);
if(unlikely(!entry))
entry = _Allocate(key,hashValue, prev, entry);
return entry->v;
}
// тут был ещё один метод, но в говнокод не влез
}
когда СГОРЕЛО от STL
0
struct HashArrayMap {
struct Node
{
Key k;
Value v;
Node(const Key &key, const Value &value) :
k(key), v(value){}
Node(const Key &key) :
k(key), v(){}
};
constexpr static size_t TblSize = 1U << TblPower;
GrowArray<Node> table[TblSize];
HashArrayMap() {
}
~HashArrayMap() {
}
size_t HashFunc(const Key &key) const
{
/// TODO: string hash?
// handle hash: handle pointers usually aligned
return (((size_t) key) >> 8) & (TblSize - 1);
}
// just in case: check existance or constant access
Value *GetPtr(const Key &key) const
{
size_t hashValue = HashFunc(key);
const GrowArray<Node> &entry = table[hashValue];
for(int i = 0; i < entry.count; i++)
{
if(entry[i].k == key)
return &entry[i].v;
}
return nullptr;
}
Value &operator [] (const Key &key)
{
return GetOrAllocate(key);
}
#define HASHFIND(key) \
GrowArray<Node> &entry = table[HashFunc(key)]; \
int i; \
for(i = 0; i < entry.count; i++) \
if( entry[i].k == key ) \
break;
Value& GetOrAllocate(const Key &key)
{
HASHFIND(key);
if(i == entry.count )
entry.Add(Node(key));
return entry[i].v;
}
bool Remove(const Key &key)
{
HASHFIND(key);
if(i != entry.count)
{
entry.RemoveAt(i);
return true;
}
return false;
}
#undef HASHFIND
};
когда СГОРЕЛО от STL
0
template<class T>
struct GrowArray
{
T *mem = nullptr;
size_t count = 0;
size_t alloc = 0;
GrowArray(size_t init = 0)
{
if(init)
Grow(init);
}
~GrowArray()
{
if(mem)
free(mem);
mem = nullptr;
count = 0;
alloc = 0;
}
// non-copyable
GrowArray(const GrowArray &) = delete;
GrowArray &operator = (const GrowArray &) = delete;
void noinline Grow(size_t size)
{
if(!size)
size = 32;
T *newMem = (T*)(mem? realloc(mem, sizeof(T) * size): malloc(sizeof(T)*size));
if(!newMem)
return;
alloc = size;
mem = newMem;
}
// TODO: insert/append
bool Add(const T& newVal)
{
size_t newIdx = count + 1;
if(unlikely(newIdx > alloc))
Grow(alloc * 2);
if(unlikely(newIdx > alloc))
return false;
mem[count] = newVal;
count = newIdx;
return true;
}
// TODO: test
bool RemoveAt(size_t idx)
{
if(idx < count)
memmove(&mem[idx], &mem[idx+1], sizeof(T) * (count - idx - 1));
if(idx <= count)
{
count--;
return true;
}
return false;
}
T& operator[](size_t i) const
{
return mem[i];
}
};
0
С днём защитника жопы Борманда вас, питухи!
День защитника Путина.
0
#include <windows.h>
#define PL 7 //длинна пароля
const char F[] = "`1234567890-=\\qwertyuiop[]asdfghjkl;'zxcvbnm,./";
const char N[] = "1`2q1qw32we43er54rt65ty76yu87ui98io09op-0p[=-[]\\=]12wa23esaq34rdsw45tfde56ygfr67uhgt78ijhy89okju90plki0-[;lo-=]';p=\\'[qwszwedxzaerfcxsrtgvcdtyhbvfyujnbguikmnhiol,mjop;.,kp['/.l[]/;asxsdczxdfvcfgbvghnbhjmnjk,mkl.,l;/.;'";
const char L[] = { 1, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3 };
struct _
{
char P[PL + 1];
BYTE I[256], O[48];
};
void __stdcall $(int n, char c, _ *X)
{
X->P[n++] = c;
for (int i = 0; n < PL && i < L[X->I[c]]; $(n, N[X->O[X->I[c]] + i++], X));
for (int i = 0, d = 0, l = 0, s = 0; n == PL && i < n; (X->P[i] >= '0' && X->P[i] <= '9') ? d++ : (X->P[i] >= 'a' && X->P[i] <= 'z') ? l++ : s++, (d && l && s) ? _lwrite(-11, X->P, ++n), i = n : i++);
}
void main()
{
_ w;
w.P[PL] = '\n';
for (int i = 0; i < 47; w.I[F[i]] = i, w.O[i] = i ? w.O[i - 1] + L[i - 1] : 0, i++);
for (int i = 0; i < 47; $(0, F[i++], &w));
}
Генератор сложных (буквы, цифры, символы) паролей с выводом в консоль.
Выводит ВСЕ пароли заданной длинны, которые можно ввести по соседним клавишам без шифта. Всякие лесенки, зигзаги и т.п., т.е. все плохие...
В main переименовал, чтоб скомпилировать. Релизный exe-шник сразу стёр антивирус, сказал Trojan:Win32/Wacatac.B!ml
Обфускаторы рулят :)
−1
void branch(int *cnt, int accum, int nxt, int comn) {
printf("accum %d %d\n", accum, comn);
if (accum < 0 && comn == 41) {
*cnt = nxt;
} else if (accum == 0 && comn == 42) {
*cnt = nxt;
} else if (comn == 40) {
*cnt = nxt;
}
else {
(*cnt)++;
}
}
void dump(int word[]) {
int d = 0, x;
printf("%3c", ' ');
while (d != 10) {
printf("%5d ", d);
d++;
}
for (d = 0; d != MEM; d++) {
x = word[d];
if (0 == (d % 10))
puts(" "), printf("%3d", d);
printf(x >= 0 ? " +%.4X" : " %.4d", x);
}
puts(" ");
}
void dump_file(int word[]) {
int d = 0, x;
FILE *flrun;
flrun = fopen("wrt.txt", "w+");
fprintf(flrun, "%3c", ' ');
while (d != 10) {
fprintf(flrun, "%5d ", d);
d++;
}
for (d = 0; d != MEM; d++) {
x = word[d];
if (0 == (d % 10))
fprintf(flrun, "\n"), fprintf(flrun, "%3d", d);
fprintf(flrun, x >= 0 ? " +%.4X" : " %.4d", x);
}
}
long long_var(long var) {
long step = 1;
do {
step *= 10;
} while (var /= step);
return (step / 10);
}
Демотрон 3
Читалка для кода симплтрона