The Code 🔗
int main()
{
int a, b;
auto _0 = +[]mutable{};
decltype(_0) _[] = {_0,_0};
a = *(int*) +_0;
b = *(int*) +0[_];
b = ([&]<auto >-> auto{_0(-[] ->auto{});}, b >> (sizeof(_0) - b));
a /= !(!(int*)&[_,_0]{0[_](),[__=&_0]() -> auto{(*__)();};}) * b;
char str[] = {a+=a-b,a-=b+1,a+a-3};
std::cout << str << std::endl;
}
Let’s walk through this…
- We declare two variables
a
andb
. - We initalize a variable
_0
with a pointer to an empty mutable lambda. - We initialize a C-style array
_
of typedecltype(_0)[]
with two elements, both of them being_0
. - We initalize
a
with the integer representation of_0
. - Wi initialize
b
with the integer representation of the first element of_
.- In C++
arr[idx]
andidx[arr]
are interchangeable whenarr
is a C-style array.
- In C++
b
is reassigned with the following expression:([&]<auto>->auto{_0(-[]->auto{});},b>>(sizeof(_0)-b))
- If we break this down we notice there is a comma in the middle and parentheses surrounding all of this. This is a comma operator expression. Which means that only the things at the most right of the comma are returned out of the expression. That being the part:
b>>sizeof(_0)-b
, in this case,b
now has the value 6.
- the
[&]<auto>->auto{_0(-[]->auto{});}
expression will:- create a templated lambda with an auto template parameter, missing parentheses, and captures its environment by reference and deduces its return type.
- The body of the lambda calls the
_0
lambda with an empty lambda pointer.
- Will divide a by the following expression:
!(!(int*)&[_,_0]{0[_](),[__=&_0]()->auto{(*__)();};}) * b
- As we can see, there’s a humongous expression there on the left and that is then multiplied times b.
- the expression on the left is a lambda that captures
_
and_0
by value. - its body calls the first element of
_
- then it creates another lambda that captures
_0
as a pointer into__
- its body then calls this lambda by dereferencing it first.
- Then the reference to this lambda’s place in memory is taken. While this expression is executing, this place in memory does exist.
- This place in memory is then converted into an
int*
. - Then, this mystery number, is negated twice. Which will then convert it to a 0 if it was a null pointer or 1 if it was any other address (it has an address during the expression).
- So all of this just evaluates to 1. Multiplying anything by 1 doesn’t matter so all of this is just obscuring that your multiplying
b
by 1.
- A
char
array namedstr
is created containing our three special characters. str
is sent tostdout
BOOM
:3c