示例#1
0
bool Architecture::FormatFunction(
    Document      const& rDoc,
    Address       const& rAddr,
    Function      const& rFunc,
    PrintData          & rPrintData) const
{
    auto FuncLabel = rDoc.GetLabelFromAddress(rAddr);

    if (rFunc.GetSize() != 0 && rFunc.GetInstructionCounter() != 0)
    {
        std::ostringstream oss;
        oss
                << std::hex << std::showbase << std::left
                << "; size=" << rFunc.GetSize()
                << ", insn_cnt=" << rFunc.GetInstructionCounter();

        rPrintData.AppendComment(oss.str());
    }
    else
        rPrintData.AppendComment("; imported");

    Id CurId;
    if (!rDoc.RetrieveDetailId(rAddr, 0, CurId))
        return true;

    FunctionDetail FuncDtl;
    if (!rDoc.GetFunctionDetail(CurId, FuncDtl))
        return true;

    rPrintData.AppendNewLine().AppendSpace(2).AppendComment(";").AppendSpace();

    auto const& RetType = FuncDtl.GetReturnType();

    std::string FuncName;
    Label CurLbl = rDoc.GetLabelFromAddress(rAddr);
    if (CurLbl.GetType() == Label::Unknown)
        FuncName = FuncDtl.GetName();
    else
        FuncName = CurLbl.GetName();

    FormatTypeDetail(RetType, rPrintData);
    rPrintData.AppendSpace().AppendLabel(FuncName).AppendOperator("(");

    bool FirstParam = true;
    auto const& Params = FuncDtl.GetParameters();
    for (auto const& Param : Params)
    {
        if (FirstParam)
            FirstParam = false;
        else
            rPrintData.AppendOperator(",").AppendSpace();

        FormatTypeDetail(Param.GetType(), rPrintData);
        rPrintData.AppendSpace().AppendLabel(Param.GetValue().GetName());
    }

    rPrintData.AppendOperator(");");

    return true;
}
示例#2
0
bool Architecture::FormatFunction(
  Document      const& rDoc,
  BinaryStream  const& rBinStrm,
  Address       const& rAddr,
  Function      const& rFunc,
  std::string        & rStrMultiCell,
  Cell::Mark::List   & rMarks) const
{
  std::ostringstream oss;
  oss << std::hex << std::showbase << std::left;
  auto FuncLabel = rDoc.GetLabelFromAddress(rAddr);

  oss
    << "; " << FuncLabel.GetLabel()
    << ": size=" << rFunc.GetSize()
    << ", insn_cnt=" << rFunc.GetInstructionCounter();

  rStrMultiCell = oss.str();
  return true;
}
示例#3
0
/*!
 * Recursive function to list children ordered by size.
 */
void PreOrderHelper(
	unsigned int n,
	//vector< Function * > &vecParents,
	Function *pParent,
	set< Function *> &track,
	log4cpp::Category *pLog )
{
	vector< Function * > ordFuncs;
	vector< Function * >::iterator b, e;//, parB, parE;

	// For each parent
	//for( parB = vecParents.begin(), parE = vecParents.end();
	//parB != parE; ++parB )
	//{
	//	Function *pParent = *parB;

		// Order children by increasing size
		Function *pChild = pParent->GetFirstChild();
		while( pChild != NULL )
		{
			// If child has been accessed, skip
			if( track.find( pChild ) != track.end() )
			{
				pChild = pParent->GetNextChild();
				continue;
			}


			// Insert child in increasing size
			for( b = ordFuncs.begin(), e = ordFuncs.end();
			b != e; ++b )
			{
				if( pChild->GetSize() < (*b)->GetSize() )
				{
					ordFuncs.insert( b, pChild );
					break;
				}
			}
			if( b == e)
				ordFuncs.push_back( pChild );

			// Child has been inserted
			track.insert( pChild );

			pChild = pParent->GetNextChild();
		}
	//}

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

	// List child in increasing size order
	for( b = ordFuncs.begin(), e = ordFuncs.end();
	b != e; ++b )
	{
		// track.insert( *b );
		pLog->info("%u\t%u\t%u\t%s", n, (*b)->GetLevel(), (*b)->GetSize(), (*b)->GetName());
	}

	// Recurse
	//PreOrderHelper( ++n, ordFuncs, track, pLog );
	for( b = ordFuncs.begin(), e = ordFuncs.end();
	b != e; ++b )
	{
		PreOrderHelper( n, (*b), track, pLog );
	}
}