开发者

How would I encode a binary file to JPG format?

I would like to be able to take a stream of 1's and 0's and convert it to a format that jpg can read, I.E. suppose I wrote a program and compiled and got an exe, then took and ran the 1's and 0's from the exe through said program, it would produce a .jpg. Any tips on what I need to do? I am hoping it's not as difficult as I'm suspecting it is.

Update: Suppose you took any old image, and brought it down to the (I suppose) Raw format, just one's and zero's, now suppose you took those 1's and 0's and somehow decoded them what kind of program would you ge开发者_StackOverflowt (obviously not a functioning one), but now I was thinking suppose we went the other way and took a .exe and lined all the 1's and 0's in some format that an "image" looks like, is it possible to see a picture, that's what I would like to discover. (I hope that explains what I'm interested in), so no the format doens't really matter, it could be bmp for all I care, just I want to see if there is in any way an image in a program that is distinguishable in a program.


Are you talking about steganography? This would be taking some hidden message (could be an executable file) and hiding it in an image file. Obviously, the image file will bloat up a bit, but I think this is what you're talking about. The Wikipedia page has a few tools that are out there like StegFS and or MP3Stego.

Update

Upon re-reading your question, do you just want something that'll be a two color image with one color representing 1s and another being 0s? So the binary sequence 0110 1101 1010 1101 would produce an image like:

wbbw
bbwb
bwbw
bbwb


Well, the "right" approach would be to use a JPEG encoding library with your favorite programming language.

If you want to get started generating JPEGs right away, one option you have is to have your program encode the image in PPM (a simple text-based bitmap image format), then use the cjpeg utility to convert it to JPEG. Example:

foo.exe > out.ppm

Now, out.ppm (stolen from Wikipedia) contains:

P3
# The P3 means colors are in ASCII, then 3 columns and 2 rows, then 255 for max color, then RGB triplets
3 2
255
255   0   0     0 255   0     0   0 255
255 255   0   255 255 255     0   0   0

With this, you can run:

cjpeg -outfile out.jpg out.ppm

This is by no means a fast or robust way to generate JPEGs, but it can help you get started quickly.


This kinda sounds silly, but by changing the extension to .raw, the file is automatically opened in photoshop (or Gimp in my case) and you can see what the "bit patterns" look like. That is kinda what I was aiming for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