0

In this decompiled code, does psVar8[-6] refer to 6*sizeof(psVar8) == 12 bytes before psVar8?

psVar8 = (short *)(&DAT_1412345b4 + named_index * 0x20);
do {
  if (psVar8[-6] == 0) break;
  // ...
} while (lVar10 < 6);

It would seem more intuitive to me if the position of psVar8 was earlier to avoid the negative index. Is there a way to change this in the decompiled code, or a reason not to?

I'm attaching the entire loop in case that is important to the question:

    do {
      if (psVar8[-6] == 0) break;
      if (psVar8[-6] == 4) {
        named_variable = 0;
        if (0 < *psVar8) {
          named_variable = (int)*psVar8;
        }
        iVar4 = 0x1d;
        if (named_variable < 0x1d) {
          iVar4 = named_variable;
        }
        *(undefined2 *)(&DAT_145678900 + (longlong)iVar4 * 2) = 1;
      }
      lVar10 += 1;
      psVar8 = psVar8 + 1;
    } while (lVar10 < 6);
1

1 Answer 1

2

I think you are running into a case of "shifted pointers". For various reasons the compiler might generate code where a pointer to the middle of a struct is returned. There is a Ghidra PR for this, but this isn't merged yet and still has various issues, IDA discusses this feature here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.