Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

symbols.cpp

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2003 Frediano Ziglio
00004 -----
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 -----
00020 
00021 INFORMATION
00022   www: https://freddy77.tripod.com/perdr/
00023   e-mail: freddy77@angelfire.com
00024 */
00025 #include "global.h"
00026 #ifdef HAVE_HDRSTOP
00027 #pragma hdrstop
00028 #endif
00029 
00030 #include <algorithm>
00031 #include <iostream>
00032 #include "symbols.h"
00033 #include "apicache.h"
00034 
00035 using namespace std;
00036 
00037 // !!! sebbene il costruttore sia vuoto e' bene non renderlo inline
00038 Symbols::Symbols()
00039 {
00040 }
00041 
00042 
00043 pair<Symbols::iterator,Symbols::iterator> Symbols::operator[](vma_t address) const
00044 {
00045   iterator begin = symbols.lower_bound(Symbol(address,""));
00046   iterator end   = begin;
00047   
00048   // usually do one loop, so do not use strange method
00049   for(; end != symbols.end() ; ++end)
00050     if ( (*end).address != address )
00051       break;
00052   _PRG_ASSERT( begin == symbols.end() || (*begin).address >= address );
00053   _DEBUG_(iterator tmp = begin);
00054   _PRG_ASSERT( tmp == symbols.begin() || (*--tmp).address < address );
00055   _PRG_ASSERT( end == symbols.end() || begin == end || (*end).address > address );
00056   if( end == symbols.end() || begin == end || (*end).address > address ) ;
00057     else { cerr << "Address=" << address << " end Address=" << (*end).address << " end Name=" << (*end).name << endl; _PRG_ASSERT(0); }
00058   _DEBUG_( tmp = end );
00059   _PRG_ASSERT( tmp == symbols.begin() || begin == end || (*--tmp).address == address );
00060   return pair<iterator,iterator>(begin,end);
00061 }
00062 
00063 bool Symbols::IsValid(vma_t address) const
00064 {
00065   pair<iterator,iterator> apis = (*this)[address];
00066   if ( apis.first != apis.second )
00067         return true;
00068   return false;
00069 }
00070 
00071 void Symbols::insert(const std::string& name,vma_t address)
00072 {
00073         symbols.insert(Symbol(address,name));
00074 }
00075 
00076 vma_t Symbols::GetNextValid(vma_t address) const
00077 {
00078   iterator i = symbols.lower_bound(Symbol(address+1,""));
00079   if ( i == symbols.end() )
00080     return 0;
00081   _PRG_ASSERT( (*i).address > address );
00082   return (*i).address;
00083 }
00084 
00085 void SymbolsAddImport(uint32_t address,uint32_t hint,const char* dll_name,const char* func_name,void* param)
00086 {
00087   if (address != 0)
00088   {
00089         SymbolsAddImportParam *p = (SymbolsAddImportParam*)param;
00090     char s[10]; // !!! constant
00091     std::string name(dll_name);
00092     name += ".";
00093     if (func_name != NULL)
00094       name += func_name;
00095     else
00096     {
00097       // name += itoa(hint,s,10);
00098       sprintf(s,"%i",hint);
00099       name += s; //itoa(hint,s,10);
00100       
00101       std::string fullName;
00102       if (ApiCache::GetFullApiName(fullName,dll_name,hint))
00103       {
00104         name += " (";
00105                                 name += fullName;
00106                                 name += ")";
00107       }
00108     }
00109     p->symbols->insert(name,address+p->imageBase);
00110   }
00111 }
00112 

Generated on Mon Jan 13 22:20:34 2003 for perdr by doxygen1.2.15