Kann imageMagick dazu gezwungen werden?
Absolut!
Beginnen wir damit, eine Programmdatei mit einer Größe von 320k zu erzeugen.
dd if=/dev/urandom of=myProgram.blob bs=1000 count=320
YMMV
Grau Ansatz. Ein 8-Bit-Bild mit einem Kanal.
cat myProgram.blob | \
convert -size 500x640 -depth 8 -format GRAY GRAY:- gray_output.png
Farb Ansatz. Dreikanaliges 8-Bit-Bild.
cat myProgram.blob | \
convert -size 500x213 -depth 8 -format RGB RGB:- rgb_output.png
Sie werden ein bisschen Mathe tun müssen, um die Bildgrößen zu bestimmen, aber das ist einfach.
total_bytes = [number of channels] * width * height
Ich weiß, dass die Daten wie nichts, aber Lärm aussehen wird, aber das ist OK. Ich möchte nur sagen können:
"Das ist es - diese Pixel repräsentieren eindeutig jedes Byte in dieser Anwendung!"
Vor einem Jahr hatte ich das gleiche Problem. Ich brauchte eine schnelle visuelle Prüfsumme, um "auf einen Blick" festzustellen, ob sich die Daten-Blobs unterschieden.
Und so habe ich vizsum erstellt. Auf keinen Fall verlustfrei oder mathematisch sicher, aber schöner auf den Augen.
cat myProgram.blob | vizsum -sha1 -bilinear visual_checksum.png
aktualisieren nur zum Spaß.
Hier ist ein schnelles C-Programm mit dem MagickWand API
// program2img.c
#include <stdio.h>
#include <math.h>
#include <wand/MagickWand.h> // Or <MagickWand/MagickWand.h> if using IM 7.x.x
int main(int argc, const char * argv[]) {
FILE
* fd;
const char
* input,
* output;
unsigned char
* buffer;
long
program_size,
program_area,
program_width,
program_width_data,
program_height,
col,
row;
MagickBooleanType ok;
// Collect input/output
if (argc != 3) {
fprintf(stderr, "Usage: %s <input> <output>\n", argv[0]);
return 1;
}
input = argv[1];
output = argv[2];
// Open input for reading
fd = fopen(argv[1], "rb");
if (fd == NULL) {
fprintf(stderr, "Unable to open `%s'\n", argv[1]);
return 1;
}
// Get size of input
fseek(fd, 0L, SEEK_END);
program_size = ftell(fd);
fseek(fd, 0L, SEEK_SET);
// Roughly calculate size of output image.
program_area = program_size/3;
program_width = sqrtl(program_area);
if (program_width < 1) {
fprintf(stderr, "Unable to generate image width\n");
return 1;
}
program_width_data = program_width * 3;
program_height = program_area/program_width + 1;
if (program_height < 1) {
fprintf(stderr, "Unable to generate image width\n");
return 1;
}
// Boot ImageMagick
MagickWandGenesis();
PixelWand * color;
MagickWand * wand;
color = NewPixelWand();
wand = NewMagickWand();
PixelSetColor(color, "BLACK");
MagickNewImage(wand, program_width, program_height, color);
color = DestroyPixelWand(color);
buffer = malloc(program_width_data);
// Iterate over input and build image line-by-line
for (row = 0; row < program_height; ++row) {
col = fread(buffer, 1, program_width_data, fd);
// Add padding (might need to double check this logic)
while (col < program_width_data) {
buffer[col++] = '\0';
}
MagickImportImagePixels(wand,
0, row,
program_width, 1,
"RGB", CharPixel, buffer);
}
fclose(fd);
// Save image output.
ok = MagickWriteImage(wand, output);
if (ok == MagickFalse) {
fprintf(stderr, "Unable to save output `%s'\n", output);
}
wand = DestroyMagickWand(wand);
MagickWandTerminus();
return 0;
}
den mit
clang `MagickWand-config --cflags --libs` program2img.c -o program2img
kompiliert werden kann und
./program2img mySmallProgram output.png
Bild Kann Magick dazu gezwungen werden? –