• Stars
    star
    244
  • Rank 160,423 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿงฌ One-touch unmanaged memory, runtime dynamic use of the unmanaged native C/C++ in .NET world, related P/Invoke features, and โ€ฆ

Conari

๐Ÿงฌ An unmanaged memory, modules, and raw data in one-touch.

Conari engine represents most flexible platform for working with unmanaged memory, modules, related P/Invoke features, and more around libraries, executable modules, runtime dynamic use of the unmanaged native C/C++ in .NET world and other raw data just in a few easy steps without configuring something, and... Even accessing to complex types like structures without their declaration at all.

Build status release-src License NuGet package Tests

Build history

[ Quick start ] [ Complex types and strings ] -> { Wiki }

Why Conari ?

It was designed to be loyal to your needs on the fly!

๐Ÿ” Easy to start

using ConariL l = new("...");

๐Ÿงฐ Powerful types

No more manual type conversions and memory management complexities. Because nothing easier than just use it,

[โฏ]

using dynamic l = new ConariX("regXwild.dll");

string data = "number = 888;";
bool found = l.replace<bool>(ref data, "+??;", "2034;");
// found: true; data: number = 2034;

๐Ÿ”จ Its amazing DLR features

using dynamic l = new ConariX("...");
l.<whatever_you_want>(curl, 10002, "https://");

Still not convinced? Here's full workable code example for regXwild:

using var c = ConariL.Make(new("regXwild"), out dynamic l);
// ready for everything even without configuring

using var u = NativeStruct.Make.f<UIntPtr>("start", "end").Struct;
/* Hey! We just generated a structure like
[StructLayout(LayoutKind.Sequential)]
private struct MatchResult
{
    public UIntPtr start;
    public UIntPtr end;
}*/

if(l.match<bool>("n = '888';", "'*'", 2/*MATCH_RESULT*/, u))
{
    /* Now we just generated and invoked this
    REGXWILD_API_L bool match
    (
        const rxwtypes::TCHAR* input,
        const rxwtypes::TCHAR* pattern,
        rxwtypes::flagcfg_t options,
        EssRxW::MatchResult* result
    )
    */
    dynamic v = u.Access; // just access the EssRxW::MatchResult* result
    // v.start == 4; v.end == 9;
}
// Yes, a 4 lines and your task is done; Free memory, Free hands.

๐Ÿš€ Awesome speed

Optional caching of 0x29 opcodes (Calli) and more.

test of regXwild's algorithms [340x10000 Unicode] +icase [x32] +icase [x64] `
regXwild native C++ EXT algorithm ~50ms ~26ms <<
regexp-c++11(regex_search) ~59309ms ~53334ms
regexp-c++11(regex_match with endings .*) ~59503ms ~53817ms
.NET Regex engine [Compiled] ~38310ms ~37242ms
.NET Regex engine ~31565ms ~30975ms
regXwild via Conari v1.3 (Lambda) - EXT ~54ms ~35ms <<
regXwild via Conari v1.3 (DLR) - EXT ~214ms ~226ms

๐Ÿ”ง The easiest (most ever) access to any data in unmanaged memory

// Everything will be generated at runtime
memory.Native()
    .f<WORD>("Machine", "NumberOfSections") // IMAGE_FILE_HEADER (0xF4)
    .align<DWORD>(3)
    .t<WORD>("SizeOfOptionalHeader")
    .t<WORD>("Characteristics")
    .region()
    .t<WORD>("Magic") // IMAGE_OPTIONAL_HEADER (0x108)
    .build(out dynamic ifh);

if(ifh.SizeOfOptionalHeader == 0xF0) { // IMAGE_OPTIONAL_HEADER64
    memory.move(0x6C);
}

// Use it !

ifh.NumberOfSections // 6
ifh.Characteristics  // IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LARGE_ADDRESS_AWARE | IMAGE_FILE_DLL
ifh.Machine          // IMAGE_FILE_MACHINE_AMD64
ifh.Magic            // PE64
dynamic l = ptr.Native().f<int>("x", "y").build();
l.x // 17
l.y // -23

๐Ÿ„ Most powerful PInvoke and even most convenient use of WinAPI without preparing something

Conari will generate and adapt everything at runtime! Specially for you! For example, below we don't provide neither user32.ShowWindow() nor user32.MessageBoxA(), even no kernel32.GetModuleHandleA/W()

dynamic user32 = new User32();

    user32.ShowWindow(0x000A0A28, 3);
    user32.MessageBoxA(0, "Conari in action", "Hello!", 0);
dynamic kernel32 = new Kernel32();

    kernel32.GetModuleHandleA<IntPtr>("libcurl-x64");
    kernel32.GetModuleHandleW<IntPtr>((WCharPtr)ustr);

Because our recipe is simple, Just use it! and have fun.

๐Ÿ”– Modern .NET Core

Conari is ready for .NET Core starting from 1.4. Even for .NET Standard 2.0 which does not cover unmanaged EmitCalli due to missing implementation for System.Private.CoreLib. Now this is another one of independent solution for everyone as https://github.com/3F/UnmanagedEmitCalli

๐Ÿฐ Open and Free

Open Source project; MIT License; Fork! Star! Contribute! Share! Enjoy!

Conari is available for everyone from 2016 ๐ŸŽ‰

๐Ÿ—ธ License

The MIT License (MIT)

Copyright (c) 2016-2021  Denis Kuzmin <[email protected]> github/3F

[ โ˜• Make a donation ]

Conari contributors https://github.com/3F/Conari/graphs/contributors

We're waiting for your awesome contributions!

Take a look closer

Conari generally provides two mode,

Fully automatic way through its dynamic features (DLR). For example, when using the unmanaged code:

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

This (or like) does not require the any configuration from you, because Conari will do it automatically.

Semi-automatic way through its custom lambda expressions. For example, when using the unmanaged code:

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

This also does not require neither the creation of any additional delegates nor the configuring something. Just a more control through l.bind<...>("...") methods that still make you happy;

// invoke it immediately
l.bind<Action<int, string>>("set")(-1, "Hello from Conari !");

// or later
set(-1, "Hello from Conari !");

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

// IMAGE_FILE_HEADER: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313.aspx
dynamic ifh = binaryData.Native()
            .t<WORD, WORD>(null, "NumberOfSections")
            .align<DWORD>(3)
            .t<WORD, WORD>("SizeOfOptionalHeader")
            .build();
                
if(ifh.SizeOfOptionalHeader == 0xF0) { // IMAGE_OPTIONAL_HEADER64
    ... 
}

// IMAGE_DATA_DIRECTORY: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680305.aspx
binaryData.Native()
    .t<DWORD>("VirtualAddress")
    .t<DWORD>("Size")
    .build(out dynamic idd);

DWORD offset = rva2Offset(idd.VirtualAddress);
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 --
...

A modern NativeData chains for everything (Memory, Streams, Local collections, ...)

.move(0x3C, Zone.D)
.read(out LONG e_lfanew)
.move(e_lfanew, Zone.D)
.eq('P', 'E', '\0', '\0')
.ifFalse(_ => throw new PECorruptDataException())
.Native()
.f<WORD>("Machine", "NumberOfSections")
.align<DWORD>(3)
.t<WORD, WORD>("SizeOfOptionalHeader", "Characteristics")
.region()
.t<WORD>("Magic") // start IMAGE_OPTIONAL_HEADER offset 0 (0x108)
.build(out dynamic ifh)
.Access
.move(ifh.SizeOfOptionalHeader == 0xF0 ? 0x6C : 0x5C)
.read(out DWORD NumberOfRvaAndSizes)
.Native() // DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]
.t<DWORD>("VirtualAddress")
.t<DWORD>("Size")
.build(out dynamic idd)
.Access.move(8 * (NumberOfRvaAndSizes - 1))
...

