home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / pedasm.zip / Symbol.cpp < prev    next >
C/C++ Source or Header  |  1998-10-23  |  3KB  |  137 lines

  1. /*        fichier Symbol.cpp : fichier implementation
  2.  *
  3.  *    descr : herarchie de classe qui represente un differents
  4.  *        type de symbols
  5.  *    projet : PEDasm
  6.  *    
  7.  *    rq:
  8.  *    Ce programme est libre de droits. Il peut etre distribue et/ou modifie
  9.  *  selon les termes de la licence 'GNU General Public License version 2'.
  10.  *    
  11.  *    Ce programme est distribue sans aucunes garanties, y compris d'utilite 
  12.  *    ni de risques encouru, quelle que soit son utilisation.
  13.  *
  14.  *    lire le fichier licence.txt fourni ou bien ecrire a :
  15.  *    the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  *    pour recevoir une copie de la licence.
  17.  *
  18.  *    Copyright (C) 1997 - 1998 Nicolas Witczak <witczak@geocities.com>
  19.  */
  20.  
  21. #include "Config.h"
  22.  
  23. #include <cassert>
  24.  
  25. #include "Symbol.h"
  26. #include "ExeRep.h"
  27.  
  28.  
  29. //////////////////////////////////////////////////////////////////
  30. // implementation class CSymbol
  31.  
  32.  
  33. CSymbol::CSymbol( unsigned int VirtAdress , unsigned int attrib , const char* pName) 
  34.     : m_VirtAdress( VirtAdress ) , m_Attrib(attrib) , m_pszName(pName) 
  35. {
  36. }
  37.  
  38. CSymbol::~CSymbol()
  39. {}
  40.  
  41. CSection* CSymbol::GetSection() const
  42. {
  43.     CSection* pRefSection = GetExe()->GetSectFromVA( m_VirtAdress ) ;
  44.     assert( pRefSection != 0 ) ;
  45.     return pRefSection ;
  46. }
  47.  
  48. unsigned int CSymbol::GetSize() const
  49. {
  50.     if( m_Attrib & fSymPointer != 0 )
  51.         return 4 ;
  52.     else
  53.         return -1 ;
  54. }
  55.  
  56. void CSymbol::Dump( FILE* pFile ) const
  57. {
  58.     fprintf( pFile ,"symbol %s : adr 0x%08x , size %i , section %s \n" ,
  59.         GetName() , m_VirtAdress , GetSize() , GetSection()->m_pHeader->Name ) ;
  60. }
  61.  
  62. const char* CSymbol::GetName() const 
  63. {
  64.     static char_buff pszBuff ;
  65.     if( m_pszName != 0)
  66.         return m_pszName ;
  67.     else
  68.     {
  69.         const char* pszTemp ;
  70.         if( ( m_Attrib & fSymKnown ) == 0 )
  71.             pszTemp =  "Unknown" ;
  72.         else if( ( m_Attrib & fSymCode ) != 0 )
  73.         {
  74.             if( ( m_Attrib & fSymFunc ) != 0 )
  75.             {
  76.                 if(  ( m_Attrib & fCallBack ) != 0  )
  77.                     pszTemp = "CallBack" ;
  78.                 else
  79.                     pszTemp = "Fun" ;
  80.             }
  81.             else // jump
  82.                 pszTemp = "Label" ;
  83.         }
  84.         else // data
  85.         {
  86.             if( ( m_Attrib & fSymPointer ) != 0 )
  87.                 pszTemp = "DataPtr" ;
  88.             else // jump
  89.                 pszTemp = "Data" ;
  90.         }
  91.         sprintf( pszBuff , "%s%x" , pszTemp , m_VirtAdress ) ;
  92.         return pszBuff ;
  93.     }
  94. }
  95.  
  96. const char* CSymbol::GetDeclaration() const
  97. {
  98.     static char_buff pszBuff ;
  99.     char* pszCur = pszBuff ;
  100.     if( ( m_Attrib & fSymKnown != 0 ) 
  101.         && ( ( m_Attrib & fSymHidden ) == 0 ) )
  102.     {
  103.         if( ( m_Attrib & fSymFunc ) != 0 )
  104.         {
  105.             sprintf(pszCur  , "\n\n%s%s\n\n" ,ctePartSep , ctePartStLine ) ;
  106.             pszCur = pszBuff + strlen( pszBuff ) ;
  107.         }
  108.         if( ( m_Attrib & fSymPublic ) != 0 )
  109.         {
  110.             sprintf( pszCur , "public %s\n" , GetName() ) ;
  111.             pszCur = pszBuff + strlen( pszBuff ) ;
  112.         }
  113.         if( ( m_Attrib & fSymExtern ) != 0 )
  114.         {
  115.             const char* pszTmp = GetName() ;
  116.             sprintf( pszCur , "extern\t_imp__%s : dword\n%s equ _imp__%s\n\n" , pszTmp , pszTmp , pszTmp  ) ;    
  117.         }
  118.         else if( ( m_Attrib & fSymCode ) != 0 )
  119.         {        
  120.             if( ( m_Attrib & fSymFunc ) != 0 )
  121.                 sprintf(pszCur  , "%s :: ; proc near\n" , GetName() ) ;
  122.             else // jump
  123.                 sprintf( pszCur  , "%s ::\n", GetName() );            
  124.         }
  125.         else
  126.         {
  127.             sprintf( pszCur  , "%s", GetName() );
  128.         }
  129.     }
  130.     return pszBuff ;
  131. }
  132.  
  133.  
  134. CSymbol* CSymbol::GetSource() const 
  135. {    return 0 ;}
  136.  
  137.