Skip to content

Instantly share code, notes, and snippets.

@tmr232
Last active January 9, 2021 00:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmr232/8fc9279c1aac47762c23 to your computer and use it in GitHub Desktop.
Save tmr232/8fc9279c1aac47762c23 to your computer and use it in GitHub Desktop.
Bitmapper - Visual Reverse Engineering
"""Bitmapper
Usage:
bitmapper.py <input> <output> [<width>]
Options:
-h --help Show this screen.
<input> The input binary file.
<output> The output bitmap.
<width> The width of the bitmap in pixels. Optional.
"""
import docopt
import struct
DEFAULT_WIDTH = 1000
HEADER = ("42 4D 36 E0 2E 00 00 00 00 00 36 00 00 00 28 00"
"00 00 E8 03 00 00 00 04 00 00 01 00 20 00 00 00"
"00 00 00 E0 2E 00 00 00 00 00 00 00 00 00 00 00"
"00 00 00 00 00 00").replace(" ", "").decode("hex")
def make_bitmap(data, width=1000):
size = len(data)
height = len(data) / 4 / width
header = (HEADER[:2] +
struct.pack("<I", size) +
HEADER[6:0x12] +
struct.pack("<I", width) +
struct.pack("<I", height) +
HEADER[0x1A:0x22] +
struct.pack("<I", size - 54) +
HEADER[0x26:])
return header + data
if __name__ == '__main__':
arguments = docopt.docopt(__doc__)
input_path = arguments["<input>"]
output_path = arguments["<output>"]
try:
width = int(arguments["<width>"])
except (ValueError, TypeError):
width = DEFAULT_WIDTH
with open(input_path, "rb") as f:
data = f.read()
bitmap = make_bitmap(data, width)
with open(output_path, "wb") as f:
f.write(bitmap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment