Advertisement
theobjop

IPCPFunc.cpp

Feb 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. IPCFunc::IPCFunc(void* funcPtr, int cPars) {
  2.     this->pFunc = (IntPtr)funcPtr;
  3.     this->cPars = cPars;
  4.     this->parameters = new int[cPars];
  5. }
  6.  
  7. extern "C" int IPCFunc::invoke() {
  8.     // Create function signature based on cArgs
  9.     if (cPars == 0)
  10.         return ((int(*)())pFunc)();
  11.    
  12.     auto funcPtr = (int(*)())pFunc;
  13.     int returnValue(0);
  14.  
  15.     int n_stack = cPars * sizeof(int);
  16.     int p_stack = 0;
  17.    
  18.     __asm {
  19.         sub esp, n_stack;
  20.         push parameters;
  21.         call funcPtr;           // call the function
  22.         mov returnValue, eax;   // Save the return value from the function return value register
  23.         pop n_stack;            // resume normal functionality
  24.         add esp, n_stack;
  25.     }
  26.        
  27.     return returnValue;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement