void LoaderPacker::ProcessExecutable( std::vector<uint8_t>& outFileBuffer, const AdditionalDataBlocksType& additionalDataBlocks) { auto loaderBlock = utils::GetSingleAdditionalBlock(additionalDataBlocks, PackerType::kLoaderPacker); // get type of source executable PlatformType platformType; auto sourcePEbits = srcPEFile_->getBits(); switch (sourcePEbits) { case 32: platformType = PlatformType::x86; break; case 64: platformType = PlatformType::x64; break; default: break; } auto loaderInfo = std::find_if(gloadersNames.begin(), gloadersNames.end(), [&platformType](LoaderInfo& loaderInfo)->bool { return loaderInfo.platformType == platformType; }); if (loaderInfo == gloadersNames.end()) { throw std::runtime_error("error finding loader"); } // load loader data boost::filesystem::path loaderFullPath = loadersStoragePath_; loaderFullPath /= loaderInfo->loaderName; boost::filesystem::ifstream loaderFile; loaderFile.open(loaderFullPath, std::ios::in || std::ifstream::binary); auto pbuf = loaderFile.rdbuf(); // get file size size_t size = static_cast<size_t>(pbuf->pubseekoff(0, loaderFile.end, loaderFile.in)); pbuf->pubseekpos(0, loaderFile.in); std::vector<PeLib::byte> loaderData(size); // get file data pbuf->sgetn(reinterpret_cast<char*>(loaderData.data()), size); loaderFile.close(); // get stub data offset to update loader code with pointer to stub data ( link stubData to loader ) ModifyLoaderWithStubDataInfo(loaderData, additionalDataBlocks); utils::ReplaceContainerData(outFileBuffer, loaderBlock.rawOffset, loaderData); }
ProgressingStreamBuf( const std::string &filename ) : BaseType(), _count(0), _readSize(0) { if ( open(filename.c_str(), std::ios_base::in|std::ios_base::binary) ) pubseekoff( 0, std::ios_base::beg, std::ios_base::in ); }