I am working on reversing a simple binary using Ghidra. The decompile results in this line of code
if ((param_1 != 4) && (func0(param_1 1), param_1 1 == 0x32))
The param_1 1==0x32 section is confusing me as I'm just not familiar with the syntax and am not sure what it is doing inside a boolean expression.
CodePudding user response:
That's the comma operator. In this case, it's just unnecessarily confusing, as an alternative decompilation could have avoided it, e.g., these are equivalent:
if ((param_1 != 4) && (func0(param_1 1), param_1 1 == 0x32)) {
doStuff();
}
if (param_1 != 4) {
func0(param_1 1);
if(param_1 1 == 0x32) {
doStuff();
}
}
CodePudding user response:
Ok this is going to be quite the breakdown
The expression is:
(func0(param_1 1), param_1 1 == 0x32)
Thus, call func0 with param_1 1
, throw away the result, and compare param_1 1
to 0x32
.
This code is unnatural; I would normally expect to find param_1 == 0x31
.
I'm guessing that this isn't a C binary and the decompiler can't express pass by value return, which is what ancient basic used. The documentation says it's pass by reference, but it is not. I found out the hard way by passing a global to a function that mutated the global.