// ifh.Machine;          - IMAGE_FILE_MACHINE_AMD64
// e_lfanew              - 0x110
// NumberOfRvaAndSizes   - 16
// idd.VirtualAddress    - VA 0x7070
// ifh.Characteristics;  - IMAGE_FILE_EXECUTABLE_IMAGE 
//                          | IMAGE_FILE_LARGE_ADDRESS_AWARE 
//                          | IMAGE_FILE_DLL
// ifh.Magic;            - PE64
// ifh.NumberOfSections; - 6
// ...

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 accessing [?]

l._.ADDR_SPEC // DLR, 0x00001CE8
l.V.get<UInt32>("ADDR_SPEC"); // lambda, 0x00001CE8
std_cin = l.addr("?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A");

Aliases [?]

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

Additional types

  • TCharPtr, CharPtr, WCharPtr, float_t, int_t, ptrdiff_t, size_t, uint_t, ...
  • NativeString<T> (+NativeStringManager<T>) - Fully supports TCharPtr, CharPtr, WCharPtr;
  • NativeStruct - Fully automatic way of working with structures without declarations using NativeData chains;
  • NativeStruct<T> - Semi-automatic way of working with structures using CLR types declarations;
  • NativeArray<T>
  • ...
using var a = new NativeString<WCharPtr>("Hello");
using var b = a + " world!"; // unmanaged C-string, a Unicode characters
CharPtr name = c.to<CharPtr>(1, out size_t len);
//CharPtr name = c.bind<FuncOut3<int, size_t, IntPtr>>("to")(1, out size_t len);
string myName += name; // 8 bit C-string and managed string (UTF-16)
using NativeArray<short> nr = new(pointer); // points to ~0x2674F89EDF0
nr[0] = 1; nr[1] = 2;
using NativeArray<int> nr = new(1, 2, 3);
nr[0] = -1;
nr[1] = 0;
nr[2] = 1;

Assert.True(nr == new int[] { -1, 0, 1 });
using var u = new NativeStruct<MatchResult>();
l.match<bool>(
    "[system]", "Sys###", 
    EngineOptions.F_ICASE | EngineOptions.F_MATCH_RESULT, 
    u
);
u.Data.start // 1
u.Data.end   // 7
using ConariL l = new("regXwild.dll");
l._.replace<bool>
(
    l._T("number = 888;", out CharPtr result), 
    l._T("+??;"), l._T("2034;")
);
// result: number = 2034;
using dynamic l = new ConariX(RXW_X);

bool found = l.replace<bool>
(
    "Hello {p}".Do(out TCharPtr result),
    "{p}",
    "world!"
); // found: true; result: Hello world!

and more ...

โœ Examples

How about regXwild (โฑ Superfast ^Advanced wildcards++? on native unmanaged C++) in your C# code?

using dynamic l = new ConariX("regXwild.dll");
if(l.match<bool>(input, "'+.#?'")) {
    // ... '1.4', '1.04', ...
}

Yes, you don't need to do anything else! Conari will prepare everything for binding with the following native method instead of you:

REGXWILD_API_L bool match
(
    const rxwtypes::TCHAR* input,
    const rxwtypes::TCHAR* pattern,
    rxwtypes::flagcfg_t options = 0,
    EssRxW::MatchResult* result = nullptr
);

How to get Conari

More Repositories

1

DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
C#
923
star
2

MvsSln

๐Ÿงฉ Customizable VisualStudio .sln parser with project support (.vcxproj, .csproj., โ€ฆ). Pluggable lightweight r/w handlers at runtime, and more โ€ฆ
C#
132
star
3

vsSolutionBuildEvent

๐ŸŽ› Event-Catcher with variety of advanced Actions to service projects, libraries, build processes, runtime environment of the Visual Studio, MSBuild Tools, and โ€ฆ
C#
76
star
4

aml_s905_uboot

u-boot DDR mods ~
C
65
star
5

