I woke up one day saying “Hey, wouldn’t it be cool to convert a software to an image?”
When you google “convert files to bmp”, you’d either get links that converts an image from one format to another, or if you’re lucky, how to inject a malicious software (*COUGH*VIRUS*COUGH*BACKDOOR*COUGH).
I remember there was a post in my blog made by one of the ex-writers; SIGTERMer. Building an image out of a few MB-sized OS.
Because I couldn’t find a program that does that. I figured I’d do that myself.
So here it is, I made a C# project that can convert any file from its binary values to an BMP image representation of it.
Here’s how it happens:
- Read file’s data in Binary.
- Do some math magic to figure out the width and height
- Gets file length.
- Pad it with FF values (Or 255) until it has a square root has an integer value (No fractions).
- Square root the total size to get the width and height.
- Convert Binary values to Integers (As in, from 0 to 255).
- Do for-loop for each dimension (Which means two), have the height’s width divided by 3, because we’re using three bytes to represent a color (Each byte for a color in RGB mode).
- Save the result in BMP
I really don’t know how to explain what I wrote up there, I tried my best (And my English is bananas right now because I just woke up, wife forced me… Don’t ask).
If you have Visual Studio 2015 (Could work on earlier releases, but that’s what I used for this project), you can check my Github to download and compile it.
The image in this post is what “explorer.exe” looks like. I’ll have to refine and comment my code. But for the time being, I’m too excited to alter anything in my code. I’ll get to it eventually, but not now.
If you’re feeling artistic in a glitchy way, I think this will be very useful for you.
Cool project. It’s nice to see you actually hosting source code in a public repository instead of just throwing up a link to an opaque binary. I don’t know C# nor do I have VS installed so I’ll just admire the post’s header image instead; for some reason, visual studio refuses to install on my windows 7 work machine, requires a service pack my IT dept. refuses to install, older versions won’t work.
I’ll probably sound like a moron, but that header image is cropped, right? Also, either you mistook columns for rows and rows for columns. or windows has a really funky way of storing executables.
Good luck with your IT department. It doesn’t hurt to install a VM in your box and have a Windows machine there to boot up every once in a while.
For the image, its not cropped. Maybe it looks cropped, but its not.
At my first attempts, I used to export a picture with 1:1 ratio. That doesn’t look so nice because only the top 1/3 of the picture is displayable while the rest is white (Since I’m padding everything in white).
My second (And last, so far) attempt was shortening the row loop by third to appear like this.
Mistaking columns and rows is a mistake I always make, for some odd reason. Its like saying Banana; I sometimes add another na or drop the last na.
Obligatory video: https://www.youtube.com/watch?v=NtWacGVBdD8
I actually created my own blog and own captcha writing numbers and converting that into jpg and own spam system using PHP. This was about 7 years ago. I read your blog and thought to share. Keep up your work.
i like this theme better tbqh
you don’t have to have a square image!!, you can have a rectangular so you don’t have to search for a square root.
I don’t like rectangles. Plus, you’d still face the same issue if the file length is odd <_<