2

I have a JPG image. I want to add/append a small piece of script(It can be of any language like PHP,Javascript,etc), but the image extension should not be changed. It must be jpg itself even after appending the script and I want to view the image in normal image viewers. Is it possible to achieve this?

2
  • 3
    A little background or the goal you are trying to reach with this construction would be appreciated.
    – Pavel
    Aug 13, 2014 at 11:13
  • @PavelPetrman its for some kind of tracking purpose:)
    – Mad Angle
    Aug 27, 2014 at 3:47

2 Answers 2

6

There's something you can do with the Windows copy facility and a RAR archive, which might suit what you're looking for. Get a JPG and a RAR and run the following command in the Windows command prompt:

copy /b image.jpg + archive.rar finalimage.jpg

This will produce a JPG image that can be opened using the WinRAR archiver to reveal files inside. It works because the RAR format is such that any program designed to handle the archives will scan through the headers of any binary file and only engage once it finds the "Rar!" header. As a result, you can place a "Rar!" header after another file (in this case a JPG, but it also works for MP3 files) without damaging the data of either file.

Under a unix operating system this can be achieved with the cat command as shown.

cat image.jpg archive.rar > finalimage.jpg

In regards to your initial question, I sincerely hope your intention was not to produce a JPG that would contain a script that would be executed by users upon viewing the image, or as some sort of 21st-century user-hostile copy-protection, as time has demonstrated again and again that such methods not only cause considerable backlash but often serve only to irritate the people who are giving you legitimate custom (with pirated versions of your material often having the offending protection either neutered or stripped out entirely).

10
  • +1 for the telling us how RAR works. Equivalent linux command is cat image.jpg archive.rar > finalimage.jpg
    – Kenneth L
    Aug 13, 2014 at 8:54
  • That simple, huh? It's a neat command either way, and chronically underused - I hope it's of some use to you.
    – seagull
    Aug 13, 2014 at 8:55
  • I have gone through this. online-tech-tips.com/computer-tips/hide-file-in-picture
    – Mad Angle
    Aug 13, 2014 at 9:14
  • @seagull, technically, concatenating files is the intended usage of cat, hence the name. The usage like cat file.txt | grep "hello" is rather crude and not true Unix style Aug 13, 2014 at 9:50
  • I'll have to disagree with your statement that the RAR format is such that all archive managers are capable of handling binary files with the RAR signature anywhere inside those files. That's simply not true. WinRAR and a few other archive managers are able to find and open the embedded archives only because they are programmed to do so. It has nothing to do with the RAR format.
    – Vinayak
    Aug 13, 2014 at 13:30
3

While you can hide something within a JPEG file, I'm afraid that adding a script that runs is not possible.

JPEG is a standard set out by Joint Photographic Experts Group, and these standards are now part of ISO standards. However in the standards there is no standard about "codes". That means most programs, if not all, would not understand the "code" you embedded in the JPEG file as it is no standard.

If you are trying to exploit security issues of certain JPEG reader, that's an other story... probably you will need a lot more research.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .