Skip to content

Instantly share code, notes, and snippets.

@gowthamsadasivam
Forked from usernaamee/binfile2pycode.py
Created March 14, 2017 06:58
Show Gist options
  • Save gowthamsadasivam/9eac7414e589cd4140ada4096f61f125 to your computer and use it in GitHub Desktop.
Save gowthamsadasivam/9eac7414e589cd4140ada4096f61f125 to your computer and use it in GitHub Desktop.
Create self extracting python 2.6+ source code from any binary file
"""
:|
- Email provider doesn't allow me to send certain file types.
- I have python installed on all my machines.
- Inflates the file size by ~4.5X, still remains under 25M for me.
"""
from __future__ import print_function
import sys
inpfile = sys.argv[1]
data_ = open(inpfile, "rb").read()
byte_array_ = bytearray(data_)
print("byte_array_ = bytearray([" + ", ".join([str(b) for b in byte_array_]) + "])")
print("open('" + inpfile + "', 'wb').write(byte_array_)")
#~~ PS: Improvements and suggestions are welcome! ~~#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment