コード例 #1
0
ファイル: TskReportPipeline.cpp プロジェクト: Smoss/sleuthkit
void TskReportPipeline::run()
{
    Poco::Stopwatch stopWatch;
    for (size_t i = 0; i < m_modules.size(); i++)
    {
        stopWatch.restart();
        TskModule::Status status = m_modules[i]->report();
        stopWatch.stop();
        updateModuleExecutionTime(m_modules[i]->getModuleId(), stopWatch.elapsed());

        TskServices::Instance().getImgDB().setModuleStatus(0, m_modules[i]->getModuleId(), (int)status);

        // The reporting pipeline continues to run on module failure. Only shutdown the pipeline if a module signals STOP.
        if (status == TskModule::STOP)
        {
            break;
        }
    }
}
コード例 #2
0
void TskFileAnalysisPipeline::run(TskFile* file)
{
    const std::string MSG_PREFIX = "TskFileAnalysisPipeline::run : ";

    if (m_modules.size() == 0)
        return;

    if (file == NULL)
    {
        LOGERROR(MSG_PREFIX + "passed NULL file pointer");
        throw TskNullPointerException();
    }

    TskImgDB& imgDB = TskServices::Instance().getImgDB();

    try
    {
        // If this is an excluded file or the file is not ready for analysis
        // we return without processing.
        if (excludeFile(file))
        {
            std::stringstream msg;
            msg << MSG_PREFIX << "skipping file (excluded) "  << file->getName() << "(" << file->getId() << ")";
            LOGINFO(msg.str());
            file->setStatus(TskImgDB::IMGDB_FILES_STATUS_ANALYSIS_SKIPPED);
            return;
        }

        if (file->getStatus() != TskImgDB::IMGDB_FILES_STATUS_READY_FOR_ANALYSIS) 
        {
            std::stringstream msg;
            msg << MSG_PREFIX << "skipping file (not ready) " << file->getName() << "(" << file->getId() << ")";
            LOGINFO(msg.str());
            return;
        }

        // Update status to indicate analysis is in progress.
        file->setStatus(TskImgDB::IMGDB_FILES_STATUS_ANALYSIS_IN_PROGRESS);
        std::stringstream msg;
        msg << MSG_PREFIX <<  "analyzing " << file->getName() << "(" << file->getId() << ")";
        LOGINFO(msg.str());

        // If there is an Executable module in the pipeline we must
        // ensure that the file exists on disk.
        if (m_hasExeModule && !file->exists())
        {
            TskFileManagerImpl::instance().saveFile(file);
        }

        bool bModuleFailed = false;

        Poco::Stopwatch stopWatch;
        for (int i = 0; i < m_modules.size(); i++)
        {
            // we have no way of knowing if the file was closed by a module,
            // so always make sure it is open
            file->open();

            // Reset the file offset to the beginning of the file.
            file->seek(0);

            stopWatch.restart();
            TskModule::Status status = m_modules[i]->run(file);
            stopWatch.stop();            
            updateModuleExecutionTime(m_modules[i]->getModuleId(), stopWatch.elapsed());
            
            imgDB.setModuleStatus(file->getId(), m_modules[i]->getModuleId(), (int)status);

            // If any module encounters a failure while processing a file
            // we will set the file status to failed once the pipeline is complete.
            if (status == TskModule::FAIL)
                bModuleFailed = true;

            // Stop processing the file when a module tells us to.
            else if (status == TskModule::STOP)
                break;
        }

        // Delete the file if it exists. The file may have been created by us
        // above or by a module that required it to exist on disk.
        // Carved and derived files should not be deleted since the content is
        // typically created by external tools.
        if (file->getTypeId() != TskImgDB::IMGDB_FILES_TYPE_CARVED &&
            file->getTypeId() != TskImgDB::IMGDB_FILES_TYPE_DERIVED &&
            file->exists())
        { 
            TskFileManagerImpl::instance().deleteFile(file);
        }

        // We allow modules to set status on the file so we only update it
        // if the modules haven't.
        if (file->getStatus() == TskImgDB::IMGDB_FILES_STATUS_ANALYSIS_IN_PROGRESS)
        {
            if (bModuleFailed)
            {
                file->setStatus(TskImgDB::IMGDB_FILES_STATUS_ANALYSIS_FAILED);
            }
            else
            {
                file->setStatus(TskImgDB::IMGDB_FILES_STATUS_ANALYSIS_COMPLETE);
            }
        }
    }
    catch (std::exception& ex)
    {
        std::stringstream msg;
        msg << MSG_PREFIX << "error while processing file id (" << file->getId() << ") : " << ex.what();
        LOGERROR(msg.str());
        imgDB.updateFileStatus(file->getId(), TskImgDB::IMGDB_FILES_STATUS_ANALYSIS_FAILED);

        // Rethrow the exception
        throw;
    }
}
コード例 #3
0
ファイル: World.cpp プロジェクト: sprenger120/FastCraft
World::World(string Name,char iDimension,MinecraftServer* pServer) :
	_WorldName(Name),
	_iDimension(iDimension)
{
	_pMinecraftServer	= pServer;
	_pWorldFileHandler	= NULL;
	_pSettings			= NULL;
	_pLevelDataFile		= NULL;

	/* Init settings */
	_fHardcore		= false;
	_iMapFeatures	= 1;
	_fRaining		= false;
	_fThundering	= false;
	_iGameType		= 0;
	_iRainTime		= 0;
	_iSpawnX		= 0;
	_iSpawnY		= 0;
	_iSpawnZ		= 0;
	_iThunderTime	= 0;
	_iVersion		= 19133;
	_iLastPlayed	= 0L;
	_iSeed			= 0L;
	_iSizeOnDisk	= 0L;
	_iTime			= 0L;
	_sGeneratorName.assign("default");
	_sLevelName.assign("world");

	/* Prepare path */	
	Poco::Path path(pServer->getServerDirectory());
	path.pushDirectory(_WorldName);

	try {
		/* Check existance of needed directories */
		IOFile::createDir(path);
		path.pushDirectory("data");
		IOFile::createDir(path);
		path.popDirectory();
		path.pushDirectory("players");
		IOFile::createDir(path);
		path.popDirectory();
		path.pushDirectory("region");
		IOFile::createDir(path);
		path.popDirectory();
		path.setFileName("level.dat");


		/* try to load level.dat */
		Poco::File filepath(path);
		NBTTagCompound* pCompData;
		char* pData = NULL;

		try {
			try { //Seperate exception catchnig for bad errors
				_pLevelDataFile = new IOFile(filepath);
			}catch(FCRuntimeException& ex) {
				throw std::exception(ex.what());
			}

			if (_pLevelDataFile->getSize() < 2)  {throw FCRuntimeException("Unable to read level.dat",false);}

			pData = new char[_pLevelDataFile->getSize()];
			_pLevelDataFile->read(pData,_pLevelDataFile->getSize());

			NBTBinaryParser parser;
			_pSettings = parser.parse(pData,FC_NBT_IO_GZIP,_pLevelDataFile->getSize());
			pCompData = dynamic_cast<NBTTagCompound*>(_pSettings->getElementByName("Data"));
			if (pCompData == NULL) {throw FCRuntimeException("No Data compound");}
			delete [] pData;

		}catch(FCRuntimeException) {
			/* Something failed, generate own one */
			if (pData) {delete [] pData;}
			if (_pSettings) {delete _pSettings;}

			_pSettings = new NBTTagCompound("");
			_pSettings->addSubElement(pCompData = new NBTTagCompound("Data"));
		}catch(std::exception){
			throw FCRuntimeException("Unable to open/create level.dat");
		}


		NBTHelper<NBTTagByte,char>::read(pCompData,"hardcore",_fHardcore);
		NBTHelper<NBTTagByte,char>::read(pCompData,"MapFeatures",_iMapFeatures);
		NBTHelper<NBTTagByte,char>::read(pCompData,"raining",_fRaining);
		NBTHelper<NBTTagByte,char>::read(pCompData,"thundering",_fThundering);
		NBTHelper<NBTTagInt,int>::read(pCompData,"GameType",_iGameType);
		NBTHelper<NBTTagInt,int>::read(pCompData,"generatorVersion",_iGeneratorVersion);
		NBTHelper<NBTTagInt,int>::read(pCompData,"rainTime",_iRainTime);
		NBTHelper<NBTTagInt,int>::read(pCompData,"SpawnX",_iSpawnX);
		NBTHelper<NBTTagInt,int>::read(pCompData,"SpawnY",_iSpawnY);
		NBTHelper<NBTTagInt,int>::read(pCompData,"SpawnZ",_iSpawnZ);
		NBTHelper<NBTTagInt,int>::read(pCompData,"thunderTime",_iThunderTime);
		NBTHelper<NBTTagInt,int>::read(pCompData,"version",_iVersion);
		NBTHelper<NBTTagInt64,Tick>::read(pCompData,"LastPlayed",_iLastPlayed);
		NBTHelper<NBTTagInt64,long long>::read(pCompData,"RandomSeed",_iSeed);
		NBTHelper<NBTTagInt64,long long>::read(pCompData,"SizeOnDisk",_iSizeOnDisk);
		NBTHelper<NBTTagInt64,Tick>::read(pCompData,"Time",_iTime);
		NBTHelper<NBTTagString,string>::read(pCompData,"generatorName",_sGeneratorName);
		NBTHelper<NBTTagString,string>::read(pCompData,"LevelName",_sLevelName);


		/* Open region files */
		path.setFileName("");
		_pWorldFileHandler = new WorldFileHandler(path);



		/* Load chunks around the spawn point */
		int iLoadedChunks = 0;
		int iChunkSpawnX = _iSpawnX/16;
		int iChunkSpawnZ = _iSpawnZ/16;
		Poco::Stopwatch nextOutput;
		Poco::Stopwatch loadingTime;
	
		nextOutput.start();
		loadingTime.start();
		for (int x = iChunkSpawnX - 12;x<=iChunkSpawnX + 12;x++) {
			for (int z = iChunkSpawnZ - 12;z<=iChunkSpawnZ + 12;z++) {
				getChunk(x,z);
				iLoadedChunks++;

				if (nextOutput.elapsed() >= 1000000) {
					cout<<"\tProgress "<<((iLoadedChunks*100)/625)<<"%\n";
					nextOutput.restart();
				}
			}
		}
		loadingTime.stop();
		cout<<"\tLoading done in "<<(loadingTime.elapsed()/1000000)<<"s\n";
	}catch(FCRuntimeException& ex) {
		ex.rethrow();
	}
}
コード例 #4
0
ファイル: main.cpp プロジェクト: qokelate/sma11caseX
int main(int argc, char **argv)
{
    Poco::Stopwatch sw;

    std::string dir = Poco::Environment::get("POCO_BASE") + "/JSON/samples/Benchmark/";
    Poco::Path  filePath(dir, "input.big.json");

    std::ostringstream ostr;

    if (filePath.isFile()) {
        Poco::File inputFile(filePath);

        if (inputFile.exists()) {
            sw.start();
            Poco::FileInputStream fis(filePath.toString());
            Poco::StreamCopier::copyStream(fis, ostr);
            sw.stop();
        } else {
            std::cout << filePath.toString() << " doesn't exist!" << std::endl;
            return 1;
        }
    }

    std::cout << "JSON Benchmark" << std::endl;
    std::cout << "==============" << std::endl;

    std::string jsonStr = ostr.str();
    std::cout << "Total of " << jsonStr.size() << " bytes," << std::endl << "loaded in " << sw.elapsed() << " [us]," << std::endl;

    std::cout << std::endl << "POCO JSON barebone parse" << std::endl;
    Poco::JSON::Parser sparser(0);
    sw.restart();
    sparser.parse(jsonStr);
    sw.stop();
    std::cout << "---------------------------------" << std::endl;
    std::cout << "[std::string] parsed in " << sw.elapsed() << " [us]" << std::endl;
    std::cout << "---------------------------------" << std::endl;

    Poco::JSON::Parser  iparser(0);
    std::istringstream  istr(jsonStr);
    sw.restart();
    iparser.parse(istr);
    sw.stop();
    std::cout << "----------------------------------------" << std::endl;
    std::cout << "[std::istringstream] parsed in " << sw.elapsed() << " [us]" << std::endl;
    std::cout << "----------------------------------------" << std::endl;

    std::cout << std::endl << "POCO JSON Handle/Stringify" << std::endl;
    try
    {
        Poco::JSON::Parser sparser;
        sw.restart();
        sparser.parse(jsonStr);
        Poco::DynamicAny result = sparser.result();
        sw.stop();
        std::cout << "-----------------------------------------" << std::endl;
        std::cout << "[std::string] parsed/handled in " << sw.elapsed() << " [us]" << std::endl;
        std::cout << "-----------------------------------------" << std::endl;

        Poco::JSON::Parser  isparser;
        std::istringstream  istr(jsonStr);
        sw.restart();
        isparser.parse(istr);
        result = isparser.result();
        sw.stop();
        std::cout << "------------------------------------------------" << std::endl;
        std::cout << "[std::istringstream] parsed/handled in " << sw.elapsed() << " [us]" << std::endl;
        std::cout << "------------------------------------------------" << std::endl;

        // Serialize to string
        Poco::JSON::Object::Ptr obj;

        if (result.type() == typeid(Poco::JSON::Object::Ptr)) {
            obj = result.extract <Poco::JSON::Object::Ptr> ();
        }

        std::ostringstream out;
        sw.restart();
        obj->stringify(out);
        sw.stop();
        std::cout << "-----------------------------------" << std::endl;
        std::cout << "stringified in " << sw.elapsed() << " [us]" << std::endl;
        std::cout << "-----------------------------------" << std::endl;
        std::cout << std::endl;
    }
    catch(Poco::JSON::JSONException jsone)
    {
        std::cout << jsone.message() << std::endl;
    }

    return 0;
}