SHARE
TWEET

Untitled

a guest Nov 29th, 2011 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ...
  2. private static GameUI GetCGameUI(Int32 construct, Int32 destruct)
  3.     {
  4.         // Manual implementation of __fastcall.
  5.         // Moves the two first arguments to the registers.
  6.  
  7.         var code = new byte[16];
  8.         var stream = new MemoryStream(code);
  9.         var writer = new BinaryWriter(stream);
  10.  
  11.         var codePtr = Kernel32.VirtualAlloc(IntPtr.Zero, code.Length, AllocationType.Commit, MemoryProtection.ExecuteReadWrite);
  12.  
  13.         // (BA) mov edx, destruct boolean
  14.         writer.Write((Byte)0xBA);
  15.         writer.Write((UInt32)destruct);
  16.  
  17.         // (B9) mov ecx, construct boolean
  18.         writer.Write((Byte)0xB9);
  19.         writer.Write((UInt32)construct);
  20.  
  21.         // (E8) call, GetCGameUI relative offset
  22.         writer.Write((Byte)0xE8);
  23.         writer.Write((UInt32)((Int32)Addresses.GetCGameUI - (Int32)codePtr - (Int32)writer.BaseStream.Position - 4));
  24.  
  25.         // (C3) retn
  26.         writer.Write((Byte)0xC3);
  27.  
  28.         Marshal.Copy(code, 0, codePtr, code.Length);
  29.  
  30.         var ui = ((EmptyGetCGameUIPrototype)Marshal.GetDelegateForFunctionPointer(codePtr, typeof(EmptyGetCGameUIPrototype)))();
  31.  
  32.         Kernel32.VirtualFree(codePtr, code.Length, 0x8000);
  33.  
  34.         return ui;
  35.     }
  36. ...
  37.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top