I've been working on some code that calls a method in WoW and returns its return value. Whilst this is fine for a single uint parameter, I'm struggling with passing strings.
So far my code allocates memory for a string, writes it to memory, then calls the method at the address with the address of the string as a parameter.
Here's what I have:
Code:
private uint Call(uint address, string Param)
{
Param += '\0';
// round length to nearest 4096
int sl = RoundPageSize(Param.Length);
// create some memory to store the string
uint sptr = wow.AllocateMemory(sl);
// write the string to memory
SMemory.WriteUnicodeString((IntPtr)wow.ProcessId, sptr, Param);
// execute at the address (I'm testing with 0x005A4FE0)
uint retn = wow.Execute(address, sptr);
System.Threading.Thread.Sleep(5);
wow.FreeMemory(sptr);
return retn;
}
This crashes WoW, stating that an access violation occured reading memory address 0x00000044.
What am I doing wrong?