diff --git a/_includes/footer.html b/_includes/footer.html index 661fb93..4b99830 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -82,4 +82,7 @@ particlesJS.load('particles-js', '/assets/js/particles.json', function () { console.log('callback - particles.js config loaded'); }); - \ No newline at end of file + + + + \ No newline at end of file diff --git a/_posts/2019-09-11-Buildingimgfrombin.md b/_posts/2019-09-11-Buildingimgfrombin.md new file mode 100644 index 0000000..bf38180 --- /dev/null +++ b/_posts/2019-09-11-Buildingimgfrombin.md @@ -0,0 +1,54 @@ +--- +layout: post +title: "Building images from binary data" +description: "Simple, yet fun" +date: 2019-09-11 12:41:00 +categories: python images +--- + +During a computer science class today, we were talking about embedding code and metadata in *jpg* and *bmp* files. @SilasBartha was showing off a program he wrote that watched a directory for new image files, and would display them on a canvas. He then showed us a special image. In this image, he had injected some metadata into the last few pixels, which were not rendered, but told his program where to position the image on the canvas, and it's size. + +This demo got @hyperliskdev and I thinking about what else we can do with image data. After some talk, the idea of converting application binaries to images came up. I had seen a blog post about visually decoding [OOK data](https://en.wikipedia.org/wiki/On%E2%80%93off_keying) by converting an [IQ capture](http://www.ni.com/tutorial/4805/en/) to an image. With a little adaptation, I did the same for a few binaries on my laptop. + + + +
+ +## Program design +Like all ideas I have, I wrote some code to test this idea out. Above is a small sample of the interesting designs found in the [gimp]() binary. The goals for this script were to: + + - Accept any file of any type or size + - Allow the user to select the file dimensions + - Generate an image + - Write the data in a common image format + +If you would like to see how the code works, read "*check out the script*". + +## A note on data wrapping +By using a [generator](https://wiki.python.org/moin/Generators), and the [range function](https://docs.python.org/3/library/functions.html#func-range)'s 3rd argument, any list can be easily split into a 2d list at a set interval. + +```python +# Assuming l is a list of data, and n is an int that denotes the desired split location +for i in range(0, len(l), n): + yield l[i:i + n] +``` + +### Binaries have a habit of not being rectangular +Unlike photos, binaries are not generated from rectangular image sensors, but instead from compilers and assemblers (and sometimes hand-written binary). These do not generate perfect rectangles. Due to this, my script simply removes the last line from the image to "reshape" it. I may end up adding a small piece of code to pad the final line instead of stripping it in the future. + +## Other file types +I also looked at other file types. Binaries are very interesting because they follow very strict ordering rules. I was hoping that a `wav` file would do something similar, but that does not appear to be the case. This is the most interesting pattern I could find in a `wav` file: + +I present: "Parts of @GIMP_Official's binary, represented as a bitmap" pic.twitter.com/iLljdE4nlK
— Evan Pratten (@ewpratten) September 11, 2019
+ +Back to executable data, these are small segments of a `dll` file: + + + + + +## Check out the script +This script is hosted [on my GitHub account](https://github.com/Ewpratten/binmap) as a standalone file. Any version of python3 should work, but the following libraries are needed: + + - Pillow + - Numpy \ No newline at end of file diff --git a/_site/about/index.html b/_site/about/index.html index 0b4b2f1..d13407f 100644 --- a/_site/about/index.html +++ b/_site/about/index.html @@ -204,7 +204,7 @@ sub rsa4096/0xA61A2F1676E35144 2019-08-11 [] [expires: 2025-08-09] Site design by: Evan Pratten | - This site was last updated at: 2019-09-11 11:41:26 -0400 + This site was last updated at: 2019-09-11 17:12:28 -0400 @@ -283,6 +283,9 @@ sub rsa4096/0xA61A2F1676E35144 2019-08-11 [] [expires: 2025-08-09] }); + + +Following up my previous post with a tiny segment of an audio file. This one is little less interesting pic.twitter.com/u9EFloxnK5
— Evan Pratten (@ewpratten) September 11, 2019