How did this person encode "Hello World" with Microsoft Paint?

I just saw this over the past few days and can't figure out how this works. The video I'm talking about is here :

This is the highest answer from this stack overflow question: Why was this program rejected by three compilers?

How can this bitmap show a C ++ program for "Hello World"?

+81
c ++ c paint
Apr 7 2018-11-11T00:
source share
3 answers

A BMP image (DIB) consists of a header followed by uncompressed data of color 1 (for 24 images in bpp format, these are 3 bytes per pixel, stored in line order and in 4-byte increments).

Bytes for color data are used to represent colors (that is, none of them are “fixed” in file format 2 , they all come from the color of each pixel), and there is a perfect 1: 1 correspondence between pixel colors and bytes recorded in the file ; Thus, using perfectly selected colors, you can actually write whatever you want in the file (except for the header).

When you open the generated file in notepad, the color data will be displayed as text; you can still clearly see from the header (the part from BM to the beginning of the text), which is determined by the file format.

In my opinion, this video was made as follows: first, the author calculated the size needed for the raster image, and created a DIB file with the correct size, filled with color, which expands to a simple template (for example, all bytes 65 => 'A' ); then replaced the template with a “payload” code, as shown in the video.

Please note that this cannot be done manually using notepad - with a color selection dialog, ASCII table and basic knowledge of the DIB format, this can be done, but it will be much slower, and the error is -prone.

More on DIB format




  • There are compressed DLEs with RLE, but in this case, uncompressed bitmaps are used (and they are used very rarely anyway).
  • With the exception of the step, this was avoided using strings of 4 bytes.
+46
Apr 07 '11 at 23:16
source share

I assume that you mean the answer to one of the questions from April.

I assume that each pixel has a binary representation for it. And that every character in the source code has a binary representation for it.

The person who created the program had to develop a color for each pixel, which would have a binary representation corresponding to each character.

+16
Apr 7 2018-11-11T00:
source share

From a theoretical point of view of computer science, it would be interesting to ask if each program can be written in such a way that, considering it as a raster image, you really see the source code that does the same. If you are seriously interested in such results, read for example. o Klein fixed point theorem .

A program as an image can also be seen as a form of code obfuscation. Not that it was especially practical ...

+5
09 Oct '13 at 19:25
source share



All Articles