LuNari

๐Ÿ—ฆ๐ŸŒ” Lua for .NET :: Lua 5.4, 5.3, 5.2, 5.1, ...
C#
50
star
6

netfx4sdk

Developer Pack (SDK). NETFX 4: Visual Studio 2022 / MSBuild 17 / or other modern tools
Batchfile
33
star
7

Examples

An complete examples and related support for various popular projects, and more.
C++
27
star
8

GetNuTool

Embeddable Package Manager (+core in .bat); ๐Ÿ•Š Lightweight tool to Create or Distribute using basic shell scripts (no powershell no dotnet-cli)
Batchfile
27
star
9

regXwild

โฑ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
C++
26
star
10

vsCommandEvent

Extending Visual Studio on the fly via E-MSBuild, SobaScript, C#, ...
C#
19
star
11

hMSBuild

.bat scripts with full Package Manager inside for searching and wrapping MSBuild tools. All Visual Studio and .NET Framework versions
Batchfile
19
star
12

IeXod

The most portable alternative to Microsoft.Build for evaluating, manipulating, and other progressive data processing in a compatible XML-like syntax
C#
16
star
13

Huid

๐ŸŽซ High-speed a FNV-1a-128 hash-based UUID.
C#
16
star
14

7z.Libs

๐Ÿ“ฆ๐Ÿ“ฆ ๐Ÿ—œ An automated build of the `7z.Libs` NuGet packages.
Batchfile
13
star
15

UnmanagedEmitCalli

A tiny hack of the System.Private.CoreLib to provide an Unmanaged EmitCalli implementation at the .NET Standard 2.0 layer.
C#
10
star
16

TmVTweaks

A variety of patches and tweaks for TeamViewer software such as a completely hidden ugly toolbar, screen fixes, hotkeys, etc.
C#
6
star
17

LX4Cnh

Algorithm for high-speed multiplication of LARGE numbers
C#
6
star
18

sandbox

:: โ›ฑ Experimental or incomplete components and libraries or tests for different languages, frameworks, components, platforms, etc.
C++
6
star
19

GhrMeter.user.js

๐Ÿ“Š๐Ÿ“ˆ Displays statistics for attachments on GitHub Releases page
JavaScript
3
star
20

E-MSBuild

Advanced Evaluator of MSBuild scripts with user-variables support through Varhead and more
C#
3
star
21

Fnv1a128

FNV-1a ใ€Œ 128-bit ใ€ High-Speed implementations ๐Ÿš€ using LX4Cnh etc.
C#
3
star
22

SobaScript

Extensible Modular Scripting Programming Language -- #SobaScript
C#
2
star
23

CI.MSBuild.Demo

[Archived] Samples with native C++ and .NET (CLR) projects for work with CI.MSBuild / vsSolutionBuildEvent. Has been moved to here โ†’: https://github.com/3F/Examples
C#
1
star
24

MoConTool

A variety of patches and tweaks for your favorite mouse.
C#
1
star
25

3F

1
star
26

FlightSDCpp

FlightSDC++ project - client for Direct Connect protocol
C++
1
star
27

N7z

[ planned ] 7-Zip file archiver for .NET via github.com/3F/Conari
Batchfile
1
star
28

FlightSDC.RPC-WebSockets

RPC-WebSockets variant of flightSDC project - migrated from my public repository on Bitbucket
C++
1
star
29

3F.github.io

HTML
1
star
30

mos3sms-smsb

mos3sms - SMSb (plugin for moservices 3) - migrated from my public repository on Bitbucket
PHP
1
star
31

web.vsSBE

To support the vsSolutionBuildEvent / `_doc` folder has been imported from - bitbucket.org/3F/vssolutionbuildevent/wiki/
CSS
1
star
32

Jt

Extremely Small, Fast, and damn Customizable โš™ template engine on Native low-level implementation. / Mr. Jt / [ TypeScript & JavaScript ]
JavaScript
1
star