Exetools  

Go Back   Exetools > General > General Discussion

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 02-28-2011, 03:31
dila dila is offline
Friend
 
Join Date: Jan 2010
Posts: 60
Rept. Given: 12
Rept. Rcvd 32 Times in 14 Posts
Thanks Given: 35
Thanks Rcvd at 74 Times in 20 Posts
dila Reputation: 32
It sounds like he wants reverse GetProcAddress. Like the sort of code "analysis" you find next to CALL instructions in OllyDbg.

I've been looking at doing this for adding details to beaengine output and it goes like this:
  • Subtract the CALL RVA back to the image base.
  • Then subtract it back to the import library FirstThunk base address (remember there are two IAT arrays for each module, the file one and the one that is fixed up at runtime). Divide by the sizeof each element (DWORD) to make it into a 0...N index into the IAT array.
  • Use that index to get the import name out of the library names array.
  • Then the code builds an OllyDbg style "Library.Func" or "Library.#Ordinal" string for asm comment.

Code:
QString importFromRva( const PeFile *peFile, uint64_t addr )
{
    if ( addr )
    {
        addr -= peFile->imageBase();
        addr = addr;

        for ( uint32_t lib = 0; lib < peFile->importLibraryCount(); ++lib )
        {
            PeFile::ImportLibrary library;
            if ( !peFile->importLibrary(&library,lib) )
            {
                continue;
            }

            uint32_t offset = addr - library.;

            offset /= sizeof(DWORD);

            if ( offset < peFile->importAddressCount(&library) )
            {
                PeFile::ImportAddress address;
                if ( peFile->importAddress(&address,&library,offset) )
                {
                    if ( address.name )
                    {
                        return QString(library.name).toUpper() + QString(".") + QString(address.name);
                    }
                    else // by ordinal
                    {
                        return QString(library.name).toUpper() + QString(".#") + QString::number(address.ordinal,16);
                    }
                }
            }
        }

    }

    return QString();
}
Reply With Quote
The Following User Gave Reputation+1 to dila For This Useful Post:
ahmadmansoor (02-28-2011)
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fake mac address theGate General Discussion 16 08-13-2022 10:12
Get real address of api not nt version Mahmoudnia General Discussion 18 05-23-2018 00:44
Finding API Address britedream General Discussion 5 10-05-2006 21:28
how to get the address of the entry point in an API Warren General Discussion 6 08-30-2005 16:18


All times are GMT +8. The time now is 19:08.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )