Function pointers ?

Posts 12 of 2 · Page 1 of 1
Function pointers ?
OOkkaay... So i have a problem:
I have a pointer, to a function:
"0x12345" (for example)...

I know excatly the parameter list (int X, int Y, string Text)


in C++, its easy to solve:
Code:
_asm
{
   push 0
   push 0
   push text
   call 0x12345
}
But how the hell can i do it in C# ?
(Without a plus C++ Dll)
Create a function delegate to the function you want to call.
Like this:
Code:
        // Function delegate..
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate int InternalGameFuncDelegate(int X, int Y, [MarshalAs(UnmanagedType.LPStr)] string Text);

        // Create the function ptr..
        var func = (InternalGameFuncDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(0x12345), typeof(InternalGameFuncDelegate));
        
        // Call the function..
        func( 123, 456, "Hello world!" );
Assuming your C# dll is injected and all. Also keep in mind, you will need to find the right return type as well as the calling convention for the function for it to not corrupt the stack.
Posts 12 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?