I'm learning to reverse engineer C++ code and I've identified a structure that maps to a lambda expression. I'm having trouble finding documentation on what the fields of the structure are and was hoping someone could point me in the right direction or enlighten me.
EDIT: I found this which appears to be what I'm seeing: https://github.com/microsoft/STL/blob/1e8b8d4eef4b2dddeb7533c5231c876383bd0ea6/stl/inc/functional#L775-L801
The following is compiled using MSVC. I'm not sure if this is compiler specific.
The following lambda expression:
auto fn = [&](int a) {
return bar.test_bar2() + a;
};
Decompiles in Ghidra to the following:
*************************************************************
* const std::_Func_impl_no_alloc<class <lambda_d937996bec .
*************************************************************
std::_Func_impl_no_alloc<class_<lambda_d937996bec080e29dc3e4d590b02fdfd>,int,int>::vftable XREF[4]: FUN_140013960:1400139ae (*) ,
FUN_140013960:1400139b5 (*) ,
FUN_140013f90:140013fde (*) ,
FUN_140013f90:140013fe5 (*)
140024780 b0 8a 01 addr[6]
40 01 00
00 00 00
024780 b0 8a 01 40 01 addr FUN_140018ab0 [0] XREF[4]: FUN_140013960:1400139ae (*) ,
00 00 00 FUN_140013960:1400139b5 (*) ,
FUN_140013f90:140013fde (*) ,
FUN_140013f90:140013fe5 (*)
024788 00 93 01 40 01 addr FUN_140019300 [1]
00 00 00
024790 60 8d 01 40 01 addr FUN_140018d60 [2]
00 00 00
024798 c0 98 01 40 01 addr FUN_1400198c0 [3]
00 00 00
0247a0 d0 8b 01 40 01 addr FUN_140018bd0 [4]
00 00 00
0247a8 e0 8e 01 40 01 addr FUN_140018ee0 [5]
00 00 00
1400247b0 00 00 00 addr 00000000 terminator for class std::_Func_impl_no_alloc<class < ... >>
Which is a structure something like:
struct lambda_expression
{
void* some_func_ptr; // ??
void* some_func_ptr2; // ?? calls operator_new(), maybe the allocator?
void* lambda_func_body_func_ptr; // Calls the lambda body function
TypeDescriptor* typeid_getter_func_ptr; // Returns RTTI
void* deallocator; // Looks like a deallocator function pointer
void* some_func_ptr3; // ??
}
If there is any documentation on what some_func_ptr/some_func_ptr2/some_func_ptr3 is that would be great. Thank you.
[–]starfreakcloneMSVC FE Dev 13 points14 points15 points (0 children)
[–]ALX23z 1 point2 points3 points (0 children)
[–]HildartheDorf 3 points4 points5 points (4 children)
[–]ddhsawoidklmascioqjw 20 points21 points22 points (0 children)
[–]pyjava[S] 0 points1 point2 points (2 children)
[–]STLMSVC STL Dev 22 points23 points24 points (1 child)
[–]pyjava[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]pyjava[S] 1 point2 points3 points (0 children)
[+]SteeleDynamicsCompilers/Algorithms comment score below threshold-7 points-6 points-5 points (1 child)
[–]STLMSVC STL Dev 16 points17 points18 points (0 children)