Skip to content

Instantly share code, notes, and snippets.

@usernaamee
Created March 13, 2017 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save usernaamee/58ca43190885a6aa8fbfa517b7c28291 to your computer and use it in GitHub Desktop.
Save usernaamee/58ca43190885a6aa8fbfa517b7c28291 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