-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hooking a function with variadic arguments #246
Comments
Take a look at this delegate implementation (I haven’t tested this myself): https://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-bots-programs/wow-memory-editing/301588-how-hooking-functions-wow-variable-arguments-c.html
Here is a fictional example that is for a function that accepts a string like formatted like %b%d%f and an arg for each of those three format specifiers (e.g. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void SomeVariadicFuncDelegate(string fmt, RuntimeArgumentHandle args);
private static unsafe void SomeVariadicFuncHook(string fmt, RuntimeArgumentHandle args)
{
// call original
OriginalSomeVariadicFunc(fmt, args);
if (fmt == null)
return;
IntPtr ptr = *(IntPtr*)&args;
var vals = new List<object>(fmt.Length / 2);
for (int i = 1; i < fmt.Length; i += 2)
{
switch (fmt[i])
{
case 'b':
vals.Add(Memory.Read<uint>(ptr) != 0);
ptr += 4;
break;
case 'd':
vals.Add(Memory.Read<int>(ptr));
ptr += 4;
break;
case 'f':
vals.Add(Memory.Read<double>(ptr));
ptr += 8;
break;
case 'u':
vals.Add(Memory.Read<uint>(ptr));
ptr += 4;
break;
case 's':
vals.Add(Memory.Read<string>((uint)ptr, 0));
ptr += 4;
break;
}
}
} |
it is my code but not working |
how can i hook _snprintf ? i don't know how to define its delegate since i don't know what is the alternative of c
...
The text was updated successfully, but these errors were encountered: