Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 30th, 2009  |  syntax: C++  |  size: 1.46 KB  |  views: 142  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. CFG::CFG(func_t *func)
  2. {
  3.   eavec_t eavec;
  4.  
  5.   eavec.push_back(func->startEA);
  6.   while(!eavec.empty())
  7.   {
  8.     ea_t *front = eavec.front();
  9.     ea_t working_ea = *front;
  10.     eavec.erase(front);
  11.     if(!Split(ea))
  12.     {
  13.       BasicBlock block;
  14.       block.boundary.ea1 = block.boundary.ea2 = ea;
  15.       bool bContinue = 1;
  16.  
  17.       do
  18.       {
  19.         flags_t flags = get_flags(ea);
  20.         if(!isFlow(flags) && block.boundary.ea1 == ea)
  21.           break;
  22.        
  23.         if(!isCode(flags))
  24.           break;
  25.        
  26.         if(Split(ea))
  27.         {
  28.           Edge edge;
  29.           edge.ea   = ea;
  30.           edge.type = 3;
  31.           block.inedges.push_back(edge);
  32.           break;
  33.         }
  34.         if(GetIncoming(ea, &eavec, &block))
  35.           bContinue = 0;
  36.        
  37.         ea = get_item_end(ea);
  38.       } while(!bContinue);
  39.     } // end if(!Split(ea))
  40.     m_Vector.push_back(block);
  41.   } // end while(!eavec.empty())
  42.   m_NumBlocks = m_Vector.size();
  43.   for(int i = 0; i < m_NumBlocks; ++i)
  44.   {
  45.     for(int j = 0; j <= m_Vector[i].inedges.size(); ++j)
  46.     {
  47.       Edge e;
  48.       e.ea   = m_Vector[i].boundary.ea1;
  49.       e.type = m_Vector[i].inedges[j].type;
  50.       int idx = -1;
  51.       for(int k = 0; k < m_NumBlocks; ++k)
  52.       {
  53.         if(m_Vector[k].boundary.ea1 == m_Vector[i].inedges[j].ea)
  54.         {
  55.           idx = k;
  56.           break;
  57.         }
  58.       }
  59.       // bug here, if idx = -1
  60.       m_Vector[idx].outedges.push_back(e);
  61.     }
  62.   }
  63. }