#include <stdio.h>
#include <stdlib.h>
#include <png.h>

//unsigned int code[]={
//    0x001d202a, 0x00042140, 0x00042022, 0x009d2020, 0x001d282a, 0x000823cc, 0x00000000, 0x00022021, 0x001d282a, 0x00053020, 0x00063080, 0x00c53020, 0x000529c0, 0x00a62820, 0x00052900, 0x00a62820, 0x00052900, 0x001d302a, 0x00c63020, 0x00a62820, 0x00a62820, 0x00a62820, 0x00052b00, 0x001d302a, 0x00063400, 0x0008244c, 0x00000000, 0x000831cc, 0x00000000, 0x0008330c, 0x00000000, 0x001d282a, 0x00053020, 0x00063080, 0x00c53020, 0x000529c0, 0x00a62820, 0x00052900, 0x00a62820, 0x00052900, 0x001d302a, 0x00c63020, 0x00a62820, 0x00a62820, 0x00a62820, 0x00052b00, 0x00a00008, 0x00000000
//};


#include "shellcode.h"



int main() {
  FILE *f;
  png_structp png_ptr;
  png_infop info_ptr;
  png_byte **row_pointers;
  int width=480, height=272,i,x,y;
  int num;


  row_pointers=calloc(height,4);
  if (!row_pointers) { perror("row_pointers"); return -10; }
  for (y=0; y<height; y++) {
	row_pointers[y]=calloc(width,4*3);
	if (!row_pointers[y]) { perror("row_pointer"); return -11; }
  }

  x=334; y=235;
  num=sizeof(code)>>2;
  for (i=0; i<num; i++) {
	unsigned int instr=code[i];
	row_pointers[y][x*3+2]=instr>>16;
	row_pointers[y][x*3+1]=instr>>8;
	row_pointers[y][x*3+0]=instr;
	if (++x == width) { x=0; y++; }
  }

  f=fopen("loader2.png","w");
  if (!f) { perror("fopen"); return -1; }
  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  if (!png_ptr) return -2;
  info_ptr = png_create_info_struct(png_ptr);
  if (!info_ptr) return -3;
  if (setjmp(png_jmpbuf(png_ptr))) {
     png_destroy_write_struct(&png_ptr, &info_ptr);
     fclose(f);
     return -4;
  }
  png_init_io(png_ptr, f);
  png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
	PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
  png_set_rows(png_ptr,info_ptr,row_pointers);
  png_write_png(png_ptr,info_ptr,PNG_TRANSFORM_IDENTITY,NULL);
  png_write_end(png_ptr,info_ptr);
  png_destroy_write_struct(&png_ptr,&info_ptr);
  fclose(f);
  return 0;
}

