void VideoEncoder::startFrameLoop() { workingThread=true; while(workingThread) { if(isMemoryReadable()&&streamServer!=NULL) { int copySize=0; int height=0; int width=0; int bpp=0; memcpy((void *)©Size,lpvMem+(SHAREDMEMSIZE-RESERVEDMEMORY)/8,sizeof(int)); memcpy((void *)&height,lpvMem+(SHAREDMEMSIZE-RESERVEDMEMORY)/8+sizeof(height),sizeof(height)); memcpy((void *)&width,lpvMem+(SHAREDMEMSIZE-RESERVEDMEMORY)/8+sizeof(height)*2,sizeof(width)); memcpy((void *)&bpp,lpvMem+(SHAREDMEMSIZE-RESERVEDMEMORY)/8+sizeof(height)*3,sizeof(bpp)); printf("%d bytes height:%d width:%d bpp:%d \n",copySize,height,width,bpp); if(bpp!=4) { printf("Encoder cannot handle this format\n"); workingThread=false; return; } encodingPerformanceTime=clock(); //===============RGB32toYUV420P=================== if(lastWidth!=width||lastHeight!=height) { printf("Swscale Rebuilt\n"); lastWidth=width; lastHeight=height; this->removeSwscale(); if(!this->setupSwscale(width,height)) { printf("Swscale failed\n"); workingThread=false; return; } } if(picture==NULL) { picture=alloc_picture(PIX_FMT_YUV420P, RWIDTH, RHEIGHT); } uint8_t *rgb_src[3]={lpvMem,NULL,NULL}; int rgb_stride[3]={4*width, 0, 0}; sws_scale(img_convert_ctx, rgb_src, rgb_stride, 0, height, picture->data, picture->linesize); //=============Write encoded frame and send============================= /*pgm_save(picture->data[0], picture->linesize[0], c->width, c->height, "c:/2.pgm");*/ int ret,getOutput; av_init_packet(&pkt); pkt.data = NULL; // packet data will be allocated by the encoder pkt.size = 0; ret = avcodec_encode_video2(c, &pkt, picture,&getOutput); if (ret < 0) { printf("Error encoding frame!Found A way to deal!\n"); workingThread=false; return; } if(getOutput) { printf("Encoding perfomance:%f\n",(float)1000/(clock()-encodingPerformanceTime)); streamServer->sendPacket((char*)(pkt.data),pkt.size); av_free_packet(&pkt); } //========================================== // setMemoryWritable(); } else { //printf("Try to see if i sleep too much"); Sleep(1000/MAXFPS); } } }
UINT32 IATAutoFix(DWORD pid, DWORD_PTR oep, WCHAR *outputFile, WCHAR * cur_path, WCHAR * tmp_dump) { Log::getInstance()->initLogPath(cur_path);//Initialize the log File NEED TO BE BEFORE ANY INFO(),WARN(),ERROR() PRINT("\n\n-------------------------------------------------------------------------------------------------------"); PRINT("------------------------------------ IAT Fixing at %08x -------------------------------------",oep); PRINT("-------------------------------------------------------------------------------------------------------"); DWORD_PTR iatStart = 0; DWORD iatSize = 0; WCHAR originalExe[MAX_PATH]; // Path of the original PE which as launched the current process //getting the Base Address DWORD_PTR hMod = GetExeModuleBase(pid); if(!hMod){ INFO("Can't find PID"); } INFO("GetExeModuleBase %X", hMod); //Dumping Process BOOL success = GetFilePathFromPID(pid,originalExe); if(!success){ INFO("Error in getting original Path from Pid: %d",pid); return SCYLLA_ERROR_FILE_FROM_PID; } INFO("Original Exe Path: %S",originalExe); success = ScyllaDumpProcessW(pid,originalExe,hMod,oep,tmp_dump); if(!success){ INFO("[SCYLLA DUMP] Error Dumping Pid: %d, FileToDump: %S, Hmod: %X, oep: %X, output: %S ",pid,originalExe,hMod,oep,tmp_dump); return SCYLLA_ERROR_DUMP; } INFO("[SCYLLA DUMP] Successfully dumped Pid: %d, FileToDump: %S, Hmod: %X, oep: %X, output: %S ",pid,originalExe,hMod,oep,tmp_dump); //DebugBreak(); //Searching the IAT int error = ScyllaIatSearch(pid, &iatStart, &iatSize, hMod + 0x00001028, TRUE); //check if ScyllaIATSearch failed and if the result IAT address is readable if(error || !isMemoryReadable((void *) iatStart,iatSize)){ /*Display why the Scylla IAT Search failed: - error in IAT search - address found not readable */ if(error){ ERRORE("[SCYLLA ADVANCED SEARCH] error %d ",error); } else{ ERRORE("[SCYLLA ADVANCED SEARCH] IAT address not readable/mapped iat_start : %08x\t iat_size : %08x\t ",iatStart,iatSize); } INFO("[SCYLLA SEARCH] Trying basic IAT search"); //Trying Basic IAT search int error2 = ScyllaIatSearch(pid, &iatStart, &iatSize, hMod + 0x00001028, FALSE); if(error2 || !isMemoryReadable((void *) iatStart,iatSize)){ /*Display why the Scylla IAT Search failed: - error in IAT search - address found not readable */ if(error2){ ERRORE("[SCYLLA BASIC SEARCH] error %d ",error2); } else{ ERRORE("[SCYLLA BASIC SEARCH] IAT address not readable/mapped iat_start : %08x\t iat_size : %08x\t ",iatStart,iatSize); } return SCYLLA_ERROR_IAT_NOT_FOUND; } } INFO("[SCYLLA SEARCH] iat_start : %08x\t iat_size : %08x\t pid : %d", iatStart,iatSize,pid,outputFile); //Fixing the IAT error = ScyllaIatFixAutoW(iatStart,iatSize,pid,tmp_dump,outputFile,1,oep,1); if(error){ INFO("[SCYLLA FIX] error %d",error); return SCYLLA_ERROR_IAT_NOT_FIXED; } //Removing the correct dump from the not working directory _wremove(tmp_dump); INFO("[SCYLLA FIX] Success fixed file at %S",outputFile); return SCYLLA_SUCCESS_FIX; }