![]() |
|
[C#] Dynamic API Call With Dynamic Delegates - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Dynamic API Call With Dynamic Delegates (/showthread.php?tid=4189010) |
Dynamic API Call With Dynamic Delegates - frontenhack - Apr 23, 2014 Hello HF :) Today i'm gonna show you this code, it automatically generates delegate types with Reflection.Emit. So Code public DynamicDelegateApiInvoker()It generates a dynamic assembly. Code public T InvokeApi<T>(string library, string function, object[] parameters)The function accept :
Firstly it loads the library and check for errors Then it gets the function address and check for errors. after it creates parameter type array for constructing the delegate. Then it creates the delegate using TypeBuilder. Example Code : Code class ProgramTo see the full code go to my blog : frontenhack.me * - morphine1337 - Apr 23, 2014 Nice, this is pretty good, thank you very much. * - iVision - Apr 23, 2014 Looks useful I guess for malware people anyway it is not fail-proof: CallingConventions.Standard you don't know the convention, it could be cdecl which usually the case when you are invoking third party libraries however for the WinAPI it is StdCall (Standard). If you choose the wrong convention I think, never tried it this would happen (assuming the no name mangling if this was the case you had to look at the export table to find the name or do the math): a. If the caller assumes stdcall but the API is cdecl: it leaves the arguments on the stack b. If the caller assumes cdecl but the API is stdcall: since the API already cleaned it parameters, so the calling API will pop off wrong things. Both messes up the stack :( The rest seems fine I think although from an object oriented perspective it doesn't make sense to have multiple instances of the class? Why isn't it static? * - Zettabit - Apr 23, 2014 If you're going to host it off site, at least upload it to a place that doesn't go down for no reason. * - Only3 - Apr 23, 2014 You Dont Need Apis Pure Reflection Code public static object DynamicInvoke(string Dll, string Name, object[] Param, Type Ret)* - frontenhack - Apr 24, 2014 (Apr 23, 2014 11:54 PM)Only3 Wrote: You Dont Need ApisThis was already released, mine was more unique xD * - Only3 - Apr 24, 2014 if this ur point ok but its been posted as well from what i remember * - frontenhack - Apr 26, 2014 (Apr 24, 2014 10:41 AM)Only3 Wrote: if this ur point ok but its been posted as well from what i remember Dynamic delegates with emit i think no, anyway thanks for posting :) |