From 58f7de7652190912ec741366f1ee1415dbb77c5c Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 10 Aug 2021 02:56:23 -0400 Subject: Commit brainfuck tools The foremost tool in this collection is the brainfuck debugger. It was written to assist with the 'boring flag checker' problem from RaRCTF 2021, but has good potential for general-purpose use. The compiler and decompiler are much more niche, given brainfuck is not typically a compiled language. They are from the same CTF and, although highly problem-specific, are kept around for posterity. A hello world program is saved under templates as a quick sanity check for the tools as well as for reference purposes, should it become useful. Signed-off-by: Malfurious --- tools/brainfuck/bf_decompile.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 tools/brainfuck/bf_decompile.py (limited to 'tools/brainfuck/bf_decompile.py') diff --git a/tools/brainfuck/bf_decompile.py b/tools/brainfuck/bf_decompile.py new file mode 100755 index 0000000..8caa97d --- /dev/null +++ b/tools/brainfuck/bf_decompile.py @@ -0,0 +1,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() -- cgit v1.2.3