Changeset 84636 in webkit


Ignore:
Timestamp:
Apr 22, 2011 9:45:49 AM (13 years ago)
Author:
Adam Roben
Message:

Add code to enumerate all the functions imported by a particular Windows binary

PEImage is where all the logic starts. It represents a single Portable Executable (PE)
binary. The various enumerator classes are used in conjunction with PEImage to enumerate the
modules and functions imported by that image.

I couldn't figure out how to write a test for this. :-(

Part of <http://webkit.org/b/51063> <rdar://problem/8769281> REGRESSION (WebKit2): No
context menu appears when right-clicking on windowless Flash plugin

Reviewed by Sam Weinig, and given a good once-over by Jeff Miller.

  • WebCore.vcproj/WebCore.vcproj: Added the new files.
  • platform/win/PEImage.cpp: Added.

(WebCore::PEImage::PEImage): Checks that the module contains the expected magic numbers,
then initializes m_ntHeaders using the module.
(WebCore::PEImage::convertRVAToAddress): Converts a relative virtual address (RVA) to a
non-relative address, which can then be dereferenced. (The PE format uses RVAs in lots of
places.)
(WebCore::PEImage::dataDirectoryEntryAddress): Returns the address of the data associated
with the given entry in the image's DataDirectory.

  • platform/win/PEImage.h: Added.

(WebCore::PEImage::isValid): We're a valid image if the validation code in our constructor
succeeded, in which case m_ntHeaders will be set.

  • platform/win/ImportedFunctionsEnumerator.cpp: Added. This class enumerates all the

functions imported by the image from a single module by walking the Import Name Table (INT)
and Import Address Table (IAT).
(WebCore::ImportedFunctionsEnumerator::ImportedFunctionsEnumerator): Initialize our members.
(WebCore::ImportedFunctionsEnumerator::isAtEnd): The INT and IAT are both 0-terminated
arrays.
(WebCore::ImportedFunctionsEnumerator::next): Step to the next entries in the INT and IAT.
(WebCore::ImportedFunctionsEnumerator::currentFunctionName): Gets the address of the
function's name, if possible, using the INT.
(WebCore::ImportedFunctionsEnumerator::addressOfCurrentFunctionPointer): Returns the address
of the function pointer for the current function. This function pointer is used whenever
code in m_image calls the current function. (A future patch will take advantage of this by
overwriting this function pointer with another, thereby redirecting calls to that function.)

  • platform/win/ImportedFunctionsEnumerator.h: Added.
  • platform/win/ImportedModulesEnumeratorBase.h: Added. This base class is used by

ImportedModulesEnumerator and DelayLoadedModulesEnumerator, and allows code to be written
that works with either one.

  • platform/win/ImportedModulesEnumerator.cpp: Added. This class enumerates all the

non-delay-loaded modules imported by the image by walking the image's import array.
(WebCore::ImportedModulesEnumerator::ImportedModulesEnumerator): Module import information
is stored in the IMAGE_DIRECTORY_ENTRY_IMPORT entry of the image's DataDirectory.
(WebCore::ImportedModulesEnumerator::isAtEnd): The import array is 0-terminated.
(WebCore::ImportedModulesEnumerator::next): Steps along the import array.
(WebCore::ImportedModulesEnumerator::currentModuleName): Gets the address of the module's
name.
(WebCore::ImportedModulesEnumerator::functionsEnumerator): Get's the addresses of the INT
and IAT for this module and wraps them in an ImportedFunctionsEnumerator.

  • platform/win/ImportedModulesEnumerator.h: Added.
  • platform/win/DelayLoadedModulesEnumerator.cpp: Added. This class enumerates all the

delay-loaded modules that are imported by the given PEImage by walking the image's
ImageDelayDescr array.
(WebCore::DelayLoadedModulesEnumerator::DelayLoadedModulesEnumerator): Delay-load
information is stored in the IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT entry of the image's
DataDirectory.
(WebCore::DelayLoadedModulesEnumerator::isAtEnd): The delay-loaded modules array is
0-terminated.
(WebCore::DelayLoadedModulesEnumerator::next): Steps along the delay-loaded modules array.
(WebCore::DelayLoadedModulesEnumerator::currentModuleName): Gets the address of the module's
name out of the descriptor.
(WebCore::DelayLoadedModulesEnumerator::functionsEnumerator): Gets the INT and IAT for the
current module out of the descriptor and makes an ImportedFunctionsEnumerator from them.
(WebCore::DelayLoadedModulesEnumerator::convertPotentialRVAToAddress): Pre-VC7.0 images
stored non-relative addresses in the ImageDelayDescr structures, while VC7.0 and later
images store RVAs. This function abstracts away the difference.

  • platform/win/DelayLoadedModulesEnumerator.h: Added.
Location:
trunk/Source/WebCore
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r84635 r84636  
     12011-04-21  Adam Roben  <aroben@apple.com>
     2
     3        Add code to enumerate all the functions imported by a particular Windows binary
     4
     5        PEImage is where all the logic starts. It represents a single Portable Executable (PE)
     6        binary. The various enumerator classes are used in conjunction with PEImage to enumerate the
     7        modules and functions imported by that image.
     8
     9        I couldn't figure out how to write a test for this. :-(
     10
     11        Part of <http://webkit.org/b/51063> <rdar://problem/8769281> REGRESSION (WebKit2): No
     12        context menu appears when right-clicking on windowless Flash plugin
     13
     14        Reviewed by Sam Weinig, and given a good once-over by Jeff Miller.
     15
     16        * WebCore.vcproj/WebCore.vcproj: Added the new files.
     17
     18        * platform/win/PEImage.cpp: Added.
     19        (WebCore::PEImage::PEImage): Checks that the module contains the expected magic numbers,
     20        then initializes m_ntHeaders using the module.
     21        (WebCore::PEImage::convertRVAToAddress): Converts a relative virtual address (RVA) to a
     22        non-relative address, which can then be dereferenced. (The PE format uses RVAs in lots of
     23        places.)
     24        (WebCore::PEImage::dataDirectoryEntryAddress): Returns the address of the data associated
     25        with the given entry in the image's DataDirectory.
     26
     27        * platform/win/PEImage.h: Added.
     28        (WebCore::PEImage::isValid): We're a valid image if the validation code in our constructor
     29        succeeded, in which case m_ntHeaders will be set.
     30
     31        * platform/win/ImportedFunctionsEnumerator.cpp: Added. This class enumerates all the
     32        functions imported by the image from a single module by walking the Import Name Table (INT)
     33        and Import Address Table (IAT).
     34        (WebCore::ImportedFunctionsEnumerator::ImportedFunctionsEnumerator): Initialize our members.
     35        (WebCore::ImportedFunctionsEnumerator::isAtEnd): The INT and IAT are both 0-terminated
     36        arrays.
     37        (WebCore::ImportedFunctionsEnumerator::next): Step to the next entries in the INT and IAT.
     38        (WebCore::ImportedFunctionsEnumerator::currentFunctionName): Gets the address of the
     39        function's name, if possible, using the INT.
     40        (WebCore::ImportedFunctionsEnumerator::addressOfCurrentFunctionPointer): Returns the address
     41        of the function pointer for the current function. This function pointer is used whenever
     42        code in m_image calls the current function. (A future patch will take advantage of this by
     43        overwriting this function pointer with another, thereby redirecting calls to that function.)
     44
     45        * platform/win/ImportedFunctionsEnumerator.h: Added.
     46
     47        * platform/win/ImportedModulesEnumeratorBase.h: Added. This base class is used by
     48        ImportedModulesEnumerator and DelayLoadedModulesEnumerator, and allows code to be written
     49        that works with either one.
     50
     51        * platform/win/ImportedModulesEnumerator.cpp: Added. This class enumerates all the
     52        non-delay-loaded modules imported by the image by walking the image's import array.
     53        (WebCore::ImportedModulesEnumerator::ImportedModulesEnumerator): Module import information
     54        is stored in the IMAGE_DIRECTORY_ENTRY_IMPORT entry of the image's DataDirectory.
     55        (WebCore::ImportedModulesEnumerator::isAtEnd): The import array is 0-terminated.
     56        (WebCore::ImportedModulesEnumerator::next): Steps along the import array.
     57        (WebCore::ImportedModulesEnumerator::currentModuleName): Gets the address of the module's
     58        name.
     59        (WebCore::ImportedModulesEnumerator::functionsEnumerator): Get's the addresses of the INT
     60        and IAT for this module and wraps them in an ImportedFunctionsEnumerator.
     61
     62        * platform/win/ImportedModulesEnumerator.h: Added.
     63
     64        * platform/win/DelayLoadedModulesEnumerator.cpp: Added. This class enumerates all the
     65        delay-loaded modules that are imported by the given PEImage by walking the image's
     66        ImageDelayDescr array.
     67        (WebCore::DelayLoadedModulesEnumerator::DelayLoadedModulesEnumerator): Delay-load
     68        information is stored in the IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT entry of the image's
     69        DataDirectory.
     70        (WebCore::DelayLoadedModulesEnumerator::isAtEnd): The delay-loaded modules array is
     71        0-terminated.
     72        (WebCore::DelayLoadedModulesEnumerator::next): Steps along the delay-loaded modules array.
     73        (WebCore::DelayLoadedModulesEnumerator::currentModuleName): Gets the address of the module's
     74        name out of the descriptor.
     75        (WebCore::DelayLoadedModulesEnumerator::functionsEnumerator): Gets the INT and IAT for the
     76        current module out of the descriptor and makes an ImportedFunctionsEnumerator from them.
     77        (WebCore::DelayLoadedModulesEnumerator::convertPotentialRVAToAddress): Pre-VC7.0 images
     78        stored non-relative addresses in the ImageDelayDescr structures, while VC7.0 and later
     79        images store RVAs. This function abstracts away the difference.
     80
     81        * platform/win/DelayLoadedModulesEnumerator.h: Added.
     82
    1832011-04-21  Adam Roben  <aroben@apple.com>
    284
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r84635 r84636  
    2649826498                                </File>
    2649926499                                <File
     26500                                        RelativePath="..\platform\win\DelayLoadedModulesEnumerator.cpp"
     26501                                        >
     26502                                </File>
     26503                                <File
     26504                                        RelativePath="..\platform\win\DelayLoadedModulesEnumerator.h"
     26505                                        >
     26506                                </File>
     26507                                <File
    2650026508                                        RelativePath="..\platform\win\DragDataWin.cpp"
    2650126509                                        >
     
    2658626594                                </File>
    2658726595                                <File
     26596                                        RelativePath="..\platform\win\ImportedFunctionsEnumerator.cpp"
     26597                                        >
     26598                                </File>
     26599                                <File
     26600                                        RelativePath="..\platform\win\ImportedFunctionsEnumerator.h"
     26601                                        >
     26602                                </File>
     26603                                <File
     26604                                        RelativePath="..\platform\win\ImportedModulesEnumerator.cpp"
     26605                                        >
     26606                                </File>
     26607                                <File
     26608                                        RelativePath="..\platform\win\ImportedModulesEnumerator.h"
     26609                                        >
     26610                                </File>
     26611                                <File
     26612                                        RelativePath="..\platform\win\ImportedModulesEnumeratorBase.h"
     26613                                        >
     26614                                </File>
     26615                                <File
    2658826616                                        RelativePath="..\platform\win\KeyEventWin.cpp"
    2658926617                                        >
     
    2661526643                                <File
    2661626644                                        RelativePath="..\platform\win\PathWalker.h"
     26645                                        >
     26646                                </File>
     26647                                <File
     26648                                        RelativePath="..\platform\win\PEImage.cpp"
     26649                                        >
     26650                                </File>
     26651                                <File
     26652                                        RelativePath="..\platform\win\PEImage.h"
    2661726653                                        >
    2661826654                                </File>
Note: See TracChangeset for help on using the changeset viewer.