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