question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Call to stdcall functions through virtual tables causes issues with the stack analysis

See original GitHub issue

Describe the bug On 32bit X86 when calling __stdcall functions through virtual tables (Microsoft interfaces for instance) the stack analysis is breaking down.

To Reproduce Steps to reproduce the behavior:

  1. compile the test_stdcall.c file (contained in the provided zip archive using gcc: gcc -m32 -fno-pic test_stdcall.c -o test_stdcall -O1
  2. import into ghidra
  3. create correct function types and correctly set global variables types.
  4. the call_func procedure is incorrectly analyzed

Expected behavior As calling conventions have been correctly specified for the function pointers I would expect the stack analysis to be performed correctly.

Screenshots This is the observed behavior: test_stdcall And here is the original function code:

void call_func(int a, int b, int c) {
    (*(*pObj)->f1)(pObj, 0, a);
    (*(*pObj)->f1)(pObj, 1, b);
    (*(*pObj)->f1)(pObj, 2, c);
}

Attachments The attachment contains the complete minimal source file as well as the completed Ghidra zip file. test_stdcall.zip

Environment (please complete the following information):

  • OS: Win10
  • Java Version: open-jdk 11.0.2
  • Ghidra Version: 9.0.2
  • gcc Version: (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0

Additional context I used Ubuntu for windows for the test case but I know of binaries compiled with visual studio that display this behavior.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
arbruijncommented, Sep 29, 2020

The problem seems to be that the call stack adjustment (ActionExtraPopSetup) is handled before resolving the indirect function type (ActionDeindirect). I came up with the following patch which fixes the problem for my small test case (FUN_0040100d should end with return param_2 + iVar1 + param_1).

fix_indirect_stdcall.patch

decompind.zip

1reaction
Kerilkcommented, May 14, 2019

Yes the __stdcall convention is set. I also checked in the debug XML file: stdcall_win_debug.zip and the flag appears in the function type definition.

Thanks again for looking into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling Convention conflict in Outputpin - c++ - Stack Overflow
Wrong calling convention is a typical problem to get this error message, however it is only one of the possible causes.
Read more >
In C++ why and how are virtual functions slower?
Virtual methods are commonly implemented via so-called virtual method tables (vtable for short), in which function pointers are stored.
Read more >
Calling Conventions Demystified - CodeProject
Because the stack is cleaned by the called function, the __stdcall calling convention creates smaller executables than __cdecl , in which the ...
Read more >
Failures and troubleshooting - Hex Rays
When the decompiler gracefully fails on a function, it will display one of ... 16-bit functions are not supported; call analysis failed; function...
Read more >
Function Interface Analysis: A Principled Approach for ...
develop a novel static analysis based method in this paper. In ... our analysis can reason about the content of the stack, as....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found