00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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];
00091 std::string name(dll_name);
00092 name += ".";
00093 if (func_name != NULL)
00094 name += func_name;
00095 else
00096 {
00097
00098 sprintf(s,"%i",hint);
00099 name += s;
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