|
|
|
@ -6,8 +6,11 @@
|
|
|
|
|
#include <algorithm> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
|
|
#ifdef WIN32 |
|
|
|
|
#include <windows.h> |
|
|
|
|
|
|
|
|
|
extern "C" IMAGE_DOS_HEADER __ImageBase; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
@ -151,7 +154,7 @@ private:
|
|
|
|
|
parse( 'H' ); |
|
|
|
|
char buf[256]; |
|
|
|
|
m_file.readString( buf, sizeof(buf) ); |
|
|
|
|
segments.add( MapFileEntry(seg,offs,len,buf) ); |
|
|
|
|
segments.add( MapFileEntry(seg,offs,len,buf,0) ); |
|
|
|
|
|
|
|
|
|
// break at empty line
|
|
|
|
|
if ( nextLineEmpty() ) |
|
|
|
@ -212,8 +215,9 @@ private:
|
|
|
|
|
entryname = newName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
long rvabase = m_file.readHex(); |
|
|
|
|
|
|
|
|
|
entries.add( MapFileEntry(seg,offs,0,entryname) ); |
|
|
|
|
entries.add( MapFileEntry(seg,offs,0,entryname,rvabase) ); |
|
|
|
|
|
|
|
|
|
// break at empty line
|
|
|
|
|
if ( nextLineEmpty() ) |
|
|
|
@ -271,26 +275,21 @@ int MapFile::line() const
|
|
|
|
|
|
|
|
|
|
int MapFile::findEntry( long addr ) const |
|
|
|
|
{ |
|
|
|
|
for ( int j = 0 ; j < segments() ; ++j ) |
|
|
|
|
{ |
|
|
|
|
const MapFileEntry& segment = getSegment( j ); |
|
|
|
|
long section = segment.section(); |
|
|
|
|
long segmentBegin = loadAddress() + (segment.section() << 12) + segment.offset(); |
|
|
|
|
long segmentEnd = segmentBegin + segment.length(); |
|
|
|
|
#ifdef WIN32 |
|
|
|
|
// Cope with Windows ASLR. Note that these operations are not commutative.
|
|
|
|
|
addr -= (long)&__ImageBase; |
|
|
|
|
addr += loadAddress(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if ( addr >= segmentBegin && addr < segmentEnd ) |
|
|
|
|
{ |
|
|
|
|
for ( int i = entries()-1 ; i >= 0 ; --i ) |
|
|
|
|
{ |
|
|
|
|
const MapFileEntry entry = getEntry( i ); |
|
|
|
|
if ( entry.section() == section ) |
|
|
|
|
{ |
|
|
|
|
long entryAddr = loadAddress() + (entry.section() << 12) + entry.offset(); |
|
|
|
|
if ( entryAddr <= addr ) |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// The code before ASLR-proofing tried to compute things by segment.
|
|
|
|
|
// It didn't work for whatever reason, so here's something simpler
|
|
|
|
|
// by address. Just be sure to toss anything larger than the
|
|
|
|
|
// highest address we know about.
|
|
|
|
|
if (addr == 0 || addr > getEntry(entries() - 1).rvabase()) |
|
|
|
|
return -1; |
|
|
|
|
for (int i = entries() - 1; i >= 0; --i) { |
|
|
|
|
if (getEntry(i).rvabase() <= addr) |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|