3F / Conari

🧬 One-touch unmanaged memory, runtime dynamic use of the unmanaged native C/C++ in .NET world, related P/Invoke features, and …
MIT License
252 stars 28 forks source link

Aliases for exported-functions and variables #9

Closed 3F closed 7 years ago

3F commented 7 years ago

hmm, just thought that is a good additional variant for: Undecorate functions from C++ compilers #3

Moreover, it will be useful for any other cases like for DllImport

[PrefixL]procName -> [PrefixR]alias1
                  -> [PrefixR]alias2

where PrefixL/R it's a main IProvider.Prefix if used
etc.

TODO

3F commented 7 years ago

I implemented the following:

using(var l = new ConariL(...))
{
    l.Aliases["getD_True"]  = "?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ";
    l.Aliases["getFlag"]    = l.Aliases["getD_True"]; // getFlag -> getD_True -> ...

    // ...

    l.DLR.getD_True<bool>();
    l.DLR.getFlag<bool>();
l.Aliases["HelloWorld"] = new ProcAlias("?HelloWorld@API@UnLib@Conari@r_eg@net@@YAPBDXZ");

l.DLR.HelloWorld<CharPtr>(); // "Hello World !"

Even for simple linkage, it easy as:

l.Aliases["Flag"] = l.Aliases["getFlag"] = l.Aliases["xFunc"]; //Flag() -> getFlag() -> xFunc()->...
l.DLR.getFlag<bool>();

l.Aliases["a"] = l.Aliases["b"] = l.Aliases["c"] = l.Aliases["d"];

the PrefixL/R features will be considered later via IAliasCfg:

public interface IAliasCfg
{
    //TODO: PrefixL/R, the rules of mangling, ...
}

upd.:

l.Aliases["gmn"] = new ProcAlias(
    "GetMagicNum",
    new AliasCfg() { NoPrefixR = true } // false by default
);