public HookHandle(IntPtr hookedFunc, IntPtr newFunc) { byte[] NewIntro = new byte[] { 0xE9, 0x90, 0x90, 0x90, 0x90, 0xC3 }; Array.Copy(BitConverter.GetBytes(newFunc.ToInt32() - hookedFunc.ToInt32() - 5), 0, NewIntro, 1, 4); byte[] OrigIntro; using (VirtualProtectHandle.Protect(hookedFunc, NewIntro.Length, MemProtection.ExecReadWrite)) { OrigIntro = new byte[NewIntro.Length]; Marshal.Copy(hookedFunc, OrigIntro, 0, OrigIntro.Length); } Init(hookedFunc, OrigIntro, NewIntro); }
void WriteIntro(byte[] Intro) { using (VirtualProtectHandle.Protect(HookedFunc, Intro.Length, MemProtection.ExecReadWrite)) { Marshal.Copy(Intro, 0, HookedFunc, Intro.Length); } }