summaryrefslogtreecommitdiffstats
path: root/tools/brainfuck/bf_decompile.py
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2021-08-10 02:56:23 -0400
committerMalfurious <m@lfurio.us>2021-08-10 02:56:23 -0400
commit58f7de7652190912ec741366f1ee1415dbb77c5c (patch)
treea4e09fe4a43914900f88e42cdcb0379d10bba0b5 /tools/brainfuck/bf_decompile.py
parent523791c15d7775f854a5bdea3463a11f14a85bfa (diff)
downloadlib-des-gnux-58f7de7652190912ec741366f1ee1415dbb77c5c.tar.gz
lib-des-gnux-58f7de7652190912ec741366f1ee1415dbb77c5c.zip
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 <m@lfurio.us>
Diffstat (limited to '')
-rwxr-xr-xtools/brainfuck/bf_decompile.py30
1 files changed, 30 insertions, 0 deletions
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()