Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork28
🧬 One-touch unmanaged memory, runtime dynamic use of the unmanaged native C/C++ in .NET world, related P/Invoke features, and …
License
3F/Conari
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
🧬 An unmanaged memory, modules, and raw data inone-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.
Copyright (c) 2016-2024 Denis Kuzmin <x-3F@outlook.com> github/3FConari is waiting for your awesome contributions!https://github.com/3F/Conari/graphs/contributors
It was designed to be loyal to your needs on the fly!
🔍 Easy to start
usingConariLl=new("...");
🧰 Powerful types
No more manual type conversions and memory management complexities. Because nothing easier than just use it,
usingdynamicl=newConariX("regXwild.dll");stringdata="number = 888;";boolfound=l.replace<bool>(refdata,"+??;","2034;");// found: true; data: number = 2034;
🔨 Its amazing DLR features
usingdynamicl=newConariX("...");l.<whatever_you_want>(curl,10002,"https://");
Still not convinced? Here's full workable code example forregXwild:
usingvarc=ConariL.Make(new("regXwild"),outdynamicl);// ready for everything even without configuringusingvaru=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 ) */dynamicv=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.
[⏯] DllExport + Conari
[DllExport]// DllExportModifiedClassLibrary.dllpublicstaticIntPtrcallme(TCharPtrstr,IntPtrstructure){if(str!="Hello world!")returnIntPtr.Zero;structure.Native().f<int>("x","y").build(outdynamicv);if(v.x>v.y){structure.Access().write<int>(8);}returnnewNativeArray<int>(-1,v.x,1,v.y);}
...// host side via C/C++, Java, Rust, Python, ... or even same dotnet C#usingNativeString<TCharPtr>ns=new("Hello world!");usingNativeStruct<Arg>nstruct=new(newArg(){x=7,y=5});usingdynamicl=newConariX("DllExportModifiedClassLibrary.dll");IntPtrptr=l.callme<IntPtr>(ns,nstruct);usingNativeArray<int>nr=new(4,ptr);// (nstruct.Data.x == 8) != (nr[1] == 7)
🚀 Awesome speed
Optional caching of 0x29 opcodes (Calli) and more.
| test of regXwild's algorithms [340x10000 Unicode] | +icase [x32] | +icase [x64] | ` |
|---|---|---|---|
regXwildnative 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 viaConari v1.3 (Lambda) -EXT | ~54ms | ~35ms | << |
regXwild viaConari v1.3 (DLR) -EXT | ~214ms | ~226ms |
🔧 The easiest (most ever) access to any data in unmanaged memory
// Everything will be generated at runtimememory.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(outdynamicifh);if(ifh.SizeOfOptionalHeader==0xF0){// IMAGE_OPTIONAL_HEADER64memory.move(0x6C);}// Use it !ifh.NumberOfSections// 6ifh.Characteristics// IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LARGE_ADDRESS_AWARE | IMAGE_FILE_DLLifh.Machine// IMAGE_FILE_MACHINE_AMD64ifh.Magic// PE64
dynamicl=ptr.Native().f<int>("x","y").build();l.x// 17l.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 neitheruser32.ShowWindow() noruser32.MessageBoxA(), even nokernel32.GetModuleHandleA/W()
dynamicuser32=newUser32();user32.ShowWindow(0x000A0A28,3);user32.MessageBoxA(0,"Conari in action","Hello!",0);
dynamickernel32=newKernel32();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 Standard2.0 which does not cover unmanagedEmitCalli due to missing implementation forSystem.Private.CoreLib. Now this is another one of independent solution for everyone ashttps://github.com/3F/UnmanagedEmitCalli
🍰Open and Free
Open Source project; MIT License;Fork! Star! Contribute! Share! Enjoy!
Conari is available for everyone from 2016 🎉
Conari generally provides two mode,
Fully automatic way through its dynamic features (DLR). For example, when using theunmanaged code:
varptr=d.test<IntPtr>();//lambda ~ bind<Func<IntPtr>>("test")();varcodec=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>(refcid,outdata);//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 itautomatically.
Semi-automatic way through its customlambda expressions. For example, when using theunmanaged code:
using(varl=newConariL("Library.dll")){l.bind<Action<int,int>>("call")(2,1);doublenum=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 throughl.bind<...>("...") methods that still make you happy;
// invoke it immediatelyl.bind<Action<int,string>>("set")(-1,"Hello from Conari !");// or laterset(-1,"Hello from Conari !");
Native C/C++ structures without declaration[?]:
// IMAGE_FILE_HEADER: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313.aspxdynamicifh=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.aspxbinaryData.Native().t<DWORD>("VirtualAddress").t<DWORD>("Size").build(outdynamicidd);DWORDoffset=rva2Offset(idd.VirtualAddress);
IntPtrptr ...Raw mt=ptr.Native().align<int>(2,"a","b").t<IntPtr>("name").Raw;-{byte[0x0000000c]}byte[][0]0x05byte--[1]0x00byte|[2]0x00byte|[3]0x00byte--^a=5[4]0x07byte--[5]0x00byte|[6]0x00byte|[7]0x00byte--^b=7[8]0x20byte--[9]0x78byte|_pointer to allocatedstring:(CharPtr)name[10]0xf0byte|[11]0x56byte--...
A modernNativeData chains for everything (Memory, Streams, Local collections, ...)
.move(0x3C,Zone.D).read(outLONGe_lfanew).move(e_lfanew,Zone.D).eq('P','E','\0','\0').ifFalse(_=>thrownewPECorruptDataException()).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(outdynamicifh).Access.move(ifh.SizeOfOptionalHeader==0xF0?0x6C:0x5C).read(outDWORDNumberOfRvaAndSizes).Native()// DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].t<DWORD>("VirtualAddress").t<DWORD>("Size").build(outdynamicidd).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(varl=newConariL("Library.dll",CallingConvention.StdCall)){//...l.Mangling=true;// _get_SevenStdCall@0 <-> get_SevenStdCalll.Convention=CallingConvention.Cdecl;}
Exported Variables [?] &raw accessing [?]
l._.ADDR_SPEC// DLR, 0x00001CE8l.V.get<UInt32>("ADDR_SPEC");// lambda, 0x00001CE8std_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>
- ._T("...") - NativeString<TCharPtr> via NativeStringManager<TCharPtr>
- ...
usingvara=newNativeString<WCharPtr>("Hello");usingvarb=a+" world!";// unmanaged C-string, a Unicode characters
CharPtrname=c.to<CharPtr>(1,outsize_tlen);//CharPtr name = c.bind<FuncOut3<int, size_t, IntPtr>>("to")(1, out size_t len);stringmyName+= name;// 8 bit C-string and managed string (UTF-16)
usingNativeArray<short>nr=new(pointer);// points to ~0x2674F89EDF0nr[0]=1;nr[1]=2;
usingNativeArray<int>nr=new(1,2,3);nr[0]=-1;nr[1]=0;nr[2]=1;Assert.True(nr==newint[]{-1,0,1});
usingvaru=newNativeStruct<MatchResult>();l.match<bool>("[system]","Sys###",EngineOptions.F_ICASE|EngineOptions.F_MATCH_RESULT,u);u.Data.start// 1u.Data.end// 7
usingConariLl=new("regXwild.dll");l._.replace<bool>(l._T("number = 888;",outCharPtrresult),l._T("+??;"),l._T("2034;"));// result: number = 2034;
usingdynamicl=newConariX(RXW_X);boolfound=l.replace<bool>("Hello {p}".Do(outTCharPtrresult),"{p}","world!");// found: true; result: Hello world!
and more ...
How aboutregXwild (⏱ Superfast ^Advanced wildcards++? on native unmanaged C++) in your C# code?
usingdynamicl=newConariX("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_Lbool match(const rxwtypes::TCHAR* input,const rxwtypes::TCHAR* pattern, rxwtypes::flagcfg_t options =0, EssRxW::MatchResult* result =nullptr);
About
🧬 One-touch unmanaged memory, runtime dynamic use of the unmanaged native C/C++ in .NET world, related P/Invoke features, and …
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.

