Skip to content

3F/DllExport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.NET DllExport

Copyright (c) 2009-2015  Robert Giesecke
Copyright (c) 2016-2020  Denis Kuzmin < x-3F@outlook.com > GitHub/3F

Build status Latest-Release License coreclr_ILAsm Cecil MvsSln GetNuTool hMSBuild Conari

Build history

DllExport -action Configure [?]

[ Quick start ] [ Examples: C++, C#, Java ] -> { Wiki }

~ ~ ~ --- ~ ~ ~

[DllExport]
public static int entrypoint(IntPtr L)
{
    // ... it will be called from Lua script

    lua_pushcclosure(L, onProc, 0);
    lua_setglobal(L, "onKeyDown");

    return 0;
}
  • For work with Unmanaged memory including native or binary data from the heap and binding between .NET and unmanaged native C/C++ etc, use Conari
  • For related work with Lua (5.4, 5.3, 5.2, 5.1, ...), use LuNari
[DllExport("Init", CallingConvention.Cdecl)]
// __cdecl is the default calling convention for our library
[DllExport(CallingConvention.StdCall)]
[DllExport("MyFunc")]
[DllExport]

We're supporting the following PE modules: Library (.dll) and Executable (.exe) [?]

v1.2+ provides dynamic definitions of namespaces (ddNS feature):

    Via Cecil or direct modification:

    000005B0                 00 C4 7B 01 00 00 00 2F 00 12 05       .Д{..../...
    000005C0  00 00 02 00 00 00 00 00 00 00 00 00 00 00 26 00  ..............&.
    000005D0  20 02 00 00 00 00 00 00 00 49 2E 77 61 6E 74 2E   ........I.want.   <<<-
    000005E0  74 6F 2E 66 6C 79 00 00 00 00 00 00 00 00 00 00  to.fly..........  <<<-


Initially the original tool UnmanagedExports was distributed by Robert Giesecke as an closed-source tool under the MIT License:

Now, we will be more open ! all details here

License

The MIT License (MIT)

.NET DllExport contributors: https://github.com/3F/DllExport/graphs/contributors

&_

How does it work

Current features has been implemented through ILDasm & ILAsm that prepares the all required steps via .export directive (it's specific directive for ILAsm compiler only).

What inside ? or how does work the .export directive ?

Read about format PE32/PE32+, start with grammar from asmparse and move to writer:

...
//yacc
if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
{
  PASM->m_pCurMethod->m_dwExportOrdinal = $3;
  PASM->m_pCurMethod->m_szExportAlias = $6;
  if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
  if(PASM->m_pCurMethod->m_wVTSlot  == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000;
}
...
EATEntry*   pEATE = new EATEntry;
pEATE->dwOrdinal = pMD->m_dwExportOrdinal;
pEATE->szAlias = pMD->m_szExportAlias ? pMD->m_szExportAlias : pMD->m_szName;
pEATE->dwStubRVA = EmitExportStub(pGlobalLabel->m_GlobalOffset+dwDelta);
m_EATList.PUSH(pEATE);
...
// logic of definition of records into EXPORT_DIRECTORY (see details from PE format)
HRESULT Assembler::CreateExportDirectory()  
{
...
    IMAGE_EXPORT_DIRECTORY  exportDirIDD;
    DWORD                   exportDirDataSize;
    BYTE                   *exportDirData;
    EATEntry               *pEATE;
    unsigned                i, L, ordBase = 0xFFFFFFFF, Ldllname;
    ...
    ~ now we're ready to miracles ~

Read also my brief explanations here: AssemblyRef encoding / about mscoree / DllMain & the export-table / DllExport.dll / ordinals ...

How to get DllExport

tl;dr: put this inside solution folder, then click it there.

Since v1.6+ have no official support of NuGet clients ([?]), you need just use this inside your solution folder. Wiki: [ Quick start ]

Get our manager (~19 Kbytes) from any trusted place. Official GHR is recommended. But you can also get it from official packages via NuGet server NuGet package, etc.

[ Documentation ]

DllExport.bat

Other way:

  • gnt /p:ngpackages="DllExport" [?]
    • GetNuTool: msbuild gnt.core /p:ngpackages="DllExport" or gnt /p:ngpackages="DllExport"
  • (deprecated) NuGet PM: Install-Package DllExport
  • (deprecated) NuGet Commandline: nuget install DllExport
  • GHR Stable: /releases [ latest stable ]
  • CI builds: /artifacts page ( old CI ) or find 🎲 CI build on GitHub Releases page.

How to Build .NET DllExport

Just use build.bat if you need final binaries (NuGet package as DllExport.<version>.nupkg, Manager, zip-archives, and others).

.\build

Part of this build scripts works via vssbe (?) and for build via console (including CI etc.) uses CIM version of this. You do not need anything else, just type build.

For Visual Studio use this vsix version for IDE

How to Debug

Wizard through MSBuild, for example:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

Arguments:

"net.r_eg.DllExport.Wizard.targets" /p:wRootPath="<...>" 
/p:wSlnFile="<SolutionFile_for_debugging>.sln" /p:wAction="Configure" 
/p:wPkgPath=packages/DllExport<version>

Working directory:

<path_to>\packages\DllExport<version>\tools

DllExport.MSBuild, for example:

C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe

Arguments:

"<path_to_SolutionFile_for_debugging>.sln" /t:Build /p:Configuration=<Configuration>

use additional Diagnostic key to msbuild if you need more details:

"<SolutionFile>.sln" /verbosity:Diagnostic /t:Rebuild /p:Configuration=<Configuration>

Now you can debug at runtime.

coreclr ILAsm / ILDasm

We're using our custom versions on coreclr specially for our .NET DllExport project - https://github.com/3F/coreclr

This helps to avoid some problems (like this, or this) and more...

To build minimal version (it will not include all components as for original coreclr repo):

git submodule update --init --recursive

Make sure that you have installed CMake, then build simply:

build-s -all -x86 -x64 Release

or use

build-coreclr-ilasm-x64.cmd
build-coreclr-ilasm-x86+x64.cmd

You can also use our compiled versions:

  • NuGet package

Donation

Please note again, the UnmanagedExports was created by Robert Giesecke. You need visit his page.

But this repository does not related to Robert and generally still being developed by GitHub/3F developer (Follow the news: [ GitHub ]; [ twitter ]).

If something is helpful from 3F/DllExport, donations are welcomed, and thanks !

[ ☕ Donate ]