user3506886
user3506886

Reputation: 11

hook. va_list .is possible?

I'm trying to intercept(hook) a function that uses a list of arguments to get the result, and then call the old function.

// int __cdecl Ordinal578(char *a1, unsigned int a2, int a3, char a4)  (HEXRAYS)
typedef int(__cdecl *Ordinal578)(char *a1, unsigned int a2, const char * a3, ...);
Ordinal578 Ordinal578org = nullptr;
Ordinal578 Ordinal578ptr = nullptr;

int __cdecl Ordinal578my(char *a1, unsigned int a2, const char * a3, ...)
{

    int result = 0;
    va_list args;
    va_start(args, a3);
    result = Ordinal578ptr(a1, a2, a3, args); // if replace this on "vsnprintf_s(a1, a2, a2, a3, args);" it works 5-10 min and then crash!
    va_end(args);

    return result;
}

Program crashes after call: Ordinal578ptr (a1, a2, a3, args)

How to set the hook on these functions?

Upvotes: 1

Views: 357

Answers (1)

Deduplicator
Deduplicator

Reputation: 45684

  1. See if there is a similar function accepting a va_list instead.
  2. There is no other standard conforming way. Some compilers support magic extensions for va_list, which might do what you want. Look at your compilers manual. For gcc, look at: __builtin_apply_args () and friends.

Upvotes: 2

Related Questions