Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
OmegaExtern opened this issue Sep 7, 2016 · 3 comments
Closed

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

OmegaExtern opened this issue Sep 7, 2016 · 3 comments
Milestone

Comments

@OmegaExtern
Copy link

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
Copy link
Owner

3F commented Sep 7, 2016

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
Copy link
Author

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
Copy link
Owner

3F commented Sep 22, 2016

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.

@OmegaExtern OmegaExtern changed the title Ordinals should start from one (1), not zero (0) Mimic ordinal counter (start from 1 instead of 0) Sep 23, 2016
@3F 3F added suggestion and removed unclear labels Sep 23, 2016
3F added a commit that referenced this issue Sep 30, 2016
3F added a commit that referenced this issue Oct 1, 2016
The one (1) now is used by default as Base for all ordinals #8

There is also alternative to configure this number - MSBuild property: DllExportOrdinalsBase
@3F 3F added this to the v1.4 milestone Oct 1, 2016
@3F 3F closed this as completed Oct 4, 2016
3F added a commit that referenced this issue Oct 5, 2016
    * FIXED: Fixed bug - `An item with the same key has already been added`. Issue #10
    * FIXED: Bug with Meta library: Incorrect default values. Issue #16
             please note, the __cdecl is the default calling convention for our library
             as and for C and C++ programs.

    * FIXED?: Probably fixed bug - `Script errors on package install` Issue #6
    * FIXED?: Probably fixed bug - `non-English system language - syntax error` Issue #7
    * NEW: GUI Configurator with updated ddNS features.
    * NEW: Implemented feature 'Export for platform': [ x86 / x64 / x86 + x64 ] Issue #9
    * NEW: Implemented feature 'Base for ordinals'. Issue #11
           There is also alternative to configure this number - MSBuild property: DllExportOrdinalsBase

    * NEW: The one (1) now is used by default as Base for all ordinals.
           `Mimic ordinal counter (start from 1 instead of 0)` Issue #8

    * CHANGED: The ddNS features now as binary cmdlet `NSBin`. Use `nsbin.bat` if needed.
    * CHANGED: `Set "Inherited = false" in AttributeUsage for DllExportAttribute`. Issue #15
    * OTHER: other possible changes and fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants