Last active
June 4, 2019 10:01
-
-
Save FrankSpierings/043be87aaf249a302e4cac9998d692f4 to your computer and use it in GitHub Desktop.
Create a bitmap file which can be used as a cmd/batch file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# | |
#Based on: https://www.thelacunablog.com/open-command-prompt-ms-paint.html | |
import struct | |
from PIL import Image | |
def imagegen(s, path): | |
# Fix header | |
s = '\x00\x00\x0a\x0d\x0a\x0d' + s | |
# Blocksize | |
bs = 3 | |
# Calc padding | |
padnr = bs - (len(s) % bs) | |
# Pad | |
s = s + ('\x00' * padnr) | |
# Create equal size blocks | |
p = [s[i:i+bs] for i in range(0, len(s), bs)] | |
# Transform block items from string to bytes (RGB) | |
p = [struct.unpack('bbb', i[::-1]) for i in p] | |
# Create new image | |
img = Image.new('RGB', (len(p),1)) | |
pixels = img.load() | |
# Walk the coordinates | |
for x in range(img.size[0]): | |
for y in range(img.size[1]): | |
# Set the pixels to the ones we created in blocks | |
pixels[x,y] = p[x] | |
filename = '{0}.bmp'.format(path) | |
print(filename) | |
img.save(filename) | |
imagegen('powershell -command "gci"', '/tmp/data/file3') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment