3F / DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
MIT License
968 stars 133 forks source link

Mimic ordinal counter (start from 1 instead of 0) #8

Closed OmegaExtern closed 8 years ago

OmegaExtern commented 8 years ago

I think the title says it all. Ordinal is not as index, thus it should start counting from 1 rather than 0. Open any native Windows DLL with dumpbin /EXPORTS (or use PE explorer program), and you will notice that ordinal always starts from 1.

3F commented 8 years ago

Where you found problems with ordinals ? :)

or you need also the DllMain features (#5) ?

In Conari engine I implemented simplified work with export table of PE data for native features between C# and C++ (binding from any exported functions of libraries etc.):

typedef struct _IMAGE_EXPORT_DIRECTORY {
    DWORD   Characteristics;
    DWORD   TimeDateStamp;
    WORD    MajorVersion;
    WORD    MinorVersion;
    DWORD   Name;
    DWORD   Base;
    DWORD   NumberOfFunctions;
    DWORD   NumberOfNames;
    DWORD   AddressOfFunctions;     // RVA from base of image
    DWORD   AddressOfNames;         // RVA from base of image
    DWORD   AddressOfNameOrdinals;  // RVA from base of image
} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;

addressofnameordinals

but important note:

DWORD Base
    The starting ordinal number for exported functions. For example, if the file exports functions with ordinal values of 10, 11, and 12, this field contains 10. To obtain the exported ordinal for a function, you need to add this value to the appropriate element of the AddressOfNameOrdinals array. 

 *AddressOfNameOrdinals
    This field is an RVA and points to an array of WORDs. The WORDs are the export ordinals of all the exported functions in this module. However, don't forget to add in the starting ordinal number specified in the Base field.

and yes, the DllExport uses native ILasm features - see .export directive (v-table, flags, fixups etc. will be generated automatically by the compiler)

.export [<ordinal>] as <export_name>

read also my short explanation here

OmegaExtern commented 8 years ago

Where you found problems with ordinals ? :)

Export ordinals are 1-based, it is the common practice.

and yes, the DllExport uses native ILasm features

Yeah, I know how this works, in fact I have made my own "DllExporter"..

3F commented 8 years ago

it is the common practice.

and ?

Vasya Pupkin loves start from 5 and hates a common practice at all... and ?

You need add 4-bytes value from offset 0x10 to each element of the AddressOfNameOrdinals.

Read more from Matt Pietrek.

If this value does not match at all ... please, say simply, this is it.

I will check it later.

I have made my own "DllExporter"..

ok.