I've just reverse engineered a binary with IDA and loaded Hex Ray to check out a specific function. The generate C source code contains the following if statement:
LP_ret_GlobalLock_1 = GlobalLock(hMem);
LP_ret_GlobalLock_2 = LP_ret_GlobalLock_1;
...
if ( !LP_ret_GlobalLock_1 || (v9 = *(_DWORD *)(v6 + 4), *(_DWORD *)v6 = LP_ret_GlobalLock_2, v9 < 0) )
I'm not sure to completely understand the following part:
(v9 = *(_DWORD *)(v6 + 4), *(_DWORD *)v6 = LP_ret_GlobalLock_2, v9 < 0)
v9 is initialised as v6 + 4; but then v6 is modified to be a pointer LP_ret_GlobalLock_2 and finally v9 is check for being less than 0. Is that correct? When calculating v9 what value is used for v6? The LP_ret_GlobalLock_2 or the previous value?
I guess you are asking about the comma operator. It evaluates the expression before the comma, then the expression after the comma, and the result of the whole thing is the result of the second expression.
So it first does v9 = *(_DWORD *)(v6 + 4), then *(_DWORD *)v6 = LP_ret_GlobalLock_2, and then v9 < 0. The result is the result of v9 < 0, after the first two expressions have been evaluated.
I understand that you got this via reverse engineering. I would never use the comma operator with side effects inside an if-statement like that when writing code myself; it's too obfuscated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With