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.

About these ads

About Tech B.

I am currently employed as a tech support rep for Frontier DSL internet and Dail-Up service. If you live on the East Coast and have Frontier or the old Verizon, you may have spoken with me at one point. I do side jobs programming and building things for people. I know Python better than any language in my toolbox. I can also develop Android Apps, which are Java based. Other languages include C , VB/VB.NET, some C#, PBASIC, Batch, Javascript, and some PHP. I love microcontrollers and interfacing with the outside world. I am currently working with Arduinos, which are amazing. Also I can work with the Basic Stamp family of microcontrollers; future development includes FPGA and embedded Linux. I was going to school, but have financial issues at the moment that are keeping me from the books. I plan on going back in the next couple semesters and finishing up my Associates in IT, then perusing a BS in computer science.
This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

4 Responses to Hide your ASSets the Python way

  1. CN says:

    How to read it back??

  2. dangayle says:

    How would you split that file back up again in Python? Can you even?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s