Re: Використання мови Brainfuck для подолання антивірусного захисту
Інтерпретатор brainfuck
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
int main(void)
{
    uint8_t *m = calloc(30000, sizeof(uint8_t));
    uint32_t b = 0;
    char *c = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
    while (*c) {
        *c == '>' && ++m, *c == '<' && --m, *c == '+' && ++*m, *c == '-' && --*m,
        *c == '.' && putchar(*m), *c == ',' && (*m = getchar());
        if (*c == '[' && !*m && ++b) while (b) ++c, *c == '[' && ++b, *c == ']' && --b;
        if (*c == ']' &&  *m && ++b) while (b) --c, *c == '[' && --b, *c == ']' && ++b;
        c++;
    }
    return 0;
}та на asm, розмір 123 б.
    cinvoke calloc, 30000, 1
    mov esi, eax    ; память
    mov edi, c      ; код
    xor ebx, ebx    ; счетчик вложенности []
    jmp .s
@@: cmp byte[edi], '>'
    jne .1
    inc esi
.1: cmp byte[edi], '<'
    jne .2
    dec esi
.2: cmp byte[edi], '+'
    jne .3
    inc byte[esi]
.3: cmp byte[edi], '-'
    jne .4
    dec byte[esi]
.4: cmp byte[edi], '.'
    jne .5
    movzx eax, byte[esi]
    push eax
    call [putchar]
    pop eax
.5: cmp byte[edi], ','
    jne .6
    call [getchar]
    mov byte[esi], al
.6: cmp byte[edi], '['
    jne .7
    cmp byte[esi], 0
    jne .7
    inc ebx
    jmp .c
.a: inc edi
    cmp byte[edi], '['
    jne .b
    inc ebx
.b: cmp byte[edi], ']'
    jne .c
    dec ebx
.c: test ebx, ebx
    jne .a
.7: cmp byte[edi], ']'
    jne .8
    cmp byte[esi], 0
    je .8
    inc ebx
    jmp .f
.d: dec edi
    cmp byte[edi], ']'
    jne .e
    inc ebx
.e: cmp byte[edi], '['
    jne .f
    dec ebx
.f: test ebx, ebx
    jne .d
.8: inc edi
.s: cmp byte[edi], 0
    jne @b