summaryrefslogtreecommitdiffstats
path: root/tools/brainfuck/bf_decompile.py
blob: 8caa97de81fbc4374411d299aab543f7f737dcc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
import sys

if len(sys.argv) < 2:
    print("Give me filename...")
    exit()

bytecode = {
    0: '>',
    2: '<',
    7: '+',
    6: '-',
    5: '.',
    4: ',',
    3: '[',
    1: ']',
}

bin_buff = open(sys.argv[1], mode="rb").read()
src_file = open(sys.argv[1]+".bf", mode="w")

for b in bin_buff:
    try:
        c = bytecode[b & 0x07]
        src_file.write(c)
    except:
        print("Error while processing file (aborting...)")
        exit()

src_file.close()