A Quiz in Advanced RE (Asm/C)
Just some interesting stuff for those interested. If anyone has their own, please share.
1) In what special circumstance is sizeof(ptr1) != sizeof(ptr2)? 2) Name the computer science algorithm which places type dependencies (typedefs) in a correct order. BONUS: how to minimize forward declarations (from structure pointer circular dependencies) and what is the complexity of the graph problem? 3) How are capture arguments of lambda functions dealt with in assembly, and with which calling convention is it effectively invoked? 4) What is the difference between parameters in a variadic function (…) verse one converted to use a va_list? 5) A recursive function has many parameters which are never changed, or even better has merely more than one argument and is using a lot of stack space, while not having an guarantee as to its depth limit. How to make this safe? Code:
|
hard to answer.
Just curious what's the percentage of interviewees that can answer the questions. Anyway, thanks for share. |
I think sizeof(ptr1) != sizeof(ptr2) is impossible.
Whether a ptr is void or NULL or even wild, its size must be equal to sizeof(unsigned int). There is only one case I may have missed, that's far pointer compared with the near one. |
1) Pointers can point to different types of memory and not all CPU architectures are Von_Neumann_architecture
example Intel 8051 pointers http://www.keil.com/support/man/docs...51_le_ptrs.htm |
1) At least with MSVC you can specify pointer size with __ptr32 and __ptr64 when building for 64-bit. https://docs.microsoft.com/en-us/cpp/cpp/ptr32-ptr64
3) I believe usually a temporary object is constructed using pointers to the lambda arguments, and the function is invoked using the __thiscall convention. Probably depends on the compiler's implementation though. Had to check answer for the others :p Very interesting questions. |
For the first question for some more interesting detail (its very compiler specific of course), taken from StackOverflow
Quote:
Quote:
A pointer to a function pointer is data again too and so the function pointer is much more specific. 3) as far as I know its the captures that are on the temporary object, and the actual function arguments are passed per __thiscall logic. I did not give any interviews with these questions but it would be interesting to see what creative answers people would come up with. Obviously these are a bit to technical and advanced to do more than probe and analyze people's knowledge a bit. Would be interesting to see them used for a "Senior Reverse Engineer" job or the like :D. |
Quote:
Here's an example of how MSVC seems to implement lambdas: Code:
bool normal_function() Code:
bool normal_function() |
Exactly right. The class you mention is originally known as a functor with the operator parenthesis.
And very notably though, lambdas are slightly more efficient. Because no class is truly constructed. The constructor you wrote is not actually called - it can be optimized out by the compiler. There is no constructor/destructor just copying capture values and invocation of the () method and of course the object is stack constructed not dynamically allocated. A really thorough analysis is here: Quote:
Quote:
|
All times are GMT +8. The time now is 23:19. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX