Sample
- SHA256
-
a1f1f37de6b61b1148b813c3415a96be5fe4415a975ba70b1b8feb4441bd4b9d - Difficulty
- easy
- Platform
- Windows
- Tags
- c++ calling conventions clean x86
- Likes
- 0
- Views
- 7
- Submitter
- struppigel
Analysis
Goal
The main function of this sample calls four functions. Each of these prepare a call with a different calling convention. Determine the calling convention of each sub function. Correct Ghidra's function definitions if necessary.
Description
all_in_one.exe
The sample was created based on the following code.
#include <iostream>
class NumberCombinator
{
public:
int i = 3;
NumberCombinator(int arg1)
{
i = arg1;
}
__declspec(noinline)
int callme_thiscall(int arg2, int arg3, int arg4, int arg5, int arg6)
{
return i + arg2 + arg3 + arg4 + arg5 + arg6;
}
};
__declspec(noinline)
int __fastcall callme_fastcall(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
{
return arg1 + arg2 + arg3 / arg4 + arg5 + arg6;
}
__declspec(noinline)
int __stdcall callme_stdcall(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
{
return arg1 + arg2 + arg3 * arg4 + arg5 + arg6;
}
__declspec(noinline)
int __cdecl callme_cdecl(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
{
return arg1 + arg2 + arg3 - arg4 + arg5 + arg6;
}
void cdecl_call()
{
int a = rand();
int b = rand();
int c = rand();
int d = rand();
int e = rand();
int f = rand();
int res1 = callme_cdecl(a, b, c, d, e, f);
std::cout << res1 << std::endl;
}
void fastcall_call()
{
int a = rand();
int b = rand();
int c = rand();
int d = rand();
int e = rand();
int f = rand();
int res1 = callme_fastcall(a, b, c, d, e, f);
std::cout << res1 << std::endl;
}
void stdcall_call()
{
int a = rand();
int b = rand();
int c = rand();
int d = rand();
int e = rand();
int f = rand();
int res1 = callme_stdcall(a, b, c, d, e, f);
std::cout << res1 << std::endl;
}
void thiscall_call()
{
int a = rand();
int b = rand();
int c = rand();
int d = rand();
int e = rand();
int f = rand();
NumberCombinator* nc = new NumberCombinator(a);
int res1 = nc->callme_thiscall(b, c, d, e, f);
std::cout << res1 << std::endl;
}
int main()
{
cdecl_call();
stdcall_call();
fastcall_call();
thiscall_call();
}
Recommended Tools
Ghidra
Comments
Please login to view and post comments.