7
$\begingroup$

Computer graphics files are in Windows rendered by components such as the Graphics Device Interface and Direct2D.

Is it possible to create a graphic file that, besides displaying a graphic also utilizes custom code inside the graphic file?

With custom code I am referring to functionality such as:

  1. Incrementing a counter or date that is displayed on the graphic.
  2. Accessing a web URL to retrieve data that is displayed on the graphic.
$\endgroup$
  • 1
    $\begingroup$ Something slightly unrelated, what about images that are code? Look at the esolang piet which lets you program with images. And this video where an image is created and then built as an executable. $\endgroup$ – Soapy Oct 14 '15 at 15:40
  • $\begingroup$ Besides vulnerabilities in image decoders (e.g. GDI+) it is possible to embed code e.g. AFTER the EOF marker on a JPEG. In this case the custom code is in same image file but technically not part of the image. See example in this document re: "hammertoss" malware: www2.fireeye.com/rs/848-DID-242/images/rpt-apt29-hammertoss.pdf $\endgroup$ – user100487 Nov 18 '15 at 17:12
  • $\begingroup$ Related: security.stackexchange.com/questions/55061/… $\endgroup$ – user100487 Nov 18 '15 at 17:12
7
$\begingroup$

Common graphics formats such as JPEG, PNG and GIF are not designed to have any form of code inside them. They just store a compressed array of pixels—they can't generate anything on command or contact a web service, etc.

(There have occasionally been vulnerabilities discovered in image decoders, that would allow a maliciously constructed image to cause code execution when viewed, via a buffer overflow exploit or similar. But this is of course not part of the design of the format.)

Some vector graphics formats such as EPS and SVG actually do allow embedding code. However, being vector formats instead of bitmap ones, these formats often aren't supported by ordinary image viewers (although SVG is supported by browsers), and can't be edited in ordinary paint programs. One needs specialized vector graphics programs to work with them.

In order to generate an image that updates with new data, you could create a web service that regenerates the image on the server each time it's requested. However, if a client caches the resulting image rather than re-requesting it each time it's viewed, they would see old data.

$\endgroup$
0
$\begingroup$

I don't know if you would consider this to be a stretch for an answer to your question seeing as how I am a bit unsure how it was intended to be interpreted. That being considered, 2d barcodes can be graphics with which store code and interact with variable data elements defined throughout such symbologies as PDF417, DataMatrix, etc.

$\endgroup$
  • $\begingroup$ I believe the question is seeking embedding of code in the image file, rather than in the image itself. If you're uncertain what a question is looking for you can also comment on the question once you have sufficient reputation. $\endgroup$ – trichoplax Oct 13 '15 at 13:58
  • 1
    $\begingroup$ thanks user1846, I was looking to embed the code inside the image file, as trichoplax mentions. $\endgroup$ – coderworks Oct 13 '15 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.