Skip to content

Array indices unrecognised, producing over complex/poor C output #5720

@Wall-AF

Description

@Wall-AF

Describe the bug
In a loop looking at elements of an array, Ghidra isn't realising that a local variable added to an address is actually equivalent to looking at the same field in the next(/previous) array element. (It doesn't seem to be checking the local variables increment (or decrement) against the size of the array's element!) This is producing expressions like
(*(char *)((int)&DgnPhoneme_0x4_t_ARRAY_1210_9b34[0].b2 + local_4) == '-')
instead of
(DgnPhoneme_0x4_t_ARRAY_1210_9b34[nItem].b2 == '-')
where nItem is the loop index.

With nested arrays, it gets worse!

To Reproduce
Steps to reproduce the behaviour:

  1. Load in the enclosed function (from the Decompile:Panels Debug Function Decompilation menu)
  2. Search down the decompiled code to find the output above
  3. See issue

Expected behaviour
Use of correct(/better) array syntax in decompiled C output.

Screenshots
N/A

Attachments
dragon_FUN_1160_0049.zip

Environment (please complete the following information):

  • OS: Windows 11
  • Java Version: 17.0,3.1
  • Ghidra Version: 10.4.DEV
  • Ghidra Origin: locally built from 26d4bd9

Additional context
This is an extract from a Windows NE DLL (circa 1990s)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions