Git Product home page Git Product logo

conari's Introduction

Conari

Conari engine represents powerful platform for work with unmanaged memory, pe-modules, and their data: Libraries, Executable Modules, other native (C/C++, ...) and binary data.

Lightweight and flexible binding, even accessing to complex types like structures without their declaration at all. Also contains wrappers for types like unmanaged structures, unmanaged strings, and much more.

Build status release-src License NuGet package

1:[ Quick start ] 2:[ Basic examples for C++ and C# ] 3:[ Complex types and Strings ] -> { Wiki }

Easy to start:

using(var l = new ConariL("Library.dll")) {
    // ...
}

Conari is ready for any exported functions and variables immediately via ...

Dynamic features / DLR - fully automatic way:

var ptr     = d.test<IntPtr>(); //Lambda variant: l.bind<Func<IntPtr>>("test")();
var codec   = d.avcodec_find_encoder<IntPtr>(AV_CODEC_ID_MP2); //Lambda variant: l.bind<Func<ulong, IntPtr>>("avcodec_find_encoder")(AV_CODEC_ID_MP2);
              d.push(); //Lambda variant: l.bind<Action>("push")();
              d.create<int>(ref cid, out data); //Lambda variant: l.bind<MyFunc<Guid, object>>("create")(ref cid, out data);

It does not require the any configuration from you, because Conari will do it automatically. Easy and works well.

This works perfectly for most popular libraries like: Lua, 7-zip, FFmpeg, ...

Lambda expressions - semi-automatic way:

using(var c = new ConariL("Library.dll"))
{
    c.bind<Action<int, int>>("call")(2, 1); 
    double num = c.bind<Func<IntPtr, int, double>>("tonumber")(L, 4);
}

This also does not require the creation of any additional delegates. Just use bind<> methods with additional types and have fun!

c.bind<...>("function")
// you already may invoke it immediately as above:
c.bind<Action<int, string>>("set")(-1, "Hello from Conari !");

// or later:
var set = c.bind<Action<int, string>>("set");
...
set(-1, "Hello from Conari !");

Lazy loading:

using(var l = new ConariL(
                    new Config("Library.dll") {
                        LazyLoading = true
                    }))
{
    ...
}

Native C/C++ structures without declaration [?]:

// IMAGE_FILE_HEADER: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313.aspx
dynamic ifh = NativeData
                ._(data)
                .t<WORD, WORD>(null, "NumberOfSections")
                .align<DWORD>(3)
                .t<WORD, WORD>("SizeOfOptionalHeader")
                .Raw.Type;
                
if(ifh.SizeOfOptionalHeader == 0xE0) { // IMAGE_OPTIONAL_HEADER32
    ... 
}

// IMAGE_DATA_DIRECTORY: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680305.aspx
dynamic idd = (new NativeData(data))
                    .t<DWORD>("VirtualAddress") // idd.VirtualAddress
                    .t<DWORD>("Size")           // idd.Size
                    .Raw.Type;
IntPtr ptr ...
Raw mt = ptr.Native()
                .align<int>(2, "a", "b")
                .t<IntPtr>("name")
                .Raw;
            
-     {byte[0x0000000c]} byte[]
        [0]    0x05    byte --
        [1]    0x00    byte   |
        [2]    0x00    byte   |
        [3]    0x00    byte --^ a = 5
        [4]    0x07    byte --
        [5]    0x00    byte   |
        [6]    0x00    byte   |
        [7]    0x00    byte --^ b = 7
        [8]    0x20    byte --
        [9]    0x78    byte   |_ pointer to allocated string: (CharPtr)name
        [10]   0xf0    byte   |
        [11]   0x56    byte --
...

Calling Convention & Name-Decoration [?]:

using(var l = new ConariL("Library.dll", CallingConvention.StdCall))
{
    //...
    l.Mangling = true; // _get_SevenStdCall@0 <-> get_SevenStdCall
    l.Convention = CallingConvention.Cdecl;
}

Exported Variables & Raw access [?]:

// v1.3+
l.ExVar.DLR.ADDR_SPEC // 0x00001CE8
l.ExVar.get<UInt32>("ADDR_SPEC"); // 0x00001CE8
l.ExVar.getField(typeof(UInt32).NativeSize(), "ADDR_SPEC"); // Native.Core.Field via raw size
l.Svc.native("lpProcName"); // Raw access via NativeData & Native.Core !
//v1.0+: Use Provider or ConariL frontend via your custom wrapper.

Aliases for exported-functions and variables [?]:

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

Additional types:

  • BSTR, CharPtr, WCharPtr, float_t, int_t, ptrdiff_t, size_t, uint_t
  • UnmanagedString - allocation of the new unmanaged strings.
  • ...
size_t len;
CharPtr name = c.bind<FuncOut3<int, size_t, IntPtr>>("to")(1, out len);
string myName += name; // (IntPtr)name; .Raw; .Ansi; .Utf8; ...

Events:

l.ConventionChanged += (object sender, DataArgs<CallingConvention> e) =>
{
    DLR = newDLR(e.Data);
    LSender.Send(sender, $"DLR has been updated with new CallingConvention: {e.Data}", Message.Level.Info);
};

l.BeforeUnload += (object sender, DataArgs<Link> e) =>
{
    // Do not forget to do something before unloading a library
};

...

and more !

Examples

Sample for DLR

How about to use regXwild (Fast and powerful wildcards on native C++) in your C# code ? It's easy:

using(var l = new ConariL("regXwild.dll")) {
...
    if(l.DLR.searchEssC<bool>((WCharPtr)data, (WCharPtr)filter, false)) {
        // ...
    }
}

yes, you don't need to do anything else! Conari will prepare all required operations and binding with native method instead of you:

REGXWILD_API bool searchEssC(const TCHAR* data, const TCHAR* filter, bool ignoreCase);

have fun !


License

The MIT License (MIT)

Copyright (c) 2016-2018  Denis Kuzmin < [email protected] > :: github.com/3F

Donate โ˜•

How to Get

Available variants:

  • NuGet PM: Install-Package Conari
  • GetNuTool: msbuild gnt.core /p:ngpackages="Conari" or gnt /p:ngpackages="Conari"
  • NuGet Commandline: nuget install Conari
  • /releases [ latest stable ]
  • Nightly builds (/artifacts page). But remember: It can be unstable or not work at all. Use this for tests of latest changes.

conari's People

Contributors

3f avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.