Hide your ASSets the Python way

Some of you may have seen the “trick” of using the command prompt to hide archives in images. Example: “C:>copy /b image1.jpg + stuff.zip newimage.jpg” This will hide stuff.zip in the picture image.jpg and output the merged file as newimage.jpg

As far as I know, this only works with jpeg’s. That’s cool and all, but how does it do that? And how can I do the same with python?

Well, it works by opening each file as it’s binary state and merges the two binaries into one. To view the image, just open it like normal. To view the archive, open it with an archive viewer like 7zip.

Now that we know how it works, lets try and do the same with python.

#open the image a=append, b=open as binary
image = open("test.jpg", "ab")

#open the archive as a binary
archive = open("test.zip","rb")

#write the archive data after a newline
#to our image
image.write("\n"+archive.read())

#close handles
image.close()
archive.close()

As you can see, it only took 5 lines of code. You can view the image as a regular image, or open as a zip file. Alliteratively, you could os.popen() or os.system() with the cmd version as well, but I like to do things the python way.

Short, sweet, and to the point.

Some of you may have seen the “trick” of using the command prompt to hide archives in images. Example: “C:>copy /b image1.jpg + stuff.zip newimage.jpg” This will hide stuff.zip in the picture image.jpg and output the merged file as newimage.jpg

As far as I know, this only works with jpeg’s. That’s cool and all, but how does it do that? And how can I do the same with python?
Well, it works by opening each file as it’s binary state and merges the two binaries into one. To view the image, just open it like normal. To view the archive, open it with an archive viewer like 7zip.

Now that we know how it works, lets try and do the same with python.

#open the image a=append, b=open as binary
image = open(test.jpg";, "ab")
#open the archive as a binary
archive = open(test.zip", "rb")
#write the archive data after a newline
#to our image
image.write("\n"+archive.read())
#close handles
image.close()
archive.close()

As you can see, it only took 5 lines of code. You can view the image as a regular image, or open as a zip file. Alliteratively, you could os.popen() or os.system() with the cmd version as well, but I like to do things the python way.

Short, sweet, and to the point.

EDIT:
Here is how to get the data back out of the image.

import os

#open the image a=append, b=open as binary
imgsize = os.stat("test.jpg").st_size
image = open("test.jpg", "ab")

#open the archive as a binary
archsize = os.stat("test.zip").st_size
archive = open("test.zip","rb")

#write the archive data after a newline
#to our image
image.write("\n"+archive.read())

#close handles
image.close()
archive.close()

#new zip
narchive = open("test2.zip", "wb")

#old image
old = open("test.jpg", "rb")
oldr = old.read()

#get and write appended data
data = oldr[-archsize:]
narchive.write(data)
narchive.close()
old.close()

You can actually pop or cut the data from the file, but this is just a demo.