image28

Run a python program embedded in an image

May 6th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. // Image28:
  2. // Runs a python program that has been embedded into (a) png image(s).
  3. // Embed program with this code https://pastebin.com/dMUqPJJ5
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <SDL/SDL.h>
  9. #include <SDL/SDL_image.h>
  10. #include <python2.7/Python.h>
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     if ( argc < 2 )
  15.     {
  16.         printf("USAGE: %s [image file(s) to extract data from]\n",argv[0]);
  17.         return(1);
  18.     }else{
  19.         find(argc,argv);
  20.         return(0);
  21.     }
  22. }
  23.  
  24. int find(int count, char *files[])
  25. {
  26.     SDL_Surface *surface;
  27.     unsigned long filesize=0;
  28.     unsigned long pixel_count=0;
  29.     int start=0;
  30.     int d,e,l;
  31.     int inbyte=0;
  32.     unsigned char command[1024];
  33.     int lc=0;
  34.     Uint8 *pixel;
  35.     int temp=0;
  36.     long pos=0;
  37.     int first=1;
  38.     int png=0;
  39.  
  40.     for(d=2;d<count;d++)
  41.     {
  42.         if ( files[d][strlen(files[d])-3] == 'p' )
  43.         {  
  44.             png++;
  45.             if ( files[d][strlen(files[d])-3] == 'p' )
  46.             {
  47.                 png++;
  48.                 if ( files[d][strlen(files[d])-3] == 'p' )
  49.                 {
  50.                     png++;
  51.                 }
  52.             }
  53.         }
  54.  
  55.         if ( png != 3 )
  56.         {
  57.             strcpy(files[first],files[d]);
  58.         }
  59.            
  60.     }
  61.  
  62.     printf("%d %s\n",count,files[1]);
  63.  
  64.     Py_Initialize();
  65.     PySys_SetArgv(count,files);
  66.  
  67.     for(d=1;d<count;d++)
  68.     {
  69.         surface=IMG_Load(files[d]);
  70.         pixel_count=(surface->w*surface->h)*3;
  71.         pixel=(Uint8 *)surface->pixels;
  72.  
  73.         if( SDL_MUSTLOCK( surface ) )
  74.         { //Lock the surface
  75.             SDL_LockSurface( surface );
  76.         }
  77.  
  78.         if ( d == 1 )
  79.         {
  80.             start=32;
  81.             filesize=pixel[0]%2;
  82.  
  83.             for(e=1;e<32;e++)
  84.             {
  85.                 temp=0;
  86.                 temp=pixel[e]%2;
  87.                
  88.                 temp <<= e;
  89.                 filesize=filesize+temp;
  90.             }
  91.    
  92.             printf("FILESIZE: %d\n",filesize);
  93.         }else{
  94.             start=0;
  95.         }
  96.  
  97.         for(l=start;l<pixel_count;l=l+8)
  98.         {
  99.             if ( pos < filesize )
  100.             {
  101.                 inbyte=0;
  102.                 inbyte=pixel[l]%2;
  103.                 for(e=1;e<8;e++)
  104.                 {
  105.                     temp=0;
  106.                     temp=pixel[l+e]%2;
  107.                     temp <<= e;
  108.                     inbyte=inbyte+temp;
  109.  
  110.                 }
  111.  
  112.                 command[lc]=inbyte;
  113.  
  114.                 if ( command[lc] == '\n' )
  115.                 {
  116.                     command[lc+1]='\0';
  117.                     PyRun_SimpleString(command);
  118.                     lc=0;
  119.                 }else{
  120.                     lc++;
  121.                 }
  122.                 //fwrite(&inbyte,1,1,output);
  123.             }else{
  124.                 d=pixel_count;
  125.             }
  126.  
  127.             pos++;
  128.         }
  129.  
  130.  
  131.         if( SDL_MUSTLOCK( surface ) )
  132.         { //Lock the surface
  133.             SDL_UnlockSurface( surface );
  134.         }
  135.  
  136.         SDL_FreeSurface(surface);
  137.     }
  138.  
  139.     Py_Finalize();
  140.  
  141.     return(0);
  142. }
Add Comment
Please, Sign In to add comment