mfxStatus WriteRawFrame(mfxFrameSurface1* pSurface, FILE* fSink) { mfxFrameInfo* pInfo = &pSurface->Info; mfxFrameData* pData = &pSurface->Data; mfxU32 i, j, h, w; mfxStatus sts = MFX_ERR_NONE; for (i = 0; i < pInfo->CropH; i++) sts = WriteSection(pData->Y, 1, pInfo->CropW, pInfo, pData, i, 0, fSink); h = pInfo->CropH / 2; w = pInfo->CropW; for (i = 0; i < h; i++) for (j = 0; j < w; j += 2) sts = WriteSection(pData->UV, 2, 1, pInfo, pData, i, j, fSink); for (i = 0; i < h; i++) for (j = 1; j < w; j += 2) sts = WriteSection(pData->UV, 2, 1, pInfo, pData, i, j, fSink); return sts; }
bool CBratSettings::SaveConfig() { return base_t::SaveConfig() && WriteSection( GROUP_COMMON, k_v( ENTRY_LAST_DATA_PATH, m_lastDataPath ), k_v( ENTRY_LAST_PAGE_REACHED, m_lastPageReached ), k_v( ENTRY_ADVANCED_OPERATIONS, mAdvancedOperations ), k_v( ENTRY_LOAD_WKSPC_AT_STARTUP, mLoadLastWorkspaceAtStartUp ), k_v( ENTRY_MAIN_LAYER_BASE_TYPE, (int)mMainLayerBaseType ), k_v( ENTRY_VIEWS_LAYER_BASE_TYPE, (int)mViewsLayerBaseType ), k_v( ENTRY_VECTOR_SIMPLIFY_METHOD, mVectorSimplifyMethod ), k_v( ENTRY_DESKTOP_MANAGER_SDI, mDesktopManagerSdi ), k_v( ENTRY_CHECK_OPENGL, mCheckOpenGL ) ) && WriteValues( GROUP_WKS, { { ENTRY_LAST, m_lastWksPath }, } ) && WriteValues( GROUP_COLORTABLE, { { ENTRY_LAST, m_lastColorTable }, } ) && SaveConfigSelectionCriteria() && SavePaths(); }
mfxStatus WriteRawFrame( mfxFrameSurface1 *pSurface, FILE* fSink, const Regions& regionsOfInterest) { const Regions& roi = regionsOfInterest; mfxFrameInfo *pInfo = &pSurface->Info; mfxFrameData *pData = &pSurface->Data; mfxU32 i, j, h, w; mfxStatus sts = MFX_ERR_NONE; mfxU32 Green = 0x00; for (i = 0; i < pInfo->CropH; i++) sts = WriteSection(pData->Y, 1, pInfo->CropW, pInfo, pData, i, 0, fSink); h = pInfo->CropH / 2; w = pInfo->CropW; for (i = 0; i < h; i++) for (j = 0; j < w; j += 2){ /*std::pair<bool, std::string> inside = insideAny(roi,i,j); if( inside.first ) { UVPixel uv( pInfo, pData, i, j ); fprintf(fdebug, inside.second.c_str() ); uv.fprint(fdebug); }*/ if( borderUAny(roi,i,j) ) fwrite(&Green, 1, 1, fSink); else sts = WriteSection(pData->UV, 2, 1, pInfo, pData, i, j, fSink); } for (i = 0; i < h; i++) for (j = 1; j < w; j += 2){ if( borderVAny(roi,i,j)) fwrite(&Green, 1, 1, fSink); else sts = WriteSection(pData->UV, 2, 1, pInfo, pData, i, j, fSink); } return sts; }
bool CBratSettings::SavePaths() { return WriteSection( GROUP_PATHS, k_v( ENTRY_USER_DATA_PATH, mBratPaths.UserDataDirectory() ), k_v( ENTRY_WORKSPACES_DIR, mBratPaths.WorkspacesDirectory() ), k_v( ENTRY_URL_RASTER_LAYER_PATH, mBratPaths.URLRasterLayerPath() ), k_v( ENTRY_PORTABLE_PATHS, mBratPaths.UsePortablePaths() ) ); }
bool Permutator::WriteModifiedFile() { try { if (elfMode) outputFile.open("permutatedFile", std::ios::out | std::ios::binary); else outputFile.open("permutatedFile.exe", std::ios::out | std::ios::binary); } catch (std::fstream::failure e) { std::cerr << "WriteModifiedFile: Error while opening stream " << "to modified file: " << e.what() << std::endl; return false; } try { if (elfMode) { // Write ELF header outputFile.write((char *)pElfHeader, sizeof(Elf32_Ehdr)); // Write program headers for (int i=0; i<pElfHeader->e_phnum; i++) { Elf32_Phdr *pElfProgramHeader = (Elf32_Phdr *) ReadHeader(hInputFile, sizeof(Elf32_Phdr), i*sizeof(Elf32_Phdr)+pElfHeader->e_phoff); if (!pElfProgramHeader) { std::cerr << "WriteModifiedFile: Invalid program header read" << std::endl; return false; } outputFile.write((char *)pElfProgramHeader, sizeof(Elf32_Phdr)); } // Note: this assumes the offsets stay the same. // the assumption will not hold when permutation is implemented } else { // Write DOS header outputFile.write((char*)pDosHeader, sizeof(IMAGE_DOS_HEADER)); // Write NT header outputFile.seekp(pDosHeader->e_lfanew, std::ios::beg); outputFile.write((char*)pNtHeader, sizeof(IMAGE_NT_HEADERS)); } } catch (std::fstream::failure e) { std::cerr << "WriteModifiedFile: Error while writing " << (elfMode ? "ELF/program" : "DOS/NT headers") << " to modified file: " << e.what() << std::endl; return false; } // Write section headers and section data BYTE* sectionData = nullptr; PIMAGE_SECTION_HEADER pSectionHeader = nullptr; Elf32_Shdr *pElfSectionHeader = nullptr; if (elfMode) { for (int i=0; i < pElfHeader->e_shnum; i++) { pElfSectionHeader = (Elf32_Shdr *) ReadHeader(hInputFile, sizeof(Elf32_Shdr), i*sizeof(Elf32_Shdr)+pElfHeader->e_shoff); if (!pElfSectionHeader) { std::cerr << "WriteModifiedFile: Invalid section header read" << std::endl; return false; } if (!ElfWriteSectionHeader(pElfSectionHeader, i, outputFile, pElfHeader->e_shoff)) { std::cerr << "WriteModifiedFile: Error writing " << i+1 << ". section header" << std::endl; continue; } // .text section if ((pElfHeader->e_entry >= pElfSectionHeader->sh_addr) && (pElfHeader->e_entry < pElfSectionHeader->sh_addr + pElfSectionHeader->sh_size)) { sectionData = (BYTE*)malloc(pElfSectionHeader->sh_size); WriteGraph(graph.GetRoot(), sectionData); WriteData(sectionData); if (!ElfWriteSection(outputFile, pElfSectionHeader, sectionData)) { std::cerr << "WriteModifiedFile: Error while writing data of " << i+1 << ". (executable) section" << std::endl; continue; } } // other sections else { sectionData = ElfLoadSection(hInputFile, pElfSectionHeader); if (!sectionData) { std::cerr << "WriteModifiedFile: Unable to load " << i+1 << ". section" << std::endl; continue; } if (!ElfWriteSection(outputFile, pElfSectionHeader, sectionData)) { std::cerr << "WriteModifiedFile: Error while writing data of " << i+1 << ". section: " << std::endl; continue; } } free(pElfSectionHeader); free(sectionData); pElfSectionHeader = nullptr; sectionData = nullptr; } } else { for (WORD i = 0; i < pNtHeader->FileHeader.NumberOfSections; ++i) { pSectionHeader = (PIMAGE_SECTION_HEADER) ReadHeader(hInputFile, IMAGE_SIZEOF_SECTION_HEADER, dwFstSctHdrOffset + i*IMAGE_SIZEOF_SECTION_HEADER); if (pSectionHeader == nullptr) { std::cerr << "WriteModifiedFile: Invalid section header read" << std::endl; return false; } if (!WriteSectionHeader(pSectionHeader, i, outputFile, dwFstSctHdrOffset)) { std::cerr << "WriteModifiedFile: Error writing " << "the section header: " << pSectionHeader->Name << std::endl; continue; } if ((pNtHeader->OptionalHeader.AddressOfEntryPoint >= pSectionHeader->VirtualAddress) && (pNtHeader->OptionalHeader.AddressOfEntryPoint < (pSectionHeader->VirtualAddress + pSectionHeader->Misc.VirtualSize))) { sectionData = (BYTE*)malloc(pSectionHeader->SizeOfRawData); WriteGraph(graph.GetRoot(), sectionData); WriteData(sectionData); if (!WriteSection(outputFile, pSectionHeader, sectionData)) { std::cerr << "WriteModifiedFile: Error while writing data of " << "executable section: " << pSectionHeader->Name << std::endl; continue; } } else { sectionData = LoadSection(hInputFile, pSectionHeader); if (sectionData == nullptr) { std::cerr << "WriteModifiedFile: Unable to load section: " << pSectionHeader->Name << std::endl; continue; } if (!WriteSection(outputFile, pSectionHeader, sectionData)) { std::cerr << "WriteModifiedFile: Error while writing data of " << "section: " << pSectionHeader->Name << std::endl; continue; } } free(pSectionHeader); free(sectionData); sectionData = nullptr; pSectionHeader = nullptr; } // Write overlays if any // Overlay == data appended to PE file PIMAGE_SECTION_HEADER pLastSectionHeader = (PIMAGE_SECTION_HEADER) ReadHeader(hInputFile, IMAGE_SIZEOF_SECTION_HEADER, dwFstSctHdrOffset + IMAGE_SIZEOF_SECTION_HEADER * (pNtHeader->FileHeader.NumberOfSections - 1)); DWORD overlaySize; BYTE* overlay = ExtractOverlays(hInputFile, pLastSectionHeader, &overlaySize); if (overlay != nullptr && overlaySize != 0) { if (!WriteDataToFile(outputFile, pLastSectionHeader->PointerToRawData + pLastSectionHeader->SizeOfRawData, overlaySize, overlay)) { std::cerr << "WriteModifiedFile: Error while writing overlay " << "data to modified file" << std::endl; return false; } } } try { outputFile.flush(); outputFile.close(); } catch (std::fstream::failure e) { std::cerr << "WriteModifiedFile: Error while closing modified file " << "stream: " << e.what() << std::endl; return false; } return true; }