I am learning to put a bot together. I am writing it in C#. I use a bootstrap DLL to load the .NET Framework. Browsing the PE shows me that the CLR is loaded. Now I am moving on to trying to hook Endscene. I found what very well may be the example I need http://www.ownedcore.com/forums/worl...k-example.html ([Source] C# EndScene hook example), but MegaUpload is dead and I cannot get a look at anything. I read Apoc's example of how to hook Endscene and I am 100% certain I am getting it wrong. Basically, I am trying to hook Endscene after I select the client I want to run the bot on and I am doing it from inside the bot program. Below is the code, I know you guys hate cut and paste and I am not looking to be spoonfed so I will try to keep this to a minimum.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using WhiteMagic;
namespace WoWEmuBot
{
public partial class FormSetup : Form
{
#region Properties
private Infrastructure.WindowInfo WInfo
{
get;
set;
}
private List<Infrastructure.WindowInfo> WInfoList
{
get;
set;
}
#endregion
#region Endscene Hooking Setup
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate int EndSceneDelegate(IntPtr instance);
private static readonly EndSceneDelegate EndSceneHandler = EndScene;
private static readonly WhiteMagic.Magic white = new WhiteMagic.Magic();
private static int EndScene(IntPtr instance)
{
// Pulse();
MessageBox.Show("EndScene");
return (int)white.Detours["EndScene"].CallOriginal(instance);
}
#endregion
public FormSetup()
{
InitializeComponent();
}
private void buttonFindClients_Click(object sender, EventArgs e)
{
WInfo = new Infrastructure.WindowInfo();
WInfoList = WInfo.GetWindowList("Wow");
this.comboBoxClientSelect.DataSource = WInfoList;
this.comboBoxClientSelect.DisplayMember = "DisplayName";
this.comboBoxClientSelect.ValueMember = "ProcessID";
}
private void buttonSelectClient_Click(object sender, EventArgs e)
{
Magic.BlackMagic magic = new Magic.BlackMagic();
magic.OpenProcessAndThread(WInfoList[this.comboBoxClientSelect.SelectedIndex].ProcessID);
string path = AppDomain.CurrentDomain.BaseDirectory;
string DLL = path + "Bootstrap.dll";
magic.InjectDllCreateThread(DLL);
IntPtr endSceneAddr = white.GetObjectVtableFunction(white.Read<IntPtr>(0x0123E908, 0x397C), 42); // This is where my problem is.
white.Detours.CreateAndApply(white.RegisterDelegate<EndSceneDelegate>(endSceneAddr), EndSceneHandler, "EndScene");
}
}
}
At the commented line above (which I did find a post with someone else having trouble with the same spot but no solution), I get an exception that it is trying to read protected memory. If I just try to read the address I get an exception that it is null. I believe there is a fundamental disconnect between my understanding of what I think needs to happen and what actually needs to happen.
So now come the very basic and very stupid questions that will improve my understanding if I can get them answered:
1. I have the .NET runtime loaded in WoW. I am having trouble understanding how I can Marshal a function in WoW and call it in the program I wrote. They do not share the same memory space, do they?
2. It feels like I should be putting all of these functions in a framework and packing them onto the DLL that gets pulled into the client. If that is the case, how do I call them from my program. They are different AppDomains, aren't they?
In the interim, I am dissecting babbot and trying to discern how to hook Endscene with EasyHook to try to improve my understanding but I would still like to learn to use WhiteMagic, it looks like a really nice tool.
I know the offsets are off from Live. I am messing around with the 3.3.5 12340 client at the moment.