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 #if defined(_MSC_VER) && _MSC_VER <= 1200
00032 #pragma warning(disable:4786)
00033 #endif
00034
00035 #include "BinaryFile.h"
00036 #include <iostream>
00037 #include <stdio.h>
00038
00039
00040 BinaryFile::BinaryFile(bool bArch )
00041 {
00042 m_bArchive = bArch;
00043 m_iNumSections = 0;
00044 m_pSections = 0;
00045 }
00046
00047
00048
00049 SectionInfo::SectionInfo() :
00050 pSectionName(NULL), uNativeAddr(0), uHostAddr(0), uSectionSize(0), uSectionEntrySize(0), uType(0),
00051 bCode(false), bData(false), bBss(0), bReadOnly(0)
00052 {}
00053
00054 SectionInfo::~SectionInfo()
00055 {}
00056
00057 int BinaryFile::GetNumSections() const
00058 {
00059 return m_iNumSections;
00060 }
00061
00062 PSectionInfo BinaryFile::GetSectionInfo(int idx) const
00063 {
00064 return m_pSections + idx;
00065 }
00066
00067 int BinaryFile::GetSectionIndexByName(const char* sName)
00068 {
00069 for (int i=0; i < m_iNumSections; i++)
00070 {
00071 if (strcmp(m_pSections[i].pSectionName, sName) == 0)
00072 {
00073 return i;
00074 }
00075 }
00076 return -1;
00077 }
00078
00079 PSectionInfo BinaryFile::GetSectionInfoByAddr(ADDRESS uEntry) const
00080 {
00081 PSectionInfo pSect;
00082 for (int i=0; i < m_iNumSections; i++)
00083 {
00084 pSect = &m_pSections[i];
00085 if ((uEntry >= pSect->uNativeAddr) &&
00086 (uEntry < pSect->uNativeAddr + pSect->uSectionSize))
00087 {
00088
00089 return pSect;
00090 }
00091 }
00092
00093 return NULL;
00094 }
00095
00096 PSectionInfo BinaryFile::GetSectionInfoByName(const char* sName)
00097 {
00098 int i = GetSectionIndexByName(sName);
00099 if (i == -1) return 0;
00100 return &m_pSections[i];
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 const char* BinaryFile::SymbolByAddress(ADDRESS uNative) {
00110 return 0;
00111 }
00112
00113 ADDRESS BinaryFile::GetAddressByName(const char* pName, bool bNoTypeOK) {
00114 return 0;
00115 }
00116
00117 int BinaryFile::GetSizeByName(const char* pName, bool bNoTypeOK) {
00118 return 0;
00119 }
00120
00121 bool BinaryFile::IsDynamicLinkedProc(ADDRESS uNative) {
00122 return false;
00123 }
00124
00125 bool BinaryFile::IsStaticLinkedLibProc(ADDRESS uNative) {
00126 return false;
00127 }
00128
00129 bool BinaryFile::IsDynamicLinkedProcPointer(ADDRESS uNative)
00130 {
00131 return false;
00132 }
00133
00134 ADDRESS BinaryFile::IsJumpToAnotherAddr(ADDRESS uNative)
00135 {
00136 return NO_ADDRESS;
00137 }
00138
00139 const char *BinaryFile::GetDynamicProcName(ADDRESS uNative)
00140 {
00141 return "dynamic";
00142 }
00143
00144 bool BinaryFile::DisplayDetails(const char* fileName, FILE* f )
00145 {
00146 return false;
00147
00148
00149
00150 }
00151
00152
00153
00154
00155
00156 std::pair<unsigned,unsigned> BinaryFile::GetGlobalPointerInfo()
00157 {
00158 return std::pair<unsigned, unsigned>(0, 0);
00159 }
00160
00161
00162
00163
00164 std::map<ADDRESS, const char*>* BinaryFile::GetDynamicGlobalMap()
00165 {
00166 return new std::map<ADDRESS, const char*>;
00167 }
00168
00169
00170 ADDRESS* BinaryFile::GetImportStubs(int& numExports)
00171 {
00172 numExports = 0;
00173 return NULL;
00174 }
00175
00176 void BinaryFile::getTextLimits()
00177 {
00178 int n = GetNumSections();
00179 limitTextLow = 0xFFFFFFFF;
00180 limitTextHigh = 0;
00181 textDelta = 0;
00182 for (int i=0; i < n; i++) {
00183 SectionInfo* pSect = GetSectionInfo(i);
00184 if (pSect->bCode) {
00185
00186
00187
00188
00189 if (strcmp(".plt", pSect->pSectionName) == 0)
00190 continue;
00191 if (pSect->uNativeAddr < limitTextLow)
00192 limitTextLow = pSect->uNativeAddr;
00193 ADDRESS hiAddress = pSect->uNativeAddr + pSect->uSectionSize;
00194 if (hiAddress > limitTextHigh)
00195 limitTextHigh = hiAddress;
00196 if (textDelta == 0)
00197 textDelta = pSect->uHostAddr - pSect->uNativeAddr;
00198 else {
00199 if (textDelta != (int) (pSect->uHostAddr - pSect->uNativeAddr))
00200 std::cerr << "warning: textDelta different for section " << pSect->pSectionName <<
00201 " (ignoring).\n";
00202 }
00203 }
00204 }
00205 }