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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #if !defined(_Object_nt_h_)
00039 #define _Object_nt_h_
00040
00041
00042
00043
00044
00045
00046
00047 #include "common/h/Types.h"
00048 #include <vector>
00049 #include <string>
00050 #include <algorithm>
00051 #include "symtabAPI/h/symutil.h"
00052
00053 #include <stdio.h>
00054 #include <stdlib.h>
00055 #define WIN32_LEAN_AND_MEAN
00056 #include <windows.h>
00057 #include <assert.h>
00058
00059 #if !defined(__out_ecount_opt)
00060 #define __out_ecount_opt(UNUSED)
00061 #endif
00062 #include <dbghelp.h>
00063
00064 namespace Dyninst{
00065 namespace SymtabAPI{
00066
00067 class ExceptionBlock;
00068
00069
00070
00071
00072
00073 class Object : public AObject
00074 {
00075 friend class Symtab;
00076 public:
00077 class intSymbol
00078 {
00079 private:
00080 std::string name;
00081 DWORD64 addr;
00082 DWORD type;
00083 DWORD linkage;
00084 DWORD size;
00085 Region *region;
00086
00087 public:
00088 intSymbol( std::string _name,
00089 DWORD64 _addr,
00090 DWORD _type,
00091 DWORD _linkage,
00092 DWORD _size,
00093 Region *_region)
00094 : name(_name),
00095 addr(_addr),
00096 type(_type),
00097 linkage(_linkage),
00098 size(_size),
00099 region(_region)
00100 {}
00101
00102 std::string GetName( void ) const { return name; }
00103 DWORD64 GetAddr( void ) const { return addr; }
00104 DWORD GetSize( void ) const { return size; }
00105 DWORD GetType( void ) const { return type; }
00106 DWORD GetLinkage( void ) const { return linkage; }
00107 Region *GetRegion( void ) const { return region; }
00108 void SetSize( DWORD cb ) { size = cb; }
00109
00110 void DefineSymbol( dyn_hash_map<std::string, std::vector< Symbol *> >& syms,
00111 std::map<Symbol *, std::string> &symsToMods,
00112 const std::string& modName ) const;
00113 };
00114
00115 class File
00116 {
00117 private:
00118 std::string name;
00119 std::vector<intSymbol*> syms;
00120
00121 public:
00122 File( std::string _name = "" )
00123 : name(_name)
00124 {}
00125
00126 void AddSymbol( intSymbol* pSym )
00127 {
00128 syms.push_back( pSym );
00129 }
00130
00131 void DefineSymbols( dyn_hash_map<std::string, std::vector< Symbol *> >& syms,
00132 std::map<Symbol *, std::string> &symsToMods,
00133 const std::string& modName ) const;
00134 std::string GetName( void ) const { return name; }
00135 const std::vector<intSymbol*>& GetSymbols( void ) const { return syms; }
00136 };
00137
00138 class Module
00139 {
00140 private:
00141 std::string name;
00142 DWORD64 baseAddr;
00143 DWORD64 extent;
00144 bool isDll;
00145
00146 std::vector<File *> files;
00147 File* defFile;
00148
00149 void PatchSymbolSizes( const Object* obj,
00150 const std::vector<intSymbol*>& allSyms ) const;
00151
00152 public:
00153 Module( std::string name,
00154 DWORD64 baseAddr,
00155 DWORD64 extent = 0 );
00156
00157 File* GetDefaultFile( void ) { return defFile; }
00158 File* FindFile( std::string name );
00159 void AddFile( File* pFile ) { files.push_back( pFile ); }
00160
00161 void DefineSymbols( const Object* obj,
00162 dyn_hash_map<std::string, std::vector< Symbol *> > & syms,
00163 std::map<Symbol *, std::string> &symsToMods ) const;
00164 void BuildSymbolMap( const Object* obj ) const;
00165
00166 std::string GetName( void ) const { return name; }
00167 bool IsDll( void ) const { return isDll; }
00168 void SetIsDll( bool v ) { isDll = v; }
00169 };
00170
00171 private:
00172 Module* curModule;
00173
00174 public:
00175 SYMTAB_EXPORT Object(MappedFile *, bool defensive,
00176 void (*)(const char *) = log_msg, bool alloc_syms = true);
00177 SYMTAB_EXPORT Object(){};
00178
00179 SYMTAB_EXPORT virtual ~Object( void );
00180
00181 SYMTAB_EXPORT bool isForwarded( Offset addr );
00182 SYMTAB_EXPORT bool isEEL() const { return false; }
00183 SYMTAB_EXPORT bool isText( const Offset addr ) const;
00184 SYMTAB_EXPORT Offset get_base_addr() const { return (Offset)mf->base_addr();}
00185 SYMTAB_EXPORT Module* GetCurrentModule( void ) { return curModule; }
00186
00187 SYMTAB_EXPORT bool getCatchBlock(ExceptionBlock &b, Offset addr, unsigned size = 0) const;
00188 SYMTAB_EXPORT unsigned int GetTextSectionId( void ) const { return textSectionId;}
00189 SYMTAB_EXPORT PIMAGE_NT_HEADERS GetImageHeader( void ) const { return peHdr; }
00190 SYMTAB_EXPORT PVOID GetMapAddr( void ) const { return mf->base_addr(); }
00191 SYMTAB_EXPORT Offset getEntryPoint( void ) const { if (peHdr) return peHdr->OptionalHeader.AddressOfEntryPoint; return 0;}
00192
00193
00194 SYMTAB_EXPORT Offset getLoadAddress() const { return imageBase; }
00195 SYMTAB_EXPORT Offset getEntryAddress() const { return getEntryPoint(); }
00196 SYMTAB_EXPORT Offset getBaseAddress() const { return get_base_addr(); }
00197 SYMTAB_EXPORT Offset getTOCoffset(Offset ) const { return 0; }
00198 SYMTAB_EXPORT ObjectType objType() const;
00199 SYMTAB_EXPORT const char *interpreter_name() const { return NULL; }
00200 SYMTAB_EXPORT dyn_hash_map <std::string, LineInformation> &getLineInfo();
00201 SYMTAB_EXPORT void parseTypeInfo(Symtab *obj);
00202 SYMTAB_EXPORT virtual Dyninst::Architecture getArch();
00203 SYMTAB_EXPORT void ParseGlobalSymbol(PSYMBOL_INFO pSymInfo);
00204 SYMTAB_EXPORT const std::vector<Offset> &getPossibleMains() const { return possible_mains; }
00205 SYMTAB_EXPORT void getModuleLanguageInfo(dyn_hash_map<std::string, supportedLanguages> *mod_langs);
00206 SYMTAB_EXPORT bool emitDriver(Symtab *obj, std::string fName,
00207 std::vector<Symbol *>&allSymbols, unsigned flag);
00208 SYMTAB_EXPORT unsigned int getSecAlign() const {return SecAlignment;}
00209 SYMTAB_EXPORT void insertPrereqLibrary(std::string lib);
00210 virtual char *mem_image() const
00211 {
00212 assert(mf);
00213 return (char *)mf->base_addr();
00214 }
00215 void setTrapHeader(Offset ptr);
00216 Offset trapHeader();
00217
00218 SYMTAB_EXPORT DWORD ImageOffset2SectionNum(DWORD dwRO);
00219 SYMTAB_EXPORT PIMAGE_SECTION_HEADER ImageOffset2Section(DWORD dwRO);
00220 SYMTAB_EXPORT PIMAGE_SECTION_HEADER ImageRVA2Section(DWORD dwRVA);
00221 SYMTAB_EXPORT DWORD RVA2Offset(DWORD dwRVA);
00222 SYMTAB_EXPORT DWORD Offset2RVA(DWORD dwRO);
00223 SYMTAB_EXPORT void addReference(Offset, std::string, std::string);
00224 SYMTAB_EXPORT std::map<std::string, std::map<Offset, std::string> > & getRefs() { return ref; }
00225
00226 std::vector<std::pair<std::string, IMAGE_IMPORT_DESCRIPTOR> > & getImportDescriptorTable();
00227 std::map<std::string, std::map<std::string, WORD> > & getHintNameTable();
00228 PIMAGE_NT_HEADERS getPEHdr() { return peHdr; }
00229 void setTOCoffset(Offset) {};
00230 private:
00231 SYMTAB_EXPORT void ParseSymbolInfo( bool );
00232 SYMTAB_EXPORT void parseFileLineInfo(Symtab *, dyn_hash_map<std::string, LineInformation> &);
00233 SYMTAB_EXPORT void FindInterestingSections( bool, bool );
00234 Region * findEnclosingRegion(const Offset where);
00235 void AddTLSFunctions();
00236
00237 Offset baseAddr;
00238
00239 Offset imageBase;
00240
00241 PIMAGE_NT_HEADERS peHdr;
00242 Offset trapHeaderPtr_;
00243 unsigned int SecAlignment;
00244
00245
00246 std::vector<std::pair<std::string, IMAGE_IMPORT_DESCRIPTOR> > idt_;
00247 std::map<std::string, std::map<std::string, WORD> > hnt_;
00248
00249
00250 std::map<std::string,std::map<Offset, std::string> > ref;
00251
00252 unsigned int textSectionId;
00253 unsigned int dataSectionId;
00254
00255 HANDLE hProc;
00256 std::vector<Offset> possible_mains;
00257 };
00258
00259
00260
00261
00262
00263
00264
00265
00266 #if !defined(SYMFLAG_FUNCTION)
00267 # define SYMFLAG_FUNCTION SYMF_FUNCTION
00268 # define SYMFLAG_LOCAL SYMF_LOCAL
00269 # define SYMFLAG_PARAMETER SYMF_PARAMETER
00270 # define SYMFLAG_EXPORT SYMF_EXPORT
00271 #endif // !defined(SYMFLAG_FUNCTION)
00272
00273 }
00274 }
00275
00276 #endif