How can I verbosely track the whole process of calling a function?

40 Views Asked by At

I'm currently developing a tool that need to call a non-imported function of a DLL (let us call it Third.DLL and the function func(arg). func create a stack variable Type var and passed it to func_impl(arg). So in order to use it directly, I implemented my own func_mine(arg), found the offset address for Type::Type() and func_impl(arg), and then wrote

int func_mine(arg...) // arg... just as a placeholder here, not real C++ code
{
    auto con = DLL_Base_Add + GetOffset("Type::Type()");
    Type* type = (Type* )new char[sizeof(Type)];
    con(type);

    auto impl = DLL_Base_Add + GetOffset("func_impl(...)");
    return impl(arg...);
}

The function terminates normally, and in those arg..., one is returned back, but I found the returned variables are not identical, I tried

  1. call func directly
  2. call func directly
  3. call func directly
  4. call func_mine
  5. call func_mine
  6. call func directly
  7. call func directly

I notices that 1,2,3 produced result 1 while 4,5,6,7 produced result 2. I cannot understand this behaviour, something's modified and cannot be recovered after calling func_mine. And I want result 1 instead of 2.

What may be the reasons of this phenomenon? how can I find which variable's incorrectly modified? Is there any tool I can use to verbosely track and dump the data section and stack space for each assembly instruction? It will cost me a lot of time to MANUALLY check all the variables for all stack frames, and after every instructions.

0

There are 0 best solutions below