Decryption of .png and .jpg files

I am trying to change the graphic resources of the software that I use (for aesthetic puroposess, I think it is difficult to do something harmful for the graphic resources), but the developer has encrypted them. I am not sure why he decided to do this, since I used and modified a bunch of similar programs, and the developers of them were not worried (since I see no reason why encryption of these assets would be necessary).

Anyway, here are examples of these encrypted graphic assets:

http://www.mediafire.com/view/sx2yc0w5wkr9m2h/avatars_50-alpha.jpg http://www.mediafire.com/download/i4fc52438hkp55l/avatars_80.png

Is there any way to decrypt them? If so, how do I do this?

+1
source share
2 answers

The β€œCF10” header appears to be a private signature, meaning that the rest of the file is β€œencoded”. This is a very simple XOR encoding: xor 8Dh was the first value I tried, and I also got it for the first time. The rationale for the first value is that the 8D value is very common in the first 100 bytes or so, where there can usually be many zeros.

The "decryption" is thus very simple: if the file starts with four bytes of CF10 , delete them and apply xor 8Dh to the rest of the file. Decoding the files shows that the first "JPG" is actually a small PNG image (and not very interesting to download), the second is a PNG file:

decoded image

The file extension may or may not be the original file extension; one sample called ".jpg" is actually also a PNG file, as can be seen from its header signature.

The next fast and dirty C source will decode the images. The same program can be adjusted in the same way as for encoding them, since the xor operation is exactly the same. The only thing needed is to add a bit of logical flow:

  • read the first 4 bytes (maximum) of the input file and test if this forms a string CF10
  • if not, the file is not encoded:
    a. write CF10 to the output file
    b. encode an image using xor 8Dh for each byte
  • if so,
    b. decode the image using xor 8Dh for each byte.

As you can see, there is no β€œ3a,” and both steps of β€œb” are the same.

 #include <stdio.h> #include <string.h> #ifndef MAX_PATH #define MAX_PATH 256 #endif #define INPUTPATH "c:\\documents" #define OUTPUTPATH "" int main (int argc, char **argv) { FILE *inp, *outp; int i, encode_flag = 0; char filename_buffer[MAX_PATH]; char sig[] = "CF10", *ptr; if (argc != 3) { printf ("usage: decode [input] [output]\n"); return -1; } filename_buffer[0] = 0; if (!strchr(argv[1], '/') && !strchr(argv[1], 92) && !strchr(argv[1], ':')) strcpy (filename_buffer, INPUTPATH); strcat (filename_buffer, argv[1]); inp = fopen (filename_buffer, "rb"); if (inp == NULL) { printf ("bad input file '%s'\n", filename_buffer); return -2; } ptr = sig; while (*ptr) { i = fgetc (inp); if (*ptr != i) { encode_flag = 1; break; } ptr++; } if (encode_flag) { /* rewind file because we already read some bytes */ fseek (inp, 0, SEEK_SET); printf ("encoding input file: '%s'\n", filename_buffer); } else printf ("decoding input file: '%s'\n", filename_buffer); filename_buffer[0] = 0; if (!strchr(argv[2], '/') && !strchr(argv[2], 92) && !strchr(argv[2], ':')) strcpy (filename_buffer, OUTPUTPATH); strcat (filename_buffer, argv[2]); outp = fopen (filename_buffer, "wb"); if (outp == NULL) { printf ("bad output file '%s'\n", filename_buffer); return -2; } printf ("output file: '%s'\n", filename_buffer); if (encode_flag) fwrite (sig, 1, 4, outp); do { i = fgetc(inp); if (i != EOF) fputc (i ^ 0x8d, outp); } while (i != EOF); fclose (inp); fclose (outp); printf ("all done. bye bye\n"); return 0; } 
+6
source

Ok, so when it comes to the practical use of the code provided by @Jongware, which was obscure to me, I figured it out with some help :)

  • I compiled the code using Visual Studio (you can find manuals on how to do this, basically create a new Visual C ++ project, and in Project β†’ Project Propeties select C / C ++ β†’ All options and Compile as C Code ( / TC)).
  • Then I opened the program at the command line using the parameter "program encrypted_file decrypted_file".

Thanks so much for helping Jongware!

0
source

Source: https://habr.com/ru/post/1277008/


All Articles