Example #1
0
	void ProcEditor::setCurrentProc( const QString &name )
	{
		actionList->clear();

		currentProc = name;
		IParser *parser = CWidgetManager::getInstance()->getParser();
		CProcedure *proc = parser->getProc( name.toUtf8().constData() );
		
		std::vector< CProcAction >::const_iterator itr;
		for( itr = proc->Actions.begin(); itr != proc->Actions.end(); ++itr )
		{
			actionList->addItem( itr->Action.c_str() );
		}

		setWindowTitle( QString( "Procedure Editor - %1" ).arg( currentProc ) );
	}
Example #2
0
bool ProxySession::Transfer(FileDesc& src, FileDesc& dest, IParser& parser, std::error_code &ec)
{
    // until we're using an actual plugin, just read and write to a local buffer
    auto inBuff = parser.GetWriteSlice();
    auto numRead = read(src, inBuff, inBuff.Size());

    if(numRead < 0) {
            ec = std::error_code(errno, std::system_category());
            return false;
    }

    if(numRead == 0) {
            ec = Error::END_OF_FILE;
            return false;
    }


    if(m_config.observeOnly)
    {
        // in observe only mode we just write the data we read immediately
        // there is no guarantee that the parser doesn't modify the buffer

        this->WriteAll(dest, RSlice(inBuff, numRead), ec);

        // regardless of if there is any error or not, we feed the parser
        // but ignore whatever it outputs
        parser.Parse(numRead);
    }
    else
    {
        // now notify the parser that we wrote some data into its input buffer
        if(parser.Parse(numRead))
        {
            // if the parser didn't reject it, pass output anything the parser kicked back
            this->WriteOutputTo(dest, ec);
        }
        else
        {
            ec = Error::PARSER_REJECT;
        }
    }

    // always clear any unwritten slices due to error or explicit parser rejection
    this->m_output_vec.clear();

    return ec.value();
}
Example #3
0
	void LinkEditor::setLinkId( uint32 linkId )
	{
		setup();
		currentLinkId = linkId;

		IParser *parser = CWidgetManager::getInstance()->getParser();
		SLinkData data;

		if( !parser->getLinkData( currentLinkId, data ) )
			return;

		expressionEdit->setPlainText( data.expr.c_str() );
		targetEdit->setText( data.target.c_str() );
		ahEdit->setText( data.action.c_str() );
		ahParamEdit->setText( data.params.c_str() );
		condEdit->setText( data.cond.c_str() );
	}
Example #4
0
	void LinkEditor::onOKButtonClicked()
	{
		IParser *parser = CWidgetManager::getInstance()->getParser();
		SLinkData data;

		if( !parser->getLinkData( currentLinkId, data ) )
			return;

		data.expr = expressionEdit->toPlainText().toUtf8().constData();		
		data.target = targetEdit->text().toUtf8().constData();
		data.action = ahEdit->text().toUtf8().constData();
		data.params = ahParamEdit->text().toUtf8().constData();
		data.cond   = condEdit->text().toUtf8().constData();
		parser->updateLinkData( data.id, data );

		Q_EMIT okClicked();

		hide();
	}
Example #5
0
 virtual unsigned int output_partitioned_file(const std::string infilename,
                                              const std::string outputfilename,
                                              CallbackFn callback=0,
                                              void * callback_data=0)
 {
   IParser* parser = IParser::get_parser(infilename);
   ofstream outfile(outputfilename.c_str());
   
   unsigned int total_reads = 0;
   unsigned int reads_kept = 0;
   
   Read read;
   string seq;
   
   std::string first_kmer;
   HashIntoType forward_hash = 0, reverse_hash = 0;
   
   map<SetID, unsigned int> lReadCounts;
   
   while(!parser->is_complete()) {
     read = parser->get_next_read();
     seq = read.seq;
     
     if (check_read(seq)) {
       first_kmer = seq.substr(0, _ksize);
       
       // generate the hash for the first kmer in the read (fair amount of work)
       HashIntoType bin = _hash(first_kmer.c_str(), _ksize, forward_hash, reverse_hash);
       
       SetID lActualFinalSetID = _sets[ _set_IDs[ bin ] ]->getCurrentPrimarySetID();
       
       lReadCounts[lActualFinalSetID]++;
       
       outfile << ">" << read.name << "\t" << lActualFinalSetID
       << " " << "\n" 
       << seq << "\n";
       
       // reset the sequence info, increment read number
       total_reads++;
       
       // run callback, if specified
       if (total_reads % CALLBACK_PERIOD == 0 && callback) {
         try {
           callback("do_truncated_partition/output", callback_data,
                    total_reads, reads_kept);
         } catch (...) {
           delete parser; parser = NULL;
           outfile.close();
           throw;
         }
       }
     }
   }
   
   for ( map<SetID, unsigned int>::iterator lIt = lReadCounts.begin(); lIt != lReadCounts.end(); ++lIt )
   {
     cout << setw(10) << lIt->first;
     cout << setw(10) << lIt->second << endl;        
   }
   
   cout << setw(6) << "unique set count: "<< lReadCounts.size() << endl;
   cout << endl;
   
   
   delete parser; parser = NULL;
   
   return lReadCounts.size();
 }
Example #6
0
	//////////////////////////////////////////////////////////////////////////
	//
	// Class MemoryViewDebugger
	// 
	// 罗嘉飞  2011、5、26  内存显示
	//
	void MemoryViewDebugger::Debug( VCPU* pCPU, LPVOID param )
	{
		auto IR = pCPU->GetIR();
		if ( IR->m_elements[ 0 ] == "leave" )  {flag = 0; m_funcId.pop();}
		else if ( IR->m_elements[ 0 ] == "mov" && IR->m_elements[ 1 ] == "d1" ) {flag = 1;m_funcId.push( pCPU->Getdreg()[ 1 ] );}

		if ( !m_funcId.empty() ) 
		{
			if ( m_funcId.top()  !=  pCPU->Getdreg()[ 1 ] ) 
				flag = 1;
		}
		if ( flag == 1 )
		{
			// 获取语法器
			IParser* pParser = (IParser*)m_callBack( NULL );
			// 获取符号表
			Environment& env = (Environment)pParser->GetTables();

			MemorySpy* pProWnd = *(MemorySpy**)( m_callBack( (LPVOID)1 ) );

			dword_pointer pebp = pCPU->Getebp();

			dword_pointer pesp = pCPU->Getesp();

			dword eip = pCPU->Geteip();

			//dword c=*(pebp+8);
			//dword d=*(pesp+8);

			//////////////////



			PropertiesInsertItem temp;
			WatchPropertiesListType* ValList = new std::list< PropertiesInsertItem >;


			//////////////////////
			DWORD pc = pCPU->Geteip();	// PC

			/*dword func_id = pCPU->Getdreg()[ 1 ];*/

			dword func_id = m_funcId.top();    //每次都去栈顶

			//m_funcId.push(func_id);

			Table* table;

			auto iter=env.m_tableList.begin();

			for (;iter!=env.m_tableList.end();iter++) 
			{
				if( iter->second.GetID()==func_id)
				{
					break;
				}
			}

			if ( iter == env.m_tableList.end() )	return;

			table = &iter->second;
			/*(table)->m_symbolList;*/

			for ( auto symbol = table->GetLocalVarTable().begin(); symbol != table->GetLocalVarTable().end(); ++symbol )
			{
				temp.varname=symbol->second.name;
				temp.val=*(dword_pointer)( ((uchar_pointer)pebp) - symbol->second.offset);
				ValList->push_back(temp);
			}

			/*table->m_paramSymbolList;*/
			for ( auto symbol = table->GetParamTable().begin(); symbol != table->GetParamTable().end(); ++symbol )
			{
				temp.varname=symbol->second.name;
				temp.val=*(dword_pointer)( ((uchar_pointer)pebp) - symbol->second.offset + 4);
				ValList->push_back(temp);
			}

			if ( listComp != *ValList )
			{

				listComp = *ValList;
				//pProWnd->PostMessageA( WM_CLEAR_ALL_ITEMS );
				pProWnd->PostMessageA( WM_INSERT_ITEM, (WPARAM)ValList, 0 );
			}
			else
			{
				delete ValList;
			}
			
		}
	}
Example #7
0
	//////////////////////////////////////////////////////////////////////////
	//
	// Class WatchDogDebugger
	// 	
	// 罗嘉飞   2011/5/26   需要看到的内存
	//
	void WatchDogDebugger::Debug( VCPU* pCPU, LPVOID param )
	{
		auto IR = pCPU->GetIR();
		if ( IR->m_elements[ 0 ] == "leave" )  {flag = 0; m_funcId.pop();}
		else if ( IR->m_elements[ 0 ] == "mov" && IR->m_elements[ 1 ] == "d1" ) {flag = 1;m_funcId.push( pCPU->Getdreg()[ 1 ] );}

		if ( !m_funcId.empty() ) 
		{
			if ( m_funcId.top()  !=  pCPU->Getdreg()[ 1 ] ) 
				flag = 1;
		}

		if( flag==1)  
		{
			// 获取语法器
			IParser* pParser = (IParser*)m_callBack( 0 );
			// 获取符号表
			Environment& env = (Environment)pParser->GetTables();

			dword_pointer pebp = pCPU->Getebp();

			dword_pointer pesp = pCPU->Getesp();

			dword eip = pCPU->Geteip();

			std::list<std::string>* pList = (std::list<std::string>*)m_callBack( (LPVOID)1 );

			PropertiesInsertItem temp;
			std::list< PropertiesInsertItem >* ValList = new std::list< PropertiesInsertItem >;

			//////////////////////
			DWORD pc = pCPU->Geteip();	// PC

			dword func_id = m_funcId.top();

			Table* table;

			auto iter=env.m_tableList.begin();

			for (;iter!=env.m_tableList.end();iter++) 
			{
				if( iter->second.GetID()==func_id)
				{
					break;
				}
			}

			if ( iter == env.m_tableList.end() )	return;

			table = &iter->second;


			for ( auto symbol = table->GetLocalVarTable().begin(); symbol != table->GetLocalVarTable().end(); ++symbol )
			{
				//在关键字List里才取出
				for (auto iter = pList->begin(); iter != pList->end(); ++iter)
				{
					if ( *iter == symbol->second.name)
					{
						temp.varname=symbol->second.name;
						temp.val=*(dword_pointer)( ((uchar_pointer)pebp) - symbol->second.offset);
						ValList->push_back(temp);
					}
				}
			}


			for ( auto symbol = table->GetParamTable().begin(); symbol != table->GetParamTable().end(); ++symbol )
			{
				//在关键字List里才取出
				for (auto iter = pList->begin(); iter != pList->end(); ++iter)
				{
					if ( *iter == symbol->second.name)
					{
						temp.varname=symbol->second.name;
						temp.val=*(dword_pointer)( ((uchar_pointer)pebp) - symbol->second.offset+4);
						ValList->push_back(temp);
					}
				}
			}

			m_callBack( (LPVOID)ValList );

	/*		CPropertiesWnd* pProWnd = *(CPropertiesWnd**)m_callBack( (LPVOID)2 );
			if ( listComp != *ValList )
			{

				listComp = *ValList;
				pProWnd->PostMessageA( WM_CLEAR_ALL_ITEMS );
				pProWnd->PostMessageA( WM_INSERT_ITEM, (WPARAM)ValList, 0 );

			}*/


			//static int i = 0;

			//if ( ! ValList->empty() )
			//{
			//	std::ofstream out("d:\\data\\" + itoa( i++ ) + ".txt",std::ios::out);
			//	out << eip << std::endl;
			//	for (auto iter = ValList->begin(); iter!=ValList->end(); ++iter)
			//	{
			//		out << iter->varname << "  ";
			//		out << iter->val << std::endl;
			//	}
			//}
	}
	}
Example #8
0
unsigned int SubsetPartition::output_partitioned_file(const std::string infilename,
						      const std::string outputfile,
						      bool output_unassigned,
						      CallbackFn callback,
						      void * callback_data)
{
  IParser* parser = IParser::get_parser(infilename);
  ofstream outfile(outputfile.c_str());

  unsigned int total_reads = 0;
  unsigned int reads_kept = 0;
  unsigned int n_singletons = 0;

  PartitionSet partitions;

  Read read;
  string seq;

  std::string first_kmer;
  HashIntoType kmer = 0;

  const unsigned int ksize = _ht->ksize();

  //
  // go through all the reads, and take those with assigned partitions
  // and output them.
  //

  while(!parser->is_complete()) {
    read = parser->get_next_read();
    seq = read.seq;

    if (_ht->check_read(seq)) {
      const char * kmer_s = seq.c_str();

      bool found_tag = false;
      for (unsigned int i = 0; i < seq.length() - ksize + 1; i++) {
	kmer = _hash(kmer_s + i, ksize);

	// is this a known tag?
	if (partition_map.find(kmer) != partition_map.end()) {
	  found_tag = true;
	  break;
	}
      }

      // all sequences should have at least one tag in them.
      // assert(found_tag);  @CTB currently breaks tests.  give fn flag to
      // disable.

      PartitionID partition_id = 0;
      if (found_tag) {
	PartitionID * partition_p = partition_map[kmer];
	if (partition_p == NULL ){
	  partition_id = 0;
	  n_singletons++;
	} else {
	  partition_id = *partition_p;
	  partitions.insert(partition_id);
	}
      }

      if (partition_id > 0 || output_unassigned) {
	outfile << ">" << read.name << "\t" << partition_id;
	outfile << "\n" << seq << "\n";
      }
#ifdef VALIDATE_PARTITIONS
      std::cout << "checking: " << read.name << "\n";
      assert(is_single_partition(seq));
#endif // VALIDATE_PARTITIONS
	       
      total_reads++;

      // run callback, if specified
      if (total_reads % CALLBACK_PERIOD == 0 && callback) {
	try {
	  callback("output_partitions", callback_data,
		   total_reads, reads_kept);
	} catch (...) {
	  delete parser; parser = NULL;
	  outfile.close();
	  throw;
	}
      }
    }
  }

  delete parser; parser = NULL;

  return partitions.size() + n_singletons;
}
Example #9
0
void Hashtable::consume_fasta(const std::string &filename,
			      unsigned int &total_reads,
			      unsigned long long &n_consumed,
			      HashIntoType lower_bound,
			      HashIntoType upper_bound,
			      ReadMaskTable ** orig_readmask,
			      bool update_readmask,
			      CallbackFn callback,
			      void * callback_data)
{
  total_reads = 0;
  n_consumed = 0;

  IParser* parser = IParser::get_parser(filename.c_str());
  Read read;

  string currName = "";
  string currSeq = "";

  //
  // readmask stuff: were we given one? do we want to update it?
  // 

  ReadMaskTable * readmask = NULL;
  std::list<unsigned int> masklist;

  if (orig_readmask && *orig_readmask) {
    readmask = *orig_readmask;
  }

  //
  // iterate through the FASTA file & consume the reads.
  //

  while(!parser->is_complete())  {
    read = parser->get_next_read();
    currSeq = read.seq;
    currName = read.name; 

    // do we want to process it?
    if (!readmask || readmask->get(total_reads)) {

      // yep! process.
      unsigned int this_n_consumed;
      bool is_valid;

      this_n_consumed = check_and_process_read(currSeq,
					       is_valid,
					       lower_bound,
					       upper_bound);

      // was this an invalid sequence -> mark as bad?
      if (!is_valid && update_readmask) {
        if (readmask) {
	  readmask->set(total_reads, false);
	} else {
	  masklist.push_back(total_reads);
	}
      } else {		// nope -- count it!
        n_consumed += this_n_consumed;
      }
    }
	       
    // reset the sequence info, increment read number
    total_reads++;

    // run callback, if specified
    if (total_reads % CALLBACK_PERIOD == 0 && callback) {
      try {
        callback("consume_fasta", callback_data, total_reads, n_consumed);
      } catch (...) {
        throw;
      }
    }
  }


  //
  // We've either updated the readmask in place, OR we need to create a
  // new one.
  //

  if (orig_readmask && update_readmask && readmask == NULL) {
    // allocate, fill in from masklist
    readmask = new ReadMaskTable(total_reads);

    list<unsigned int>::const_iterator it;
    for(it = masklist.begin(); it != masklist.end(); ++it) {
      readmask->set(*it, false);
    }
    *orig_readmask = readmask;
  }
